ssg*_*hal 6 nginx selinux gunicorn
使用 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
Run Code Online (Sandbox Code Playgroud)
项目的 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;
}
}
Run Code Online (Sandbox Code Playgroud)
我有我的项目的这些权限
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
Run Code Online (Sandbox Code Playgroud)
这是来自 /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"
Run Code Online (Sandbox Code Playgroud)
ssg*_*hal 14
我有一个 centos 7 操作系统,无论如何我解决了安装问题:
sudo yum install policycoreutils-python
sudo semanage permissive -a httpd_t
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5074 次 |
| 最近记录: |