2017-05-31 180 views
0

如何改造這個nginx的配置阿帕奇try_files模擬

location/{ 
    try_files /public/$uri @app; 
} 

location @app { 
    fastcgi_pass php5-fpm; 
} 

}

到Apache的配置?

+0

這是一個有趣的問題,因爲在/公衆甚至PHP文件將返回明文和位置上的過濾/公衆不能因爲使用。如果文件不存在,它會仍然傳遞給PHP。 – pucky124

回答

0

這是你可以使用(需要一定的調整我猜):

Alias /public /xxxxx/public 

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/public/ 
RewriteCond /xxxxx/public/%{REQUEST_URI} !-f 
RewriteCond /xxxxx/public/%{REQUEST_URI} !-d 
RewriteRule . "-" [H=application/x-httpd-php] 

RewriteCond %{REQUEST_URI} !^/public/ 
RewriteRule (.) /public/$1 [L,QSA] 

application/x-httpd-php是PHP處理程序,它可以在你的設置(fcgid腳本/應用/ PHP的不同... )檢查你的php安裝程序定義的處理程序。

0

這實際上只是做了兩件事。

  1. 如果該文件存在於root的公共子目錄中,則將其返回。
  2. 否則,將其發送到php。

所以在Apache的,我們需要做測試第一

RewriteCond %{DOCUMENT_ROOT}/public/%{REQUEST_URI} -f 
RewriteRule (.*) /public/$1 [L] 

的RewriteCond提出以下規則的條件,-f意味着該文件存在。所以我們知道該文件存在於公共子目錄中,所以應用將請求重寫到公共子目錄的規則。 L標誌意味着Apache將認爲這是最後一個重寫規則,並且不處理任何其他重寫規則。

現在爲第二部分。

RewriteRule . "-" [H=application/x-httpd-php] 

當然,這個假設所有相應的Apache模塊安裝和積極的,特別是mod_rewrite的和RewriteEngine on已經被調用。值得一提的是,在nginx和apache中都有很多選項必須設置才能正常工作。

更多文檔瀏覽:http://httpd.apache.org/docs/current/mod/mod_rewrite.html