php-Nginx本地Web服务器的所有权和权限

前端之家收集整理的这篇文章主要介绍了php-Nginx本地Web服务器的所有权和权限 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在设置本地Nginx环境时遇到问题.我已经在网上阅读了无数的教程,并且一切似乎都使我的大脑有些混乱.

作业系统:OSX 10.11.4 El Capitan
Nginx的:1.8.1
PHP-FPM:5.5.31

我的网络根目录的文件目录如下所示:

  1. /webserver
  2. /webverver/PHPinfo.PHP
  3. /webserver/example
  4. /webserver/example/index.PHP

我可以使用curl或在访问本地主机的Web浏览器中访问默认的“欢迎使用Nginx页面.如果我随后浏览,则会得到文件的索引,但是PHP文件将尝试下载而不是执行.如果我尝试访问在local.example.com(已添加到我的主机文件)中创建的示例站点,那么我会使用curl获得403 Forbidden标头返回,并使用网络浏览器返回一个简单易用的“拒绝访问” .

我对文件权限和目录所有权不是很了解,有人可以建议我如何配置所有内容吗?建议我运行以下命令,但到目前为止它什么都没有改变:

须藤chmod -R 755 / Users / nickcorin / webserver

除“信号已启动”日志外,我的错误日志中没有任何日志.

这是我目前的配置:

Nginx.conf

  1. #user nobody;
  2. worker_processes 1;
  3. error_log logs/error.log;
  4. error_log logs/error.log notice;
  5. error_log logs/error.log info;
  6. #pid logs/Nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. '$status $body_bytes_sent "$http_referer" '
  15. '"$http_user_agent" "$http_x_forwarded_for"';
  16. access_log logs/access.log main;
  17. sendfile on;
  18. tcp_nopush on;
  19. keepalive_timeout 65;
  20. #gzip on;
  21. server {
  22. listen 80;
  23. server_name localhost;
  24. location / {
  25. root /Users/nickcorin/webserver;
  26. autoindex on;
  27. }
  28. # redirect server error pages to the static page /50x.html
  29. #
  30. error_page 500 502 503 504 /50x.html;
  31. location = /50x.html {
  32. root html;
  33. }
  34. }
  35. include servers/*;
  36. }

服务器/示例

  1. upstream PHP {
  2. server 127.0.0.1:9000;
  3. }
  4. server {
  5. listen 80;
  6. root /Users/nickcorin/webserver/example;
  7. server_name local.example.com;
  8. index index.PHP index.html index.htm;
  9. autoindex on;
  10. location ~ \.PHP${
  11. try_files $uri $uri/ /index.PHP?$args ;
  12. index index.html index.htm index.PHP;
  13. fastcgi_param PATH_INFO $fastcgi_path_info;
  14. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  15. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  16. fastcgi_pass 127.0.0.1:9000;
  17. fastcgi_index index.PHP;
  18. fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
  19. fastcgi_intercept_errors on;
  20. include fastcgi_params;
  21. }
  22. }

**编辑-Nginx文件夹权限&流程负责人**

我在日志文件夹/usr/local/var / Nginx上运行ls -la,结果如下:

  1. drwxr-xr-x 4 nickcorin admin 136 Apr 20 23:53 .
  2. drwxr-xr-x 5 nickcorin admin 170 Apr 20 21:47 ..
  3. -rw-r--r-- 1 root admin 4718 Apr 21 08:06 access.log
  4. -rw-r--r-- 1 nickcorin admin 480 Apr 21 10:28 error.log

这是我的网络服务器根目录上的结果:

  1. drwxr-xr-x 4 nickcorin staff 136 Apr 22 12:23 .
  2. drwx-----x+ 54 nickcorin staff 1836 Apr 22 10:01 ..
  3. drwxr-xr-x 3 nickcorin staff 102 Apr 20 22:14 example
  4. -rw-r--r--@ 1 nickcorin staff 23 Apr 19 11:58 info.PHP

这是ps aux的结果| grep Nginx

  1. root 756 0.0 0.0 2466616 480 ?? Ss 12:24PM 0:00.00 Nginx: master process Nginx
  2. nickcorin 759 0.0 0.0 2445080 820 s000 S+ 12:24PM 0:00.00 grep Nginx
  3. nobody 757 0.0 0.0 2475832 1044 ?? S 12:24PM 0:00.00 Nginx: worker process

**编辑#2-虚拟主机配置文件**

我设法解决了我的问题,现在一切似乎进展顺利.我必须将虚拟主机配置文件编辑为此:

  1. server {
  2. listen 80;
  3. listen [::]:80 ipv6only=on;
  4. server_name local.example.com;
  5. root /Users/nickcorin/webserver/example;
  6. index index.PHP index.html index.htm;
  7. location ~ \.PHP${
  8. try_files $uri =404;
  9. fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
  10. fastcgi_pass 127.0.0.1:9000;
  11. fastcgi_index index.PHP;
  12. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  13. include fastcgi_params;
  14. }
  15. }

我还通过以下两行修复了我的权限:

  1. sudo chown -R nickcorin /Users/nickcorin/webserver (Web Server Root)
  2. sudo chmod 755 /Users/nickcorin/webserver/example (Virtual Host Root)

谢谢所有帮助我弄清楚这个问题的人:)

最佳答案
案件清单:

>确保“ 403禁止”是由Web服务器而不是应用程序脚本引起的.例如使index.PHP看起来像

  1. echo 'hi there';

如果错误仍然存​​在,则可能是我们配置了错误的Web服务器.

>找出由Web服务器生成的权限拒绝错误的原因.您可以临时将此指令添加到服务器/示例配置中(也许在server_name之后):

  1. error_log /var/log/Nginx/example.error.log warn

甚至如此

  1. error_log /var/log/Nginx/example.error.log notice

但是根据您的Nginx.conf,您已经完成了此操作,因此请检查日志文件以查找有关权限相关问题的信息.

通常,您应该在其中找到问题的具体描述-文件无效权限,套接字无效权限或上游问题.

>修正错误.这通常取决于我们在上一步中找到的内容.

一种.对Web服务器上托管的文件的权限错误.

1)谁是谁-确定Web服务器用户(默认情况下为Nginx)以及站点目录的所有者和组(/ Users / nickcorin / webserver / example).对于Nginx用户(用户,nickcorin和Web服务器),每个父目录(本身)应(至少)是可执行文件(–x).

2)虽然示例dir及其所有内容也应可读(r-x).为此,可以使用以下命令:

  1. # cd example
  2. # find . -type d | xargs chmod 755
  3. # find . -type f | xargs chmod 644

(这样做不会像sudo chmod -R 755 / Users / nickcorin / webserver那样使文件可执行)

b.上游故障排除.使用上游PHP {服务器127.0.0.1:9000;检查防火墙(如果有)是否正常. }

注1. “ Welcome to Nginx” html文档通常存储在/usr/share /中,具有必需的授权.

笔记2.最好在系统中使用一些位置,该位置将为您的环境手动创建并设置所有必需的访问权限,而不是使用带有700个权限的用户目录(并导致设置权限相关的其他步骤).

注意3.请记住,当目录中没有索引文件时,也会响应“ 403 Forbidden”.

猜你在找的Nginx相关文章