Forbidden location when using alias in nginx for relative urls
<p>I am trying to set up roundcube / phpldapadmin / ... with Nginx on relative urls, e.g.:</p>
<pre><code>example.com/roundcube
example.com/phpldapadmin
</code></pre>
<p>The source are in the following folders:</p>
<pre><code>/var/www/roundcube
/usr/share/phpldapadmin
</code></pre>
<p>Everything was working fine with Apache 2.4 but I am new to Nginx. I have the following <code>location</code> for <code>roundcube</code>:</p>
<pre><code>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;
    }
}
</code></pre>
<p>Which works fine, but the following for <code>phpldapadmin</code> does not work:</p>
<pre><code>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;
    }
}
</code></pre>
<p>I get a <code>403 forbidden</code>, with the following logs:</p>
<blockquote>
<p>2016/02/07 21:43:33 [error] 23047#0: *1 directory index of &quot;/usr/share/phpldapadmin/htdocs&quot; is forbidden, client: xxx.xxx.xxx.xxx, server: <strong><strong>, request: &quot;GET /phpldapadmin/ HTTP/1.1&quot;, host: &quot;</strong></strong>&quot;</p>
</blockquote>
<p>I checked the permission:</p>
<pre><code>$ 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
</code></pre>
<p>I tried changing the owner to <code>:www-data</code> but it did not work. When I tried the following for roundcube it did not work:</p>
<pre><code>location /roundcube/ {
    alias /var/www/roundcube;
    ...
}
</code></pre>
<p>I am thinking that this is probably a problem with a trailing <code>/</code>, or something similar, but I am really new to nginx so I can't find it...</p>
<p>Basically, I have the inverse problem of: <a href="https://stackoverflow.com/questions/31820362/nginx-403-directory-is-forbidden-when-using-root-location">https://stackoverflow.com/questions/31820362/nginx-403-directory-is-forbidden-when-using-root-location</a></p>