Apache的reverse proxy設定

來源:互聯網
上載者:User

標籤:技術分享   輸入   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設定

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.