关于Apache 设置反向代理的一个注意问题
2020-02-16 05:00
555 查看
Apache 反向代理默认会改写Request head中的host,这样会造成在应用中如果使用reqeust.getHead("host")来做绝对路径的时候存在无法连接的问题。
网上很多Apache的proxy设置都只写了ProxyPass 和 ProxyPassReverse
ProxyPass / http://172.18.100.51/
ProxyPassReverse / http://172.18.100.51/
[/code]
这个时候如果在应用中使用reqeust.getHead("host") 或者PHP中使用$_SERVER['HTTP_HOST'] 绝对路径来请求js或者css 就会是172.18.100.5,本地浏览器如果是在外网就无法访问了。
只需要在Apache中添加
ProxyPreserveHost On
[/code]
就可以解决这个问题
在Apache官方文档中关于他的描述
ProxyPreserveHost Directive
Description:Use incoming Host HTTP request header for proxy request
Syntax:ProxyPreserveHost On|Off
Default:ProxyPreserveHost Off
Context:server config, virtual host, directory
Status:Extension
Module:mod_proxy
Compatibility:Usable in directory context in 2.3.3 and later.
When enabled, this option will pass the Host: line from the incoming request to the proxied host, instead of the hostname specified in the ProxyPass line.
This option should normally be turned Off. It is mostly useful in special configurations like proxied mass name-based virtual hosting, where the original Host header needs to be evaluated bythe backend server.
[/code]
同理 Nginx 中也有一个类似的参数
proxy_set_header Host $host;
[/code]
转载于:https://my.oschina.net/caiw/blog/289103
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Nginx 反向代理基本框架
- Nginx的使用(反向代理,负载均衡)
- nginx反向代理
- Squid服务日志分析
- 解决nginx proxy_pass反向代理cookie,session丢失的问题
- Kubernetes用nginx反向代理另外服务
- Nginx反向代理缓存架构设计
- 负载均衡与反向代理理解
- 配置反向代理(到指定文件的静态文件)
- vanish高速反向代理服务器配置
- 在CentOS7上部署squid缓存服务器及代理功能
- 关于修改banner信息;nginx反向代理apache应用
- 新手入门:一分钟学会反向代理!
- squid.conf 详解
- 负载均衡 和 反向代理
- 最有价值的squid3.0配置说明:squid对应不同端口提供服务
- nginx反向代理ajax,解决跨域问题
- nginx简单配置反向代理和负载均衡
- Apache:反向代理配置
- 动态PHP电商网站伪静态的Nginx反向代理Cache缓存终级设置