Nginx:403在静态文件上(仅端口80)
当在更高的端口(比如8000)上时,静态文件可以正常加载。当我使用sudo在端口80上运行服务器时,我得到403个错误。知道为什么会这样吗 我唯一的想法是,这与以root用户身份运行有关,文件权限都是正常的,即使使用-777也不会改变错误Nginx:403在静态文件上(仅端口80),nginx,Nginx,当在更高的端口(比如8000)上时,静态文件可以正常加载。当我使用sudo在端口80上运行服务器时,我得到403个错误。知道为什么会这样吗 我唯一的想法是,这与以root用户身份运行有关,文件权限都是正常的,即使使用-777也不会改变错误 # the upstream component nginx needs to connect to events { worker_connections 1024; } http{ upstream django { ser
# the upstream component nginx needs to connect to
events {
worker_connections 1024;
}
http{
upstream django {
server 127.0.0.1:8001;
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
root ~/my/path/;
# the domain name it will serve for
server_name 127.0.0.1;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias _; # your Django project's media files - amend as required
}
location /static/ {
autoindex on;
root /my/path/static/;
}
location ~ \.css {
root /my/path/static/;
}
location ~ \.js {
root /my/path/static/;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include ../uwsgi_params;
}
}
}
您需要将此上下文添加到内容目录:
chcon -R -t httpd_sys_content_t /my/path/static
或者您需要禁用Selinux。
编辑/etc/sysconfig/selinux文件以永久禁用selinux。
setEnforce0可动态禁用selinux。您可能希望共享您的nginx配置文件。此外,请查看nginx错误日志,以获取有关抛出403的原因的提示。通常/var/log/nginx/error将添加配置,错误只是在日志中表示权限被拒绝。我不明白为什么它只会在端口80上抛出它,我觉得这与将nginx作为root运行有关。