2015-11-23 79 views
0

我用nginx和apache建立了本地機器。我使用nginx作爲所有nodejs通信的前端服務器。每個nodejs應用程序都有自己的上游定義,並在我的hosts文件中有一個條目,這樣我就可以得到一個方便的URL。另外,我有一個爲apache定義的上游,它在我的配置中工作在端口8080上 - 這樣我所有的php應用程序都可以在localhost/*(內部是localhost:8080/*)下使用。此配置現在可以正常工作幾個月。但是這次我想在本地機器上安裝magento安裝。爲此我加入127.0.0.1 magento.local我的hosts文件(像我一樣對所有應用程序的NodeJS),並增加了以下我的nginx.conf:帶有nginx和Apache的虛擬主機

upstream apache { 
    server 127.0.0.1:8080; 
} 

server { 
    listen  80; 
    server_name magento.local; 
    client_max_body_size 1024M; 
    root /Users/phunkei/htdocs/magento; 
    location/{ 
     proxy_set_header Host $http_host; 
     proxy_set_header X-Forwarded-For $remote_addr; 
     proxy_pass http://apache; 
    } 
} 

這改寫一切/Users/phunkei/htdocs/,這是我的Apache根。我已經嘗試向上遊定義server 127.0.0.1:8080/magento添加子文件夾,但nginx不允許這樣做。

+0

不知道你想達到的目標。但是'root'語句是多餘的。它不是必需的,也沒有使用。你想要做'proxy_pass http:// apache/magneto /;'? –

+0

是的,它會爲網址添加「magento」,導致產生「http:// magento.local/magento」。我試圖讓'http://magento.local/'point到'/ Users/phunkei/htdocs/magento'或'http:// localhost:8080/magento' – Daniel

回答

0

目前你代理一切,所以http://magento.local/指向​​。

如果你想http://magento.local/指向http://localhost:8080/magento/你需要使用:

proxy_pass http://apache/magneto/; 

如果你想從nginx使用root /Users/phunkei/htdocs/magento直接服務於一些靜態的內容,你將需要添加指令來實現這一點,這樣的作爲移動代理代碼到指定位置,並使用try_files

location/{ 
    try_files $uri $uri/ @proxy; 
} 
+0

我已經嘗試過'proxy_pass http:// apache/magento /;',但它導致302重定向到'http:// localhost/magento /' – Daniel

+0

302看起來像是來自'apache'而不是'nginx'。 apache訪問日誌說什麼? –