V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
1dian01
V2EX  ›  问与答

nginx web 目录下权限设置哪个是对的?

  •  
  •   1dian01 · 2015-02-10 11:22:00 +08:00 · 9339 次点击
    这是一个创建于 3371 天前的主题,其中的信息可能已经有所发展或是发生改变。
    第一种 chown -R www-data /web目录
    第二种 chown -R www-data /web目录/*

    目前我用的是第一种,但是/var/log/nginx/error.log老是提示:

    [error] 20461#0: *3 FastCGI sent in stderr: "Unable to open primary script: /usr/share/nginx/xxx/index.php (No such file or directory)" while reading response header from upstream, client: 91.16.139.115, server: www.xxx.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.xxx.com"
    16 条回复    2015-02-10 14:16:30 +08:00
    msg7086
        1
    msg7086  
       2015-02-10 11:41:48 +08:00
    你nginx在哪个权限下?
    如果是纯粹自己用的话,nginx和php的运行用户都设成www-data,然后用你第一种里的命令就好了。
    1dian01
        2
    1dian01  
    OP
       2015-02-10 11:48:32 +08:00
    @msg7086 nginx在www-data下面

    请问如何设置php的运行用户
    1dian01
        3
    1dian01  
    OP
       2015-02-10 11:54:29 +08:00
    @msg7086

    etc/php5/fpm/pool.d/www.conf 中

    user = www-data
    group = www-data

    也是在 www-data下面
    msg7086
        4
    msg7086  
       2015-02-10 11:55:14 +08:00   ❤️ 1
    php的pool里面找你的对应pool设定,里面user=和group=改掉就好了
    msg7086
        5
    msg7086  
       2015-02-10 11:56:28 +08:00
    而且我看你上面写的是 No such file or directory 你确定是因为权限问题而不是你指错目录了?
    1dian01
        6
    1dian01  
    OP
       2015-02-10 11:58:20 +08:00
    @msg7086 我的网站是可以正常打开的,所以应该不是指错目录
    msg7086
        7
    msg7086  
       2015-02-10 12:02:12 +08:00
    你web目录的权限是?
    1dian01
        8
    1dian01  
    OP
       2015-02-10 12:03:47 +08:00
    @msg7086 现在用的 chown -R www-data /web目录
    msg7086
        9
    msg7086  
       2015-02-10 12:05:36 +08:00
    @1dian01 权限,不是属主。
    另外你上面提示是 Unable to open primary script: /usr/share/nginx/xxx/index.php
    所以你web目录是 /usr/share/nginx/xxx ?
    1dian01
        10
    1dian01  
    OP
       2015-02-10 12:08:09 +08:00
    是的,我的web目录是 usr/share/nginx/xxx

    那我还需要另外设置权限?,这个对吗?

    chmod -R 755 usr/share/nginx/xxx
    youling
        11
    youling  
       2015-02-10 12:11:24 +08:00
    # find /home/yourblog/ -type d -exec chmod 755 {} ;
    # find /home/yourblog/ -type f -exec chmod 644 {} ;
    #chown www-data:www-data /home/yourblog/ -R
    msg7086
        12
    msg7086  
       2015-02-10 13:10:25 +08:00
    @1dian01 你不at我,我是看不到的。
    -R 755是不行的。
    以下是你要检查的问题。
    1. 用htop或者top或者ps来检查nginx和php-fpm的运行用户是否正确。
    2. 查看/usr/share/nginx/xxx目录以及里面index.php文件的权限。
    3. 试着su到www-data,访问你的程序index.php看看能否读取。
    1dian01
        13
    1dian01  
    OP
       2015-02-10 13:27:53 +08:00
    @msg7086 感谢!
    1.
    ps -u www-data
    PID TTY TIME CMD
    1382 ? 00:00:14 php5-fpm
    1383 ? 00:00:15 php5-fpm
    1384 ? 00:00:13 php5-fpm
    2187 ? 00:00:00 nginx
    2188 ? 00:00:00 nginx
    2189 ? 00:00:00 nginx
    2190 ? 00:00:00 nginx


    2.
    目录权限 755 index.php文件的权限 644

    3.
    第三个不知道咋处理,不过我的网站可以正常访问,应该是ok的
    msg7086
        14
    msg7086  
       2015-02-10 13:30:51 +08:00
    @1dian01 看着没有问题啊。
    那么就要回到最初了。
    到底发生了什么错误。
    特别是,如果网站访问一切正常的话,那你看到的错误信息是啥时候发生的?
    1dian01
        15
    1dian01  
    OP
       2015-02-10 14:11:44 +08:00
    @msg7086 现在ok了,排除法,看起来是我添加了一个监听域名引起的,感谢!
    msg7086
        16
    msg7086  
       2015-02-10 14:16:30 +08:00
    @1dian01 np.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1723 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:15 · PVG 00:15 · LAX 09:15 · JFK 12:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.