Production Deployment (Apache + VueJS + Axios) vs Django DB

I’ve hit a brick wall trying to understand how to get my PROD SSL front-end (Apache with VueJS/Axios) talking to my back-end (Django views/models + database using SQLite for very lightweight I/O app); all hosted on a private Windows Server 2022 VM instance.

I realise there are a myriad of configs possible but none I’ve read seem to fit my specific setup i.e. running django purely as db server serving queries from REST axios calls embedded in Vuejs components - with Django sitting outside of Apache (specific separation of the front and back-ends).

  • NB: I have my SSL localhost setup working fine using npm run serve for the front-end (js, css, html) and runsslserver for the backend; I realise I cannot use these commands in PROD.

  • NB: The only Django templates/texts files I’m using are those used for account setup (login, reg, forgotten password); using dj-rest-auth, allauth.

For PROD I’ve already:

  • FRONT-END: Installed Apache (configured httpd), installed Vue js (from npm run build), plus dependencies (node_modules).

  • BACK-END: Setup Django project/app directory structure, created a separate settings.py file for PROD (had been differentiating dev vs prod using “–setting” arg on runsslerver).

BUT, I don’t understand for PROD how to ‘start’ django in this setup, which then allows login/reg, supports axios REST async calls from the front-end, and also allows DRF/admin panel (all working in DEV)??

  • NB: I have reviewed mod_wsgi, wsgi, gunicorn, etc, etc; mod_wsgi may be the way fwd but not convinced yet.

This is my 1st deployment so apologies for the newbie question - just want to ensure I’m going down the right track. So at a high-level (happy to do the detailed reading) which route should I be taking??

Many thanks in advance for any advice!

PS: I ack I will also need the collectstatic step + associated config to serve static files.

Welcome @Strigoi666 !

Keep in mind that what you use for a front end has no influence or effect on how you deploy Django for the back end.

From Django’s perspective, its work is initiated by an HTTP request coming in - regardless of the source of that request.

So, you look at this as any other Django deployment. None of the front-end stuff matters at all. You’ll still be running Django under some kind of wsgi/asgi container - whether it’s mod_wsgi under Apache, or uwsgi/gunicorn behind either Apache or nginx as a proxy, it’s up to you.

The starting point for this information is at How to deploy Django | Django documentation | Django. I’ll also highlight the Deployment checklist.

Hi @KenWhitesell

Thanks for the response.

So, in my case it does sound from my initial reading that mod_wsgi is probably the way to go, BUT I will indeed review the other options you’ve referred to.

I realise it’s my choice but is there a simple pros/cons list for the available options (apologies if the answer is contained in the links you’ve kindly provided)?

Cheers!

I don’t think I could identify any objective pros/cons, they really are just options based on personal preferences. (That hasn’t always been true, but it’s true enough now - at least at the stage I believe you to be.)

For example, Apache vs Nginx. I’m strongly in the Nginx camp - not because there’s any technical difference that matters to me, but because I’m more comfortable with how it’s configured.

For Gunicorn vs uWSGI, I lean in the direction of uWSGI. Again, there’s no specific technical reason why. (Yes, there are technical differences between the two, but none that matter to me.) In my case, it’s because of non-Django-usage. I’ve had web apps deployed under uWSGI that weren’t Django, and so found it beneficial to use the same containers for everything.

So yes, I do prefer nginx / uwsgi, but that’s because I find them easier for what I need to do. That doesn’t mean that the others can’t do the job, or that someone else doesn’t find them easier.

… many thanks for your experiences - appreciated.

I’ll have a play to see what suite me.

No doubt I’ll have follow-up questions but they’ll be for another day.

Thanks again.

Something else potentially worth looking at is Caddy Server which takes care of a lot of the complexity of having to use certbot in conjunction with Apache or nginx for SSL. I haven’t used it in a production setting, but my understanding is that it is production ready.

thank you - I’ll look at this as well.

You don’t happen to know where I can source “mod_wsgi” for my Apache24 install?

I (like many others it would appear) seem to be going around and around trying to find this file so I can use ‘pip install mod_wsgi’ - so I can then talk to my django back-end.

Cheers!

The current version is available at mod-wsgi · PyPI. However, it’s still at its heart an operating-system level package and not a Python package, which means you still need your system set up to compile the code from source. (See that page for details.)

Or, you can install it from your repo’s package manager. For example, in Ubuntu, the current version is named libapache2-mod-wsgi-py3, and would be installed using apt.