nginx多根配置问题

时间:2017-08-06 09:44:46

标签: nginx url-rewriting config centos7

我有多个root的以下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

有人能建议更好的配置方式吗?

1 个答案:

答案 0 :(得分:0)

我可以在配置中看到两个错误。

try_files语句应以/index.php=404结尾,而不是两者都结束!有关详细信息,请参阅this document

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

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