【发布时间】:2017-12-27 05:22:47
【问题描述】:
以前我为我的路由器使用 Apache 服务器(我有一个特殊的 .htaccess),一切都按预期工作:
请求:test.local/index/action 由 test.local/index.php 处理。
我的 .htaccess 文件是:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
问题:现在,我需要在 Nginx 中实现相同的功能。我为我的网站实现了 nginx 配置,包括主要的 nginx.conf -nginx 文件夹- /include.d/test.conf 。我试过这个 test.conf 配置:
server {
listen 80;
listen [::]:80;
server_name productlocator.local;
root /var/www/test/;
index index.php index.html;
location ~ \.php$ {
# fastcgi_split_path_info ^(.+?\.php)(/.*)$;
try_files $uri $uri/ /index.php?$query_string;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
对test.local/index.php 的请求得到正确处理,但像test.local/index/action 这样的请求会导致404 Not Found 错误。
问题:如何配置 Nginx 以使我的路由器正常工作?
【问题讨论】:
-
您的服务器名称错误
标签: php nginx url-routing