Question

Need some help completing deployment of Django site on Nginx from local computer

I followed this tutorial for setting up uwsgi and Nginx on Ubunutu

https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04

The guide shows how to setup two fresh Django sites, I just did the first one and that is now working here

http://128.199.120.162/

for the second site I want to deploy a Django blog I had built locally, put it on the same ip and serve it on port :8080 so then I followed this tutorial

https://www.digitalocean.com/community/tutorials/how-to-deploy-a-local-django-app-to-a-vps

I have followed everything in the guide apart from the GUnicorn part as I believe I dont need that if I have Uwsgi.

Ive cloned my site there, setup psql, migrated the db and finally done collecstatic and they all seem to have worked without any problems, I can run the site and see it at :8080 if I do manage.py runserver 0.0.0.0:8080 but if I just go to that port normally then I get an ‘internal server error’.

The following is my setup for uwsgi and Nginx, its almost exactly the same as what I did for ‘first site’ however I should add that the second tutorial had somethings a bit different for the Nginx server block setup which Im not sure if I need so I have commented those out (e.g. proxy_pass etc)

/etc/uwsgi/sites/codego.ini

[uwsgi] project = codego uid = david base = /home/david

chdir = /home/david/codego/codego home = /home/david/Env/codego module = codego.wsgi:application

master = true processes = 5

socket = /run/uwsgi/codego.sock chown-socket = david:www-data chmod-socket = 666 vacuum = true

/etc/systemd/system/uwsgi.service

[Unit] Description=uWSGI Emperor service

[Service] ExecStartPre=/bin/bash -c ‘mkdir -p /run/uwsgi; chown david:www-data /run/uwsgi’ ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites Restart=always KillSignal=SIGQUIT Type=notify NotifyAccess=all

[Install] WantedBy=multi-user.target

/etc/nginx/sites-available/codego

server { listen 8080; server_name = 128.199.120.162;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
            root /home/david/codego;
    }

    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"';
            include         uwsgi_params;
            uwsgi_pass      unix:/run/uwsgi/codego.sock;
    }

}

Ive been banging my head against this for hrs now and still can’t figure it out.

I should add btw that my wigs.py file was blank for some reason so I had to manually add that content there from local and also Nginx error logs dont seem to be logging anything for some reason.

Any advice would be appreciated, I think Im very close to finishing this setup!


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Accepted Answer

Found the problem, my directory structure was causing this I think as I had too many folders within folders and not named correctly, after removing everything in the Env and starting again for that Django install but this time with a more simple folder structure I seem to have it right and can see the site at :8080.

@easycompany80

Have you checked the log files generated by NGINX?

tail -20 /var/log/nginx/error.log

The above will display the last 20 lines of the error.log and may have more information as to why you’re receiving the ISE.

and could file ownership be the problem? This is what ls -ld gives me:

drwxr-xr-x 3 root root 4096 Feb 5 04:28 /home drwxr-xr-x 9 david david 4096 Feb 12 04:54 /home/david drwxr-xr-x 3 david root 4096 Feb 10 14:07 /home/david/codego drwxr-xr-x 6 david root 4096 Feb 11 05:48 /home/david/codego/codego

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.