10

相対 URL で Nginx を使用して roundcube / phpldapadmin / ... をセットアップしようとしています。

example.com/roundcube
example.com/phpldapadmin

ソースは次のフォルダーにあります。

/var/www/roundcube
/usr/share/phpldapadmin

Apache 2.4 ではすべて正常に動作していましたが、Nginx は初めてです。私は次locationのものを持っていますroundcube

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 forbidden次のログを含む を取得します。

2016/02/07 21:43:33 [エラー] 23047#0: *1 "/usr/share/phpldapadmin/htdocs" のディレクトリインデックスは禁止されています, クライアント: xxx.xxx.xxx.xxx, サーバー: , リクエスト: "GET /phpldapadmin/ HTTP/1.1"、ホスト: " "

許可を確認しました:

$ 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

4

2 に答える 2

14

locationandのalias両方に末尾がある/か、どちらにも末尾がない必要があり/ます。ただし、あなたの場合は、両方のロケーション ブロックrootの代わりに使用する必要があります。alias

location /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(このドキュメントを参照してください)。

このSCRIPT_FILENAMEパラメーターは両方のブロックで必要です (既に にある場合はどちらも必要ありません/etc/nginx/fastcgi_params)。

于 2016-02-08T20:01:36.220 に答える
1

nginx.confまたは、 >> userの先頭に書いてみることもできますusername

私はAWS Linux EC2インスタンスを使用しているので、私が書いた

user ec2-user;

それ以外の

user nginx;

これにより、必要なすべての権限を付与することで問題が解決します

于 2017-06-16T09:59:30.397 に答える