搭建hexo的时候遇到了403错误。查了许多说修改权限或者修改nginx用户,都不行。

其实是selinux在作怪。

在StackOverflow上的一篇回答给出了解决方法。

简单来说,先关闭selinux看看问题有没有解决

1
setenforce Permissive

如果解决了就说明是selinuxd在作怪。然后先把selinux打开 setenforce Enforcing

然后去包含了index.html的目录(比如hexo的public),然后

1
chcon -Rt httpd_sys_content_t .

然后查看一下是不是允许http连入,不允许的话打开。

1
2
3
getsebool -a
#看httpd_can_network_connect是on还是off。如果是off就用下面一条命令打开
setsebool -P httpd_can_network_connect on