2016-01-08 43 views
1

apache問題。一定是簡單的,但我失敗了。基於子路徑的反向代理服務器

我試圖配置Apache作爲反向代理到它後面的兩臺服務器。棘手的部分是註冊代理規則的唯一區別是子路徑。

我的想法是:

mydomain.com -> localhost:8083 
mydomain.com/api -> localhost:8080/api 

目前我的配置是這樣的:

<VirtualHost *:80> 
     ProxyPreserveHost On 
     ProxyRequests Off 
     ServerName mydomain.com 
     ServerAlias www.mydomain.com 

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 

     ProxyPass/http://localhost:8083/ 
     ProxyPassReverse/http://localhost:8083/ 

     ProxyPass /api http://localhost:8080/api #already tried with slashes on both first and second parameters 
     ProxyPassReverse /api http://localhost:8080/api #already tried with slashes on both first and second parameters 

</VirtualHost> 

但/ API無法正常工作,它不斷將請求發送到8083.爲什麼任何想法?

感謝關注

回答

2

嘗試做 '/ API' 的ProxyPass + ProxyPassReverse的 '/' 的人之前。我強烈懷疑'/'是否充當了一個流行語,並且你從來沒有進入'/ api'的情況。這可以解釋爲什麼你總是去8083,這是'/'情況。

<VirtualHost *:80> 
     ProxyPreserveHost On 
     ProxyRequests Off 
     ServerName mydomain.com 
     ServerAlias www.mydomain.com 

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 

     ProxyPass /api http://localhost:8080/api #already tried with slashes on both first and second parameters 
     ProxyPassReverse /api http://localhost:8080/api #already tried with slashes on both first and second parameters 

     # do this last... 
     ProxyPass/http://localhost:8083/ 
     ProxyPassReverse/http://localhost:8083/ 


</VirtualHost> 
+0

你說得對。非常感謝! –

+0

很高興工作:) – obscurite

相關問題