[TOC] ## 开启模块 去掉httpd.conf中的注释 ``` LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so ``` ## 配置 ### 在虚拟主机汇中配置 适合用在单个域下 ``` <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> ``` ### 配置全局 ``` ProxyPass /cas http://192.168.0.206:9090/cas ProxyPassReverse /cas http://192.168.0.206:9090/cas ``` ## 方法 ### ProxyPass 实例1:不同代理 ``` ProxyPass /mirror/foo/ http://backend.example.com/mirror/foo/ ``` 实例2:排除无需代理的 ``` ProxyPass /mirror/foo/i ! ProxyPass /mirror/foo http://backend.example.com ``` ### ProxyPassMatch ``` ProxyPassMatch ^(/.*\.gif)$ http://backend.example.com:8000$1 ``` `http://example.com/foo/bar.gif`,那内部将会转换为这样的请求`http://backend.example.com/foo/bar.gif`。