在nginx中为相对URL使用别名时的禁止位置

前端之家收集整理的这篇文章主要介绍了在nginx中为相对URL使用别名时的禁止位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图在相对网址上设置带有Nginx的roundcube / PHPldapadmin / …,例如:

  1. example.com/roundcube
  2. example.com/PHPldapadmin

首先,Apache 2.4一切正常.我有以下文件夹:

  1. # roundcube
  2. /var/www/roundcube
  3. # PHPldapadmin
  4. /usr/share/PHPldapadmin

我有圆形立方体的以下位置:

  1. location /roundcube/ {
  2. root /var/www;
  3. index index.PHP;
  4. location ~ \.PHP${
  5. try_files $uri =404;
  6. include /etc/Nginx/fastcgi_params;
  7. fastcgi_pass unix:/var/run/PHP5-fpm.sock;
  8. fastcgi_index index.PHP;
  9. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  10. }
  11. }

哪个工作正常,但PHPldapadmin的以下功能不起作用:

  1. location /PHPldapadmin/ {
  2. alias /usr/share/PHPldapadmin/htdocs;
  3. index index.PHP index.html index.htm;
  4. location ~ \.PHP${
  5. try_files $uri =404;
  6. fastcgi_pass unix:/var/run/PHP5-fpm.sock;
  7. fastcgi_index index.PHP;
  8. include /etc/Nginx/fastcgi_params;
  9. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  10. }
  11. }

我得到403禁用,包含以下日志:

  1. 2016/02/07 21:43:33 [error] 23047#0: *1 directory index of "/usr/share/PHPldapadmin/htdocs" is
  2. forbidden,client: xxx.xxx.xxx.xxx,server: ****,request: "GET /PHPldapadmin/ HTTP/1.1",host: "****"

我检查了许可:

  1. $namei -om /usr/share/PHPldapadmin/htdocs
  2. f: /usr/share/PHPldapadmin/htdocs
  3. drwxr-xr-x root root /
  4. drwxr-xr-x root root usr
  5. drwxr-xr-x root root share
  6. drwxr-xr-x root root PHPldapadmin
  7. drwxr-xr-x root www-data htdocs
  8. $ls -l /usr/share/PHPldapadmin/htdocs/index.PHP
  9. -rw-r--r-- 1 root root 20036 Oct 28 17:32 /usr/share/PHPldapadmin/htdocs/index.PHP

我尝试将所有者更改为:www-data但它不起作用.当我尝试使用以下方法进行roundcube时,它不起作用:

  1. location /roundcube/ {
  2. alias /var/www/roundcube;
  3. ...
  4. }

我认为这可能是尾随/或类似的问题,但我对Nginx很新,所以我找不到它……

基本上,我有这个问题的反问题:https://stackoverflow.com/questions/31820362/nginx-403-directory-is-forbidden-when-using-root-location

位置和别名都应该有一个尾随/或者都没有尾随/.但在您的情况下,您应该为两个位置块使用root而不是别名.

  1. location /roundcube {
  2. root /var/www;
  3. index index.PHP;
  4. location ~ \.PHP${
  5. try_files $uri =404;
  6. fastcgi_pass unix:/var/run/PHP5-fpm.sock;
  7. include /etc/Nginx/fastcgi_params;
  8. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  9. }
  10. }
  11. location /PHPmyadmin {
  12. root /usr/share;
  13. index index.PHP index.html index.htm;
  14. location ~ \.PHP${
  15. try_files $uri =404;
  16. fastcgi_pass unix:/var/run/PHP5-fpm.sock;
  17. include /etc/Nginx/fastcgi_params;
  18. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  19. }
  20. }

fastcgi_index不会在仅匹配.PHP的位置执行任何操作(请参阅this document).

两个块中都需要SCRIPT_FILENAME参数(如果它已经在/ etc / Nginx / fastcgi_params中,则不需要).

猜你在找的Nginx相关文章