我们有一个自定义PHP应用程序,我们使用.htaccess文件编写并运行在Apache上,以处理url重写。我们正试图将其转换为使用Plesk Onyx下的FPM在NGINX下工作。如何让NGINX在自定义PHP应用程序上正确地重写和执行?
应用程序生成类似链接:
https://somedomain.com/mypage (same as index/mypage)
https://somedomain.com/index/sitemap
https://somedomain.com/blog/some-article-name
这些网址的映射到采取REQUEST_URI,并用它来渲染页面响应的index.php文件。
的应用程序的结构被嵌套如下:
docroot (/)
./index.php //handler for the request in/
./blog/index.php //handler for any request to /blog
每个的index.php期望接收的路径= {REQUEST_URI},以便它可以将请求映射到控制器和动作?。
我已经尝试了多种方式让NGINX使用tryfiles来重写,但没有运气。使用重写我可以/可以工作,但它不会渲染/ 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;
}