標籤:技術分享 輸入 host 伺服器 80連接埠 server png code pre
工作需要,從同一個連接埠進入,在伺服器端分流,去執行不同連接埠的服務。用apache的reverse proxy的功能實現。
①「apache2ctl -M」查看proxy module(下面的★)是否載入。如果沒有載入,執行「a2enmod proxy_http」載入。
[email protected]:/etc/apache2/sites-available# apache2ctl -MLoaded Modules: core_module (static) so_module (static) mpm_event_module (shared) negotiation_module (shared) proxy_module (shared) ★ proxy_http_module (shared) ★ rewrite_module (shared) setenvif_module (shared) status_module (shared)
②Port 9596用的httpd conf檔案裡追加reverproxy的設定
作為前提,確保以下檔案,及檔案夾的存在
/var/wwwtest_9596/test/index.html
/var/wwwtest_9596/test/apachetest
<VirtualHost *:9596> ServerAdmin [email protected] DocumentRoot /var/wwwtest_9596/ ########追加部分######## <IfModule mod_proxy.c> #Reverse Proxy <Proxy *> Order Deny,Allow Deny from all Allow from all </Proxy> ProxyRequests Off #proxy setting ProxyPass /test/apachetest/ http://127.0.0.1:80/ ProxyPassReverse /test/apachetest/ http://127.0.0.1:80/ </IfModule> ########追加部分########</VirtualHost>
③「service apache2 restart」,重啟apache服務,以讓上述proxy設定生效。
④從瀏覽器裡輸入http://serverip:9596/test,此時執行的是9596連接埠下的服務。
⑤從瀏覽器裡輸入http://serverip:9596/test/apachetest/,此時執行的是80連接埠下的服務。一般80下預設的是開啟apache的測試頁面。
其實apache做了一個替換http://serverip:9596/test/apachetest/ -> http://serverip:80/
其實如果帶參數的話,會自動傳過去。http://serverip:9596/test/apachetest/?u=username&p=password -> http://serverip:80/?u=username&p=password
Apache的reverse proxy設定