Nginx, django, gunicorn, ubuntu 14.04 (13: Permiss

2019-02-18 04:10发布

问题:

I am working at my django project with nginx and gunicorn, as it said here:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04

My site works locally, but when I start nginx and gunicorn server I had

502 Bad Gateway error.

OS is UBUNTU 14.04

I'm trying to make my project working, and reinstall everything as root (I know its bad) - the same mistake.

Here is my "error.log":

2016/04/20 20:15:10 [crit] 10119#0: *1 connect() to
unix:/root/myproject/myproject.sock failed (13: Permission denied) while connecting to upstream, client: 46.164.23

When i run comand "nginx":

  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] still could not bind()

My gunicorn.conf

description "Gunicorn application server handling myproject" start on runlevel [2345] stop on runlevel [!2345] respawn setuid root setgid www-data chdir /root/myproject exec myprojectenv/bin/gunicorn --workers 3 --bind unix:/root/myproject/myproject.sock myproject.wsgi:application

Thats my "/etc/nginx/sites-available/myproject"

server {
listen 80;
server_name         www.mysite.ru;

error_log /nginx_error.log;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /root/myproject;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/root/myproject/myproject.sock;
}

}

I will appreciate your help very much!!!

回答1:

proxy_pass http://unix:/root/myproject/myproject.sock;

The socket is in the superuser's home folder. That's pretty much inaccessible to all other users including your nginx users. Please more the socket to a different location. /var/log/gunicorn/ is a good place.

Also do i see you running gunicorn as root?. Not recommended.

setuid root

Please use some other user here.



回答2:

I think you have some other process using port 80, according to your nginx error log.

You'll have to figure out what that process is, and kill it if unneeded. Or use another port.