我试图在相对网址上设置带有Nginx的roundcube / PHPldapadmin / …,例如:
example.com/roundcube
example.com/PHPldapadmin
首先,Apache 2.4一切正常.我有以下文件夹:
# roundcube
/var/www/roundcube
# PHPldapadmin
/usr/share/PHPldapadmin
我有圆形立方体的以下位置:
location /roundcube/ {
root /var/www;
index index.PHP;
location ~ \.PHP${
try_files $uri =404;
include /etc/Nginx/fastcgi_params;
fastcgi_pass unix:/var/run/PHP5-fpm.sock;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
哪个工作正常,但PHPldapadmin的以下功能不起作用:
location /PHPldapadmin/ {
alias /usr/share/PHPldapadmin/htdocs;
index index.PHP index.html index.htm;
location ~ \.PHP${
try_files $uri =404;
fastcgi_pass unix:/var/run/PHP5-fpm.sock;
fastcgi_index index.PHP;
include /etc/Nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
我得到403禁用,包含以下日志:
2016/02/07 21:43:33 [error] 23047#0: *1 directory index of "/usr/share/PHPldapadmin/htdocs" is
forbidden,client: xxx.xxx.xxx.xxx,server: ****,request: "GET /PHPldapadmin/ HTTP/1.1",host: "****"
我检查了许可:
$namei -om /usr/share/PHPldapadmin/htdocs
f: /usr/share/PHPldapadmin/htdocs
drwxr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x root root share
drwxr-xr-x root root PHPldapadmin
drwxr-xr-x root www-data htdocs
$ls -l /usr/share/PHPldapadmin/htdocs/index.PHP
-rw-r--r-- 1 root root 20036 Oct 28 17:32 /usr/share/PHPldapadmin/htdocs/index.PHP
我尝试将所有者更改为:www-data但它不起作用.当我尝试使用以下方法进行roundcube时,它不起作用:
location /roundcube/ {
alias /var/www/roundcube;
...
}
我认为这可能是尾随/或类似的问题,但我对Nginx很新,所以我找不到它……
基本上,我有这个问题的反问题:https://stackoverflow.com/questions/31820362/nginx-403-directory-is-forbidden-when-using-root-location
位置和别名都应该有一个尾随/或者都没有尾随/.但在您的情况下,您应该为两个位置块使用root而不是别名.
原文链接:https://www.f2er.com/nginx/434831.htmllocation /roundcube {
root /var/www;
index index.PHP;
location ~ \.PHP${
try_files $uri =404;
fastcgi_pass unix:/var/run/PHP5-fpm.sock;
include /etc/Nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
location /PHPmyadmin {
root /usr/share;
index index.PHP index.html index.htm;
location ~ \.PHP${
try_files $uri =404;
fastcgi_pass unix:/var/run/PHP5-fpm.sock;
include /etc/Nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
fastcgi_index不会在仅匹配.PHP的位置执行任何操作(请参阅this document).
两个块中都需要SCRIPT_FILENAME参数(如果它已经在/ etc / Nginx / fastcgi_params中,则不需要).