记录一

当你将 nginx 作为 web server 的时候,403 错误主要是下面两条原因:

一、所有者对目录没有写的权限。

此时可用 chmod 777 目录名 先完全放开权限,如果问题解决,则再慢慢缩小访问权限。

$ chown -R nginx_user:nginx_user /htdocs

二、未配置 index 的类型。

请在 nginx 相应 http 配置节添加 index 的配置。

index index.html index.php;

绝大部分这个报错都是各种权限问题

记录二

我把个人简历放在github上,但是访问很慢,就把这个静态简历迁移到我的VPS服务器上,使用nginx做web服务,访问时出现403错误

nginx配置(只展示重要部分):
server {
        listen  10000 ;
    server_name xxxx.xxxx.com ;
        access_log /home/resume/log/access.log main ;
        error_log /home/resume/log/error.log ;
    location / {
          root /home/resume/www ;
          index index.html ;
    }
}
访问结果:

1240

Paste_Image.png

查看nginx错误日志:

出现了关键字“Permission denied”

2016/12/23 14:02:26 [error] 5887#5887: *573 open() "/home/resume/www/index.html" failed (13: Permission denied), client: 192.168.15.2, server: xxxx.xxxx.com, request: "GET /index.html HTTP/1.0", host: "xxxx.xxxx.com"
排错记录:

一看是权限问题,马上把 /home/resume/www目录下的所有文件权限改为777 ,重新访问还是 403 ,反反复复折腾了很久,无解....
第二天晚上继续,怀疑是nginx配置错误,搜索 nginx html时找到这个文章nginx 代理本地的html
原来是nginx配置中的用户权限问题

  1. 查看nginx worker 用户,www-data 是nginx默认配置的

    1240

    Paste_Image.png

  2. 静态文件存放的文件夹用户是scott,组为executor ,所nginx用户为www-data导致权限问题(如果nginx配置的用户和静态文件的用户不匹配,那怕权限是777也会出现权限问题,具体看<nginx.conf> nginx用户权限)

    1240

    用户

  3. 配置nginx权限和静态文件统一

  4. 编辑nginx配置文件

    vim /etc/nginx/nginx.conf
  5. 修改文件第一行的为静态文件的用户和组

    # user 用户名 用户组  ; 这里的用户名和组就是静态文件的user scott executor ;

    1240

    Paste_Image.png

  6. 检查配置正确性

    nginx -t

    上面的命令执行后返回以下内容则成功

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
  7. 重启nginx

    nginx stopnginx start


当你将 nginx 作为 web server 的时候,403 错误主要是下面两条原因:

一、所有者对目录没有写的权限。

此时可用 chmod 777 目录名 先完全放开权限,如果问题解决,则再慢慢缩小访问权限。

$ chown -R nginx_user:nginx_user /htdocs

二、未配置 index 的类型。

请在 nginx 相应 http 配置节添加 index 的配置。

index index.html index.php;

绝大部分这个报错都是各种权限问题

记录三

论坛点击管理中心,出现403报错,权限问题

查看网站配置文件,添加管理员电脑的外网IP

只允许管理员自己的电脑外网IP可以访问,其他都禁止访问

重启Nginx服务,然后点击论坛工具,更新缓存就解决了这个问题


vim /home/lnmp/nginx/conf/vhost/*.conf

location ~ .*admin.* {

    allow 管理员电脑外网IP/32;

    deny all;


location ~ .*\.php?$ {

    allow 管理员电脑外网IP/32;

    deny all;


service nginx reload


最后要注意的是,在本地电脑添加服务器的外网IP和域名做个解析