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

2015-02-10 11:22:00 +08:00
 1dian01
第一种 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"
9369 次点击
所在节点    问与答
16 条回复
msg7086
2015-02-10 11:41:48 +08:00
你nginx在哪个权限下?
如果是纯粹自己用的话,nginx和php的运行用户都设成www-data,然后用你第一种里的命令就好了。
1dian01
2015-02-10 11:48:32 +08:00
@msg7086 nginx在www-data下面

请问如何设置php的运行用户
1dian01
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
2015-02-10 11:55:14 +08:00
php的pool里面找你的对应pool设定,里面user=和group=改掉就好了
msg7086
2015-02-10 11:56:28 +08:00
而且我看你上面写的是 No such file or directory 你确定是因为权限问题而不是你指错目录了?
1dian01
2015-02-10 11:58:20 +08:00
@msg7086 我的网站是可以正常打开的,所以应该不是指错目录
msg7086
2015-02-10 12:02:12 +08:00
你web目录的权限是?
1dian01
2015-02-10 12:03:47 +08:00
@msg7086 现在用的 chown -R www-data /web目录
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
2015-02-10 12:08:09 +08:00
是的,我的web目录是 usr/share/nginx/xxx

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

chmod -R 755 usr/share/nginx/xxx
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
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
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
2015-02-10 13:30:51 +08:00
@1dian01 看着没有问题啊。
那么就要回到最初了。
到底发生了什么错误。
特别是,如果网站访问一切正常的话,那你看到的错误信息是啥时候发生的?
1dian01
2015-02-10 14:11:44 +08:00
@msg7086 现在ok了,排除法,看起来是我添加了一个监听域名引起的,感谢!
msg7086
2015-02-10 14:16:30 +08:00
@1dian01 np.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/169771

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX