【问题标题】:Nginx config for pretty URLsNginx 配置漂亮的 URL
【发布时间】:2017-12-27 05:22:47
【问题描述】:

以前我为我的路由器使用 Apache 服务器(我有一个特殊的 .htaccess),一切都按预期工作:

请求:test.local/index/actiontest.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


【解决方案1】:

使用

server_name test.local;

改为

server_name  productlocator.local;

然后看看这个link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 2013-08-30
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 2013-05-06
    相关资源
    最近更新 更多