Forbidden location when using alias in nginx for relative urls

前端 未结 2 1557
再見小時候
再見小時候 2021-01-02 08:32

I am trying to set up roundcube / phpldapadmin / ... with nginx on relative urls, e.g.:

example.com/roundcube
example.com/phpldapadmin

Firs

2条回答
  •  [愿得一人]
    2021-01-02 08:46

    The location and alias should both have a trailing / or neither have a trailing /. But in your case, you should be using root instead of alias for both location blocks.

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

    The fastcgi_index will not do anything in a location that only matches .php (see this document).

    The SCRIPT_FILENAME parameter is needed in both blocks (or neither if it is already in /etc/nginx/fastcgi_params).

提交回复
热议问题