I am following this tutorial to deploy my Django website: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-local-django-app-to-a-vps.
I am able to connect to the site using gunicorn, but all of my pages are displayed without any static content (css, javascript.)
Here is my nginx configuration file for the site.
server {
server_name [DROPLET IP ADDRESS];
access_log off;
location /static/ {
alias /home/myuser/myvirtualenv/myproject/static/;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
I solved this myself.
The issue was a misconfiguration of both Nginx and Gunicorn.
Nginx was not set to listen on a port. Here is the updated site configuration file:
Gunicorn’s issue was that it was set to listen to my hosts IP address rather than the address Nginx’s “proxy_pass.”
I initially launched Gunicorn using my Droplet’s IP address.
I changed
[DROPLET IP ADDRESS]
to127.0.0.1
and now everything works after restarting both Gunicorn and Nginx.Hi @richiegreen95,
The problem that I’m seeing is with your
proxy_pass
and your backend. You need to make sure that your backend service is actually listening on port8001
. You can do that with:If you don’t see any output you need to make sure that you’ve followed the instructions in step 9 regarding the Gunicorn configuration.
Regards, KDSys