【发布时间】:2017-07-28 15:56:39
【问题描述】:
我们有一个自定义的 PHP 应用程序,我们编写并在 Apache 上运行,使用 .htaccess 文件来处理 url 重写。我们正在尝试将其转换为在 NGINX 下使用 Plesk Onyx 下的 FPM 工作。
应用程序生成如下链接:
https://somedomain.com/mypage (same as index/mypage)
https://somedomain.com/index/sitemap
https://somedomain.com/blog/some-article-name
这些 URL 映射到 index.php 文件,这些文件采用 request_uri 并使用它来呈现页面响应。
应用的结构嵌套如下:
docroot (/)
./index.php //handler for the request in /
./blog/index.php //handler for any request to /blog
每个 index.php 都希望收到一个 ?path={request_uri} 以便它可以将请求映射到控制器和操作。
我尝试了多种方法让 NGINX 使用 tryfiles 和重写来执行此操作,但没有运气。使用 rewrite 我可以让 / 工作,但它不会呈现 /mypage 或 /index/sitemap。
如果我尝试点击 /index/sitemap,它会下载 index.php 而不是执行它,如果我尝试访问博客,也会发生同样的事情。事实上,唯一有效的路径是 /,所有其他路径只是下载 index.php 文件。
这是我现在的配置,我哪里出错了?
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control “public”;
try_files $uri @fallback;
}
location / {
#index index.php index.html index.html;
rewrite ^/([^?]*) /index.php?path=$1 break;
rewrite ^blog/([^?]*) /blog/index.php?path=$1 break;
#try_files $uri @fallback;
}
【问题讨论】: