试图弄清楚这一点非常困难。 我已经把我的网站从另一个平台更改为Joomla,现在Nginx无法处理旧的url。
我的老url是这样的:
example.com/home.php example.com/contact-us.php
我的新Joomla SEF的Url是这样的:
example.com/home example.com/contact-us
根据Joomla指南,我有以下的Nginxconfiguration:
location / { try_files $uri $uri/ /index.php?$args; } # Process PHP location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
我想让Nginx把这些旧的URL传给Joomla来处理它。 现在发生的事情是,Nginx将这些旧的url作为php文件处理,然后向我展示这个No input file specified.
错误。 然后,我改变了PHP块内的try_files为try_files $uri /index.php?$args;
所以我的Nginxconfiguration如下所示:
location / { try_files $uri $uri/ /index.php?$args; } # Process PHP location ~ \.php$ { try_files $uri /index.php?$args; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
这有效吗? 这会在某些情况下造成无限循环问题吗? 这是正确的方式来做到这一点? 我没有find任何类似的解决scheme。 有人可以指导我吗?
location /
从不使用 您所遇到的问题与位置优先权 (强调添加)有关。
nginx首先search由文字string给出的最具体的前缀位置,而不pipe列出的顺序如何。 […]然后nginx按照configuration文件中列出的顺序检查正则expression式给出的位置。 第一个匹配expression式会停止search ,nginx会使用这个位置。 如果没有正则expression式匹配请求,那么nginx使用前面find的最具体的前缀位置。
因此,这个位置块:
location ~ \.php$ { try_files $uri =404; # <-
符合此要求:
example.com/home.php
并没有其他位置块是相关的。
正如你已经意识到的那样,这意味着nginx会试图find并服务于home.php
导致404。
通常,唯一相关的php文件是index.php
,你可以像这样使用它:
try_files $uri $uri/ @joomla; location @joomla { include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root/index.php; fastcgi_param SCRIPT_NAME $document_root/index.php; fastcgi_param DOCUMENT_URI /index.php; fastcgi_index index.php; }
除了前端控制器,joomla允许/期待其他的PHP文件可以直接访问,如/administrator/index.php
。 要允许访问它们而不尝试处理缺less的php文件:
location ~ \.php$ { try_files $uri @joomla; include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
这将允许直接访问其他的PHP文件(通常,这不是一件好事…),通过@joomla
位置,使用/index.php
,返回任何不存在的php文件请求。
请注意,上述设置也在文档中 。