Deploy Django App with NGINX
After the multiple issues that arose from having Django as an App service talking to the Azure VM (containing PostgreSQL) database, which would then talk to the Static Web App. The entire configuration was dropped.
- The following tutorial was followed to setup Django with NGINX on the VM.
info
- Following the steps in the tutorial the deployment was successful.
Serving static files via NGINX
info
To serve static files via NGINX, you need to specify the path to the static files in the NGINX conf.
- To do so, you first need to run
python manage.py collectstaticin the correct venv. - Open NGINX conf and add,
location /static/ {
<!-- root <path-to-the-static folder> -->
root /home/gqc/riverflows_django/riverflows/;
} - In this case, the
riverflows_django/riverflows/contains thestaticfolder.
Handling CORS via NGINX
info
Reference link: https://www.willandskill.se/en/articles/using-cors-with-nginx
- Once the app is hosted through NGINX, CORS headers are no longer handled by Django, but are handled by NGINX.
- Adding the following line in the NGINX conf allows CORS requests.
add_header Access-Control-Allow-Origin * always;