繁体   English   中英

Centos nginx + django + gunicorn 403 禁止

[英]Centos nginx + django + gunicorn 403 forbidden

我有一个安装了 nginx 的 centos 服务器,我将在其中加载 django 应用程序。 安装 python34、nginx、django 和 gunicorn 后,我配置 nginx.conf 文件,如下所示:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

index   index.html index.htm;

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  54.17X.2XX.11X;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

location /static/ {
    #alias /opt/cath/static/;
    alias /home/ec2-user/test/endpoint/website/static/;
} 

    location / {
    proxy_pass http://127.0.0.1:8000/site;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }

此时,当我为 /home/ec2-user/test/endpoint/website/static/ 下的所有资源启动 gunicorn 和 nginx seervic 时,我收到 403 禁止访问错误。 我尝试:

sudo chmod -R 777 <Path to static>

也试过

sudo chown -R nginx:nginx <path to static>

但错误 403 仍然存在

我该如何解决这个问题?

提前致谢

但问题仍然存在

我认为它与 SELinux 有关,您可以通过以下方式禁用它:

nano /etc/selinux/config 将 SELINUX 的值更改为禁用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM