【问题标题】:NGINX throwing '403 Forbidden' when 'root' is changed更改“root”时 NGINX 抛出“403 Forbidden”
【发布时间】:2018-05-06 20:51:25
【问题描述】:

新的centos7.4 已安装。尚未安装 PHP 或 mySQL。只安装了 NGINX。

'/etc/nginx/nginx.conf' 文件没有被修改。

'/etc/nginx/conf.d/default.conf'是:

server {
    listen       80;
    server_name public_IP private_IP;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

}

一切正常...

但是当我将配置更改为...

...
root /var/www/html;
...

它抛出错误:

我已经吩咐过了:

sudo chmod -R 755 /var/www
sudo chown -R nginx:nginx /var/wwww

但不起作用。

【问题讨论】:

  • 那里有文件吗?
  • 是的,我在 /var/www/html、server_ip/*.* 位置有 index.html、test.html 文件,没有任何东西可以访问
  • 考虑到这是 CentOS,您可能还想检查 SElinux 权限。试试ls -alZ /var/www,公共网络内容的上下文应该类似于system_u:object_r:httpd_sys_content_t:s0

标签: nginx virtualhost centos7


【解决方案1】:

如果你尝试了所有方法都没有成功,这个方法可以帮助你:

检查 SELinux 状态

sestatus

如果启用:

# getenforce

# setenforce Permissive

结束

sudo systemctl restart nginx

【讨论】:

    猜你喜欢
    • 2013-12-09
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 2018-11-14
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    相关资源
    最近更新 更多