Forbidden location when using an alias in nginx for relative URLs

I am trying to configure roundcube / phpldapadmin / ... from nginx to relative URLs, for example:

example.com/roundcube
example.com/phpldapadmin

First of all, everything worked perfectly with Apache 2.4. I have the following folders:

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

I have locationfor 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;
    }
}

Which works fine, but the following phpldapadmindoes not work:

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;
    }
}

I get 403 forbiddenwith the following logs:

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: "****"

I checked the resolution:

$ 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

I tried changing the owner to :www-data, but it did not work. When I tried the following for roundcube, it did not work:

location /roundcube/ {
    alias /var/www/roundcube;
    ...
}

I think this is probably a problem with a finite /or something similar, but I'm really new to nginx, so I can't find it ...

, : https://stackoverflow.com/questions/31820362/nginx-403-directory-is-forbidden-when-using-root-location

+4
2

location 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).

+2

nginx.conf → user username

AWS Linux EC2,

user ec2-user;

user nginx;

,

0

Source: https://habr.com/ru/post/1627692/


All Articles