gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:16:56 25 4
gpt4 key购买 nike

使用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 - Gunicorn Nginx连接到上游时被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49647277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com