我在 CentOS 7 上设置了 nginx 服务器 nginx/1.10.2。我已将 nginx 配置为使用 php-fpm PHP 5.4.16 (fpm-fcgi)(构建时间:2016 年 11 月 6 日 00:30:57)。
我使用在 /etc/php-fpm.d/piwik.conf 中配置的新池:
[piwik]
user = piwik
group = piwik
listen = /var/run/php5-fpm-piwik.sock
listen.owner = nginx
listen.group = nginx
;listen.mode = 0660
;php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_flag[allow_url_fopen] = off
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /
nginx.conf 的重要部分:
location ~ ^/piwik/(.*)$ {
root /usr/share/nginx/html;
try_files $uri =404;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm-piwik.sock;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_param PATH_INFO $fastcgi_script_name;
# include fastcgi_params;
include fastcgi.conf;
# fastcgi_param REQUEST_METHOD $request_method;
fastcgi_index info1.php;
}
当我请求http://localhost/piwik/info1.php它显示我 _SERVER["USER"] piwik
所以现在我只有在设置文件夹/usr/share/nginx/html/piwik 的正确权限时遇到问题。
正如我所读到的,用户需要对整个路径具有 x 权限才能遍历到正确的文件夹。文件夹和文件必须是可读的,对于 piwik,一些文件夹必须是可写的。因为 CentOS 7 默认启用 SELinux,所以我必须执行以下命令才能获得写入权限: chcon -R -t httpd_sys_content_rw_t /usr/share/nginx/html/piwik/tmp/ systemctl restart php-fpm
我已将用户和组更改为 piwik。但是当我设置以下权限 chmod 700 -R /usr/share/nginx/html/piwik/ 我无法访问这些文件。我收到权限被拒绝错误。我发现我需要权利 701:
drwx-----x. 13 piwik piwik 4096 18. Aug 09:49 .
drwxr-xr-x. 5 root root 4096 16. Aug 04:27 ..
-rwx-----x. 1 piwik piwik 932 8. Jun 2015 bower.json
-rwx-----x. 1 piwik piwik 38272 11. Apr 2016 CHANGELOG.md
...
...
请帮助我理解为什么我必须为其他用户启用可执行位。
好的,为了提供静态文件,甚至必须设置 775?!
谢谢你。
此致
编辑:
问题不在于动态 php 文件的服务。它提供静态文件,因为 nginx 在一个特定用户下运行。
我找到了这个链接: https ://serverfault.com/questions/370820/user-per-virtual-host-in-nginx
一个有用的评论是:在设置 vhost 时,给文档 root 一组 www-data 和 perms 0710(因为这需要 root 来配置 nginx,所以让您的自动化也设置必要的权限不是问题)。然后 docroot 的内容只需要 o+x 用于目录和 o+r 用于文件。
所以我认为这是一个很好的设置: nginx 以用户 nginx 运行以分隔不同的用户(应用程序)设置以下权限(以 root 身份运行):
ls -la /usr/share/nginx/
drwx--x--x. 6 nginx nginx 4096 18. Aug 19:18 html
groupadd pydio
useradd -g pydio pydio
mkdir /usr/share/nginx/html/pydio/
chown pydio:pydio -R /usr/share/nginx/html/pydio/
find /usr/share/nginx/html/pydio/ -type d -exec chmod 701 {} \;
find /usr/share/nginx/html/pydio/ -type f -exec chmod 704 {} \;
chmod 710 /usr/share/nginx/html/pydio/
请问有人可以查吗?