403-forbidden - Nginx更改Web根目录导致403 Forbidden
问题描述
1.背景服务器环境:CentOS7/Nginx1.10.0
2.问题更改Nginx的默认Web根目录之后,访问网站出现403 Forbidden问题。
默认目录:/usr/share/nginx/html
[root@AllenServer html]# pwd /usr/share/nginx/html[root@AllenServer html]# ls -al总用量 16drwxr-xr-x. 2 allen allen 71 5月 29 01:45 .drwxr-xr-x. 5 allen allen 51 6月 1 14:47 ..-rw-r--r--. 1 allen allen 537 4月 26 23:11 50x.html-rw-r--r--. 1 allen allen 22 5月 29 01:45 index2.php-rw-r--r--. 1 allen allen 617 5月 29 01:23 index.html-rw-r--r--. 1 allen allen 167 5月 29 01:36 index.php
新目录:/home/nginx/default
[root@AllenServer default]# pwd /home/nginx/default[root@AllenServer default]# ls -al总用量 16drwxrwxrwx. 2 nginx nginx 71 6月 2 17:15 .drwxrwxrwx. 3 nginx nginx 20 6月 1 16:10 ..-rwxrwxrwx. 1 nginx nginx 537 6月 1 16:11 50x.html-rwxrwxrwx. 1 nginx nginx 22 6月 1 16:11 index2.php-rwxrwxrwx. 1 nginx nginx 618 6月 2 17:15 index.html-rwxrwxrwx. 1 nginx nginx 167 6月 1 16:11 index.php
Nginx配置文件:
[root@AllenServer default]# more /etc/nginx/nginx.conf user nginx;#user root;worker_processes 1;error_log /var/log/nginx/error.log warn;pid/var/run/nginx.pid;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; 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; sendfileon; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf;}
网站配置文件:
[root@AllenServer conf.d]# more default.conf server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / {#root /usr/share/nginx/html;root /home/nginx/default;#root /test;index index.html index.htm index.php; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html {#root /usr/share/nginx/html;root /home/nginx/default;#root /test; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ {#root /usr/share/nginx/html;root /home/nginx/default;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;includefastcgi_params; } # deny access to .htaccess files, if Apache’s document root # concurs with nginx’s one # #location ~ /.ht { # deny all; #}}
3.说明(1)更改配置之前访问默认的目录是正常的;(2)更改配置之后重启Nginx服务;(3)更改新的Web根目录之后访问出现403问题。
请教各位大神如何解决这个问题?
问题解答
回答1:权限问题一般是这么查的:
切换到出问题的软件所使用的用户。比如 su - nginx
尝试从 / 开始一级级地进入有问题的目录
尝试读取文件
访问一个文件时,不光要目标文件的权限允许,还要它之上的各级目录都允许的。
看哪一步报错就知道是哪里的问题了。
另外注意一下你的权限除了基本 POSIX 权限外,还有 SELinux。你检查一下,如果 SELinux 启用了的话,要让 SELinux 也允许 nginx 来访问的。如果是 SELinux 引起的问题,SELinux 专门有个报告用的程序可以查看详细信息的。
相关文章:
1. 求大神帮我看看是哪里写错了 感谢细心解答2. javascript - JS设置Video视频对象的currentTime时出现了问题,IE,Edge,火狐,都可以设置,反而chrom却...3. php自学从哪里开始?4. span的color问题5. javascript - 数组原声方法中的一段代码6. html - eclipse 标签错误7. 数据库 - MySQL 单表500W+数据,查询超时,如何优化呢?8. 网页爬虫 - python爬虫翻页问题,请问各位大神我这段代码怎样翻页,还有价格要登陆后才能看到,应该怎么解决9. phpstady在win10上运行10. python - from ..xxxx import xxxx到底是什么意思呢?
