配置Nginx,而后生成一键生成静态页面,而后就没有而后了,全部栏目页面都显示nginx 403 forbidden。php
通常来讲nginx 的 403 Forbidden errors 表示你在请求一个资源文件可是nginx不容许你查看。
403 Forbidden 只是一个HTTP状态码,像404,200同样不是技术上的错误。
哪些场景须要返回403状态码的场景?
1.网站禁止特定的用户访问全部内容,例:网站屏蔽某个ip访问。
2.访问禁止目录浏览的目录,例:设置autoindex off后访问目录。
3.用户访问只能被内网访问的文件。
以上几种常见的须要返回 403 Forbidden 的场景html
命令:linux
ps aux | grep "nginx: worker process" | awk '{print $1}'
[root@localhost hc]# ps aux | grep "nginx: worker process" | awk '{print $1}' nginx root
发现是nginx,而不是用root启动的nginx
将nginx.conf文件中的 user 对应的nginx 改成 root ,改完后重启web
[root@localhost hc]# vim /etc/nginx/nginx.conf [root@localhost hc]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@localhost hc]# nginx -s reload
server { listen 80; server_name localhost; index index.php index.html; root / var/www; }
若是在/ var/www下面没有index.php,index.html的时候,直接访问域名,找不到文件,会报403 forbidden。vim
解决办法:修改web目录的读写权限,或者是把nginx的启动用户改为目录的所属用户,重启Nginx便可解决centos
chmod -R 755 / var/www
首先查看本机SELinux的开启状态,若是SELinux status参数为enabled即为开启状态bash
/usr/sbin/ sestatus -v
或者使用getenforce命令检查网站
如何关闭 SELinux 呢server
setenforce 0
修改配置文件 /etc/selinux/config,将SELINUX=enforcing改成SELINUX=disabled
vi /etc/selinux/config #SELINUX=enforcing SELINUX=disabled
重启生效。