nginx 多根配置问题

nginx multiple root config issue

我有以下多根 nginx 配置(html/web 是默认值,html/pma 是附加路由):

server {

        listen 443 http2 ssl;
        listen [::]:443 http2 ssl;

        server_name  website.com;
        server_tokens off;

        root /usr/share/nginx/html/web; 
        index index.php;

        location / {    
            try_files $uri /index.php?$args;
        }

        location ^~ /pma {
            root /usr/share/nginx/html; 

            location ~ \.php$ {
            try_files  $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }

        }   


        location ~ \.php$ {
            try_files  $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }

因此,默认情况下 /html/web/index.php 打开,但是 website.com/pma 打开 /html/pma/,其中 pmaPHPMyAdmin

问题是:

PHPMyAdmin 身份验证表单重定向到 index.php。因此,当我写下我的凭据时,它会将我重定向到 /html/web/index.php!但是应该/html/pma/index.php。甚至从 PHPMyAdmin 注销重定向到 /html/web/index.php

谁能建议更好的配置方式?

我在您的配置中看到两个错误。

您的 try_files 语句应该以 /index.php=404 结尾,不能同时以 /index.php=404 结尾!有关详细信息,请参阅 this document

嵌套的 location ~ \.php$ 块永远不会被查询。外 location ~ \.php$ 块优先。您可以通过在周围前缀 location 上使用 ^~ 修饰符来解决此问题。有关详细信息,请参阅 this document。例如:

location ^~ /pma {
    ...
    location ~ \.php$ {
        ...
    }
}
location ~ \.php$ {
    ...
}