nginx之Gunicorn Nginx连接到上游时被拒绝

wuhuacong 阅读:16 2024-10-24 08:47:37 评论:0

使用Gunicorn和Nginx设置Django网站

项目的gunicorn设置:

[Unit] 
Description=gunicorn daemon 
After=network.target 
 
[Service] 
User=username 
Group=nginx 
WorkingDirectory=/home/username/my_project 
ExecStart=/home/username/my_project/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/username/my_project/my_project.sock my_project.wsgi:application 
 
[Install] 
WantedBy=multi-user.target 

Nginx项目的配置文件:
user nginx; 
 
server { 
    listen       80; 
        server_name  192.168.66.106; 
 
        # Load configuration files for the default server block. 
        include /etc/nginx/default.d/*.conf; 
 
        location = /favicon.ico { access_log off; log_not_found off; } 
        location /static { 
            alias /home/username/my_project; 
        } 
 
        location / { 
            proxy_set_header Host $http_host; 
            proxy_set_header X-Real-IP $remote_addr; 
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
            proxy_set_header X-Forwarded-Proto $scheme; 
            proxy_pass http://unix:/home/username/my_project/my_project.sock; 
       } 
    } 

我有我的项目的这些许可
drwxrwxr-x. 5 username nginx 4.0K Apr  4 10:20 modulo1 
-rwxrwxr-x. 1 username nginx  823 Apr  4 10:13 manage.py 
drwxrwxr-x. 4 username nginx 4.0K Apr  4 10:20 modulo2 
drwxrwxr-x. 2 username nginx  249 Apr  4 10:29 my_project 
srwxrwxrwx. 1 username nginx    0 Apr  4 10:47 my_project.sock 
-rw-rw-r--. 1 username nginx  565 Apr  4 10:13 README.md 
-rw-rw-r--. 1 username nginx  228 Apr  4 10:14 requirements.txt 
drwxrwxr-x. 5 username nginx   38 Apr  4 10:13 static 
drwxrwxr-x. 3 username nginx   88 Apr  4 10:14 templates 

这是来自/var/log/nginx/error.log的日志错误
2018/04/04 10:54:03 [crit] 14238#0: *4 connect() to unix:/home/username/my_project/my_project.sock failed (13: Permission denied) while connecting to upstream client: 192.168.66.50, server: 192.168.66.106, request: "GET / HTTP/1.1", upstream: "http://unix:/home/username/my_project/my_project.sock:/", host: "192.168.66.106" 

请您参考如下方法:

我有一个centos 7操作系统,无论如何我通过安装解决了该问题:

sudo yum install policycoreutils-python  
sudo semanage permissive -a httpd_t  


标签:nginx
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号