0

Having some trouble linking up Django + uWSGI + NGINX

If I run the Django development server, the page works perfectly.

If I run with: uwsgi --http 0.0.0.0:8134 --wsgi-file /test/test_project/wsgi.py and access it at localhost:8134 the site works except the images are not being loaded.

But if I access the site at localhost:80 (presumably for nginx handling), I get an error in the nginx error.log (the following is for ONE page request, so not sure why it looks like two):

2018/07/15 11:55:34 [error] 20986#20986: *1 connect() to unix:/test
/test_project/test.sock failed (111: Connection refused) while 
connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, 
request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/test/test_project
/test.sock:", host: "localhost"
2018/07/15 11:55:34 [error] 20986#20986: *1 connect() to unix:/test
/test_project/test.sock failed (111: Connection refused) while 
connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, 
request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:
/test/test_project/test.sock:", host: "localhost", referrer: 
"http://localhost/"

I've made sure to run 'sudo service nginx reload' and 'sudo service nginx restart'.

Primary Question:
1. Why can I not access the site via localhost:80. I am guessing it has to do with the socket file refusing connections; the socket file is empty and was created with 'uwsgi --ini test_uwsgi.ini'. Is there something with inetd/xinetd I need to check?

Secondary Questions (may require a separate post):
1. Not sure if there is something wrong with the configuration or if I am running this correctly to begin with at all. Do I have to run 'sudo service nginx start' AND run 'uwsgi --http 0.0.0.0:8134 --wsgi-file /test/test_project/wsgi.py'? I'm guessing yes for now unless I somehow automate the uwsgi command through nginx.
2. Should every script, image and configuration file be owned by www-data?
3. Are my static images folder accessible by uwsgi and nginx (based on the configs below)? How to make sure?
4. I've had issues with cookies not being passed, so if there's something with the config preventing that, please let me know.

Here is the setup:

/test/test_project/test.sock permissions:

srwxrwxrwx 1 www-data www-data 0 Jul 14 22:51 test.sock
*Obviously I'll want to tighten this up, but for troubleshooting   purposes permissions are open wide.

/test/test_project/test_uwsgi.ini:

[uwsgi]

chdir = /test/test_project
module = test.wsgi

pythonpath = /usr/bin/python2
# process-related settings
master = true
processes = 8
socket = /test/test_project/test.sock
chmod-socket = 666
max-requests = 50000

/test/test_project/uwsgi.py:

def application_backup(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

return view.index(environ, start_response)

custom_nginx.conf:

upstream django {
 server unix:/test/test_project/test.sock;
 # Also tried unix:///test/test_project/test.sock;
}

server {
 listen 80;
 server_name 127.0.0.1;
 charset utf-8;

client_max_body_size 1024M;

location /static {
 alias /test/test_project/static;
 }

location /media {
 alias /test/test_project/media;
 }

location / {
 uwsgi_pass django;
 include uwsgi_params;
 }

 access_log /var/log/nginx/access.log;
 error_log /var/log/nginx/error.log warn;
}

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.