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!
Accepted Answer
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:
server {
listen 1234;
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"';
}
}
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.
gunicorn --bind [DROPLET IP ADDRESS]:8001 drawbook.wsgi
I changed [DROPLET IP ADDRESS]
to 127.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 port 8001
. You can do that with:
sudo netstat -plant | grep 8001
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.