为什么即使所有权限设置正确,Nginx也会返回403?
作者:互联网
我有Nginx设置并正确显示测试页面.如果我尝试更改根路径,即使所有权限都相同,我也会收到403 Forbidden错误.此外,nginx用户存在.
nginx.conf:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
index index.html index.htm;
server {
listen 80;
server_name localhost;
root /var/www/html; #changed from the default /usr/share/nginx/html
}
}
namei -om /usr/share/nginx/html/index.html
f: /usr/share/nginx/html/index.html
dr-xr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x root root share
drwxr-xr-x root root nginx
drwxr-xr-x root root html
-rw-r--r-- root root index.html
namei -om /var/www/html/index.html
f: /var/www/html/index.html
dr-xr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root www
drwxr-xr-x root root html
-rw-r--r-- root root index.html
错误日志
2014/03/23 12:45:08 [error] 5490#0: *13 open()
“/var/www/html/index.html” failed (13: Permission denied), client:
XXX.XX.XXX.XXX, server: localhost, request: “GET /index.html HTTP/1.1”, host: “ec2-XXX-XX-XXX-XXX.compute-1.amazonaws.com”
解决方法:
我遇到了同样的问题,这是由于SELinux.
要检查SELinux是否正在运行:
# getenforce
要在下次重新启动之前禁用SELinux:
# setenforce Permissive
重新启动Nginx并查看问题是否仍然存在.如果您想永久更改设置,可以编辑/ etc / sysconfig / selinux
如果SELinux是您的问题,您可以运行以下命令以允许nginx为您的www目录服务(确保在测试之前重新启用SELinux.即,#setenforce Enforcing)
# chcon -Rt httpd_sys_content_t /path/to/www
如果您仍有问题,请查看getsebool -a中的布尔标志,特别是您可能需要打开httpd_can_network_connect进行网络访问
# setsebool -P httpd_can_network_connect on
对我来说,这足以让http服务我的www目录.
标签:nginx,installation,http-status-code-403 来源: https://codeday.me/bug/20190929/1834212.html