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.

I have setup uwsgi logging from the answer here:

https://www.digitalocean.com/community/questions/how-to-check-error-logs-for-flask-uwsgi-nginx-app

results are below, not sure what it means about ‘No such file or directory [core/socket.c line 230]’ though…

current working directory: /etc/uwsgi/sites detected binary path: /usr/local/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! chdir() to /home/david/codego/codego your processes number limit is 1882 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) bind(): No such file or directory [core/socket.c line 230] *** Starting uWSGI 2.0.14 (64bit) on [Wed Feb 15 10:56:24 2017] *** compiled with version: 5.4.0 20160609 on 05 February 2017 05:08:58 os: Linux-4.4.0-62-generic #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 nodename: ubuntu-512mb-sgp1-01 machine: x86_64 clock source: unix detected number of CPU cores: 1

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

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

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

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel