![在 apache 反向代理中处理位置标头](https://linux22.com/image/756826/%E5%9C%A8%20apache%20%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E4%B8%AD%E5%A4%84%E7%90%86%E4%BD%8D%E7%BD%AE%E6%A0%87%E5%A4%B4.png)
我使用的是 Apache/2.4.29 (Ubuntu),并将其配置为内部 Web 服务器的反向代理服务器。我的反向代理服务器地址是 10.0.0.1,它向公众公开,而我的内部服务器地址是 192.168.1.15,它是私有服务器。虚拟主机配置文件如下所示。
ServerName web.example.com
ServerAlias web.example.com
ProxyRequests off
ProxyPreserveHost On
ProxyPass / http://192.168.1.15/web/public/
ProxyPassReverse / http://192.168.1.15/web/public/
ProxyPassReverseCookiePath / /
<Location "/">
Order allow,deny
Allow from all
</Location>
ErrorLog ${APACHE_LOG_DIR}/web-error.log
CustomLog ${APACHE_LOG_DIR}/web-access.log combined
预期结果:http://web.example.com实际结果:http://web.example.com/web/public/
当我卷曲 URL 时..$curl -vhttp://web.example.com
Trying 10.0.0.1...
TCP_NODELAY set
Connected to web.example.com (10.0.0.1) port 80 (#0)
GET / HTTP/1.1
Host: web.example.com
User-Agent: curl/7.58.0
Accept: /
HTTP/1.1 302 Found
Date: Sun, 30 Aug 2020 13:28:09 GMT
Server: Apache/2.4.29 (Ubuntu)
Cache-Control: no-cache, private
Location: http://web.example.com/web/public/
Content-Length: 522
Content-Type: text/html; charset=UTF-8