2012-07-28 160 views
0

我做了一些廣泛的搜索,並且在nginx proxy_pass問題上有不少文章。我試着將問題修改爲其中一些問題,但沒有任何進展。nginx重寫/ proxy_pass問題

我正在重寫一個基於php的網站到Rails中。原始網站本身是簡單的2頁與表格。它使用Apache中的mod_rewrite/mod_proxy解決方案來掩蓋站點在表單發佈後繼續的URL。

這個php站點有3個目錄,它們只有3個.htaccess文件,爲了簡單起見,我們可以調用目錄a,b,c。具有以下

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteRule ^(.*)$ http://www.domainbeingpostedto.com/actual_letter_directory/$1 [P,L] 
</IfModule> 

我不是一個Apache的專家,但我敢肯定的[P,L]每個.htaccess文件是相同proxy_pass和上次在nginx的?

我想改寫這個解決方案爲PHP的網站,將其轉變成使用客運和nginx的,而不是軌釐米。

的解決方案,我至今不能工作,因爲Rails應用程序只是將返回未找到頁面中的404,所以我知道proxy_pass不轉發POST請求到其他服務器。 我有我的nginx.conf文件是:

server { 
    listen 80; 
    server_name newtestappdomain.com; 

    location /a/ { 
     proxy_pass http://www.domaintoacceptdatapostandbemasked.com/; 
     #rewrite ^/a/(.*)$ http://www.domaintoacceptdatapostandbemaskedcom/a/ last; 
    } 

    location /b/ { 
     proxy_pass http://www.domaintoacceptdatapostandbemasked.com/; 
     #rewrite ^/b/(.*)$ http://www.domaintoacceptdatapostandbemasked.com/b/ last; 
    } 

    location /c/ { 
     proxy_pass http://www.domaintoacceptdatapostandbemasked.com/; 
     #rewrite ^/c/(.*)$ http://www.domaintoacceptdatapostandbemasked.com/c/ last; 

    } 

    root /home/deploy/testapp/public; # <--- be sure to point to 'public'! 
    passenger_enabled on; 

} 

如果我取消了重寫規則,它只是反彈到我試圖掩蓋其他站點。我也做了一個頭部跟蹤來驗證。沒有看到任何發佈到其他域。我很難過,因爲我對nginx真的很陌生,不知道該怎麼做。 Apache在rails和mod_rewrite/mod_proxy下工作不好。任何見解都會很棒。

回答

1
proxy_pass http://www.domaintoacceptdatapostandbemasked.com/; 

此規則將請求代理到 「/」 位置(領先proxy_pass URI斜線)(A/B /和c /將丟失)。

只需使用URI沒有領先斜線,它應該工作完美

proxy_pass http://www.domaintoacceptdatapostandbemasked.com; 

如果您需要更改URI,你可以proxy_pass使用前重寫。 例如:

location /a/ { 
    rewrite /(a/.*)$ /actual_letter_directory/$1 break; # as from you .htaccess example 
} 
+0

結尾的斜線是問題所在。很容易修復,謝謝 – toucansam 2012-08-07 22:22:03