2017-08-06 68 views
1

我有多个根以下nginx的配置(html/web是默认,html/pma是额外路线):nginx的多根配置问题

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

任何人都可以提出更好的配置方式吗?

+0

我不使用PMA,但是您是否已将'PmaAbsoluteUri'设置为指向'/ pma /'?请参阅[此链接](https://docs.phpmyadmin.net/en/latest/config.html#basic-settings)。 –

+0

将'index'移到'location'之外。 http://nginx.org/en/docs/http/ngx_http_index_module.html#index – Deadooshka

+0

@Deadooshka没有帮助。编辑问题 – Leeloo

回答

0

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

try_files声明应以/index.php=404结尾,而不是两个!详细信息请参见this document

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

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

谢谢,我会检查你的答案。你如何建议try_files被写入? – Leeloo

+0

假设路径'/ index.php'始终存在,** first **'try_files'语句中的'= 404'是多余的,使用:'try_files $ uri /index.php?$ args'。我不相信'$ uri /'这个术语有所帮助 - 因为它会违背你的重写规则 - 它的目的是在目录存在的情况下添加尾随的'/'。 –

+0

你的意思是我应该删除它呢? – Leeloo