本文 55779 pv

1

Mac OS X 下安装Nginx遇到的坑

© kekehu / 技术资源 / 2015.04.22 / 00:02 / 55779PV

我是通过brew install nginx的,前面都很顺利,
nginx常用命令:
    nginx -s stop/quit/reopen/reload
用ln -s 命令创建个软件链接于 /usr/sbin/ 下以方便操作。
直接搞个server看看效果,代码如下:
server {
    listen       80;
    server_name  www.geekso.com;
    index index.html index.htm index.php;
    root  /Users/han/Documents/git/msg/web/public;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }


    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include fastcgi.conf;
    }

    location ~ /(\.svn|\.git|\.ht|\.DS) {
        deny all;
        internal;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
         expires max;
         log_not_found off;
    }
}
然后sudo命令重启nginx,访问www.geekso.com发现php文件可以访问执行,访问图片、js、css...就报403 forbidden?
403不是没有权限嘛,好吧,加上权限750权限应该就能解决,加上去发现还是403,这下不懂了。会不会我nginx配置错了,一行行看,还是没找到问题,一直在想为什么同一目录下php文件可以访问,访问其它文件就报403,各种排除法,搞nginx, 还是不行。最终靠google搜索还真找到了遇到跟我一样的人。
解决方案:用ls -l 查看/Users/, /Users/xxx/, /Users/xxx/Documents/, /Users/xxx/Documents/git/ 的权限,确保均含最后一个x(其他用户的执行权限),倘若/Users/xxx/Documents/ 缺少x,执行 chmod o+x /Users/xxx/Documents/ 把x 权限添加上即可。
其实搞了半天也是权限问题。

本文有 1 篇评论

  1. @ 司法所 Email 说 :
    2016.05.03 17:38
    avatar

    我去,折腾了一下午,终于解决了,感谢楼主。原来是权限问题,搞死人啊。zanzanzan

1/1 第一页 1 最后页

发表你的见解

打开HTML 打开UBB 打开表情 隐藏 记住我
emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot
emotemotemotemotemot