我們有一個自定義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;
}