代理 / 重定向
最后更新于:2022-04-02 02:55:18
[TOC]
## 开启模块
去掉httpd.conf中的注释
```
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
```
## 配置
### 在虚拟主机汇中配置
适合用在单个域下
```
ServerAdmin webmaster@dummy-host.example.com
ServerName 127.0.0.1
ProxyRequests Off
ProxyPreserveHost On
Require all granted
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
```
### 配置全局
```
ProxyPass /cas http://192.168.0.206:9090/cas
ProxyPassReverse /cas http://192.168.0.206:9090/cas
```
## 方法
### ProxyPass
#### 反向代理
```
DocumentRoot ../ant_universal_10
ServerName default:8000
ErrorLog logs/default-error_log
Options FollowSymLinks
AllowOverride All
Require all granted
ProxyPass /imapp/depts http://127.0.0.1:8081/imapp/depts
```
> 在内部进行代理
##### 排除无需代理的
```
ProxyPass /mirror/foo/i !
ProxyPass /mirror/foo http://backend.example.com
```
### ProxyPassMatch
```
ProxyPassMatch ^(/.*\.gif)$ http://backend.example.com:8000$1
ProxyPassMatch ^/\d{4}-\d{2}-\d{2} http://www.baidu.com/$1 // 把 /2019-10-10 代理到 www.baidu.com/xxxx
```
`http://example.com/foo/bar.gif`,那内部将会转换为这样的请求`http://backend.example.com/foo/bar.gif`。
';