2

I followed this post to serve my django project. The project runs well with manage.py runserver and I want to set it up for production. Here are my setting files:

nginx.conf:

upstream django { server /tmp/vc.sock; #server 10.9.1.137:8002; } server { listen 8001; server_name 10.9.1.137; charset utf-8; client_max_body_size 25M; location /media { alias /home/deploy/vc/media; } location /static { alias /home/deploy/vc/static; } location / { uwsgi_pass django; include /etc/nginx/uwsgi_params; } } 

uwsgi.ini:

[uwsgi] chdir = /home/deploy/vc wsgi-file = vc/wsgi.py master = true processes = 2 #socket = :8002 socket = /tmp/vc.sock chmod-socket = 666 vacuum = true 

If I use TCP port socket (server 10.9.1.137:8002 and socket = :8002), it's going to be fine. However if I comment them out and use Unix sockets(server /tmp/vc.sock and socket = /tmp/vc.sock), the server will return 502 error. How should I fix it?

EDIT

Here's the nginx error log when I run /etc/init.d/nginx restart

nginx: [emerg] invalid host in upstream "/tmp/vc.sock" in /etc/nginx/conf.d/vc.conf:2 nginx: configuration file /etc/nginx/nginx.conf test failed 

And this is the warning when I run uwsgi --ini vc/uwsgi.ini:

*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 

Can't I run uWSGI as root?

2 Answers 2

5

roberto's comment should be an answer!

the syntax in nginx for unix socket path is wrong, you need to prefix it with unix:

Sign up to request clarification or add additional context in comments.

Comments

0

Check your nginx error log, very probably is telling you it does not have permissions to the socket. Unix sockets honour file system permissions, so nginx must have write privilege over the socket file. Short answer: 664 is not enough, you need 666

2 Comments

Thank you for the answer. I changed to 666 but it's still the same. I edited my question and added the error log. Is it because I'm running as root?
the syntax in nginx for unix socket path is wrong, you need to prefix it with unix:

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.