Apache根據URL路徑進行轉發

根據URL的PATH進行轉發,適合沒有域名的狀況下,例如:
     http://127.0.0.1/support       轉到 http://192.168.1.251:8008/support 
     http://127.0.0.1/gdForestry  轉到 http://192.168.1.251:9007/gdForestry  php

首先啓用代理模塊,去掉httpd.conf中的註釋: web

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so



而後配置虛擬主機,重啓完成(這裏用的Apache2.4,語法稍有不一樣):
<VirtualHost 127.0.0.1:80>
    ServerAdmin webmaster@dummy-host.example.com
    ServerName 127.0.0.1
    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
        Require all granted
    </Proxy>
    ProxyPass /support http://192.168.1.251:8008/support
    ProxyPass /gdForestry http://192.168.1.251:9007/gdForestry
    ProxyPassReverse /support http://192.168.1.251:8008/support
    ProxyPassReverse /gdForestry http://192.168.1.251:9007/gdForestry
    ErrorLog "logs/test.localhost-error_log"
    CustomLog "logs/test.localhost-access_log" common
</VirtualHost>



若是不須要配置在虛擬主機,要對全局進行轉發,則直接配置在httpd.conf最後添加:
ProxyPass /cas http://192.168.0.206:9090/cas
ProxyPassReverse /cas  http://192.168.0.206:9090/cas
相關文章
相關標籤/搜索