大网数据广告活动
服务器运维问答

Apache ProxyPass to Shared Ip Address for Domain

· 52CE 我爱测

I have a case where I need to proxy pass a domain (domain1.com) to a different domain (domain2.com) hosted on a shared ip address (192.168.168.168), but domain2.com DNS is pointed other than the shared ip address, so domain2.com …

问题原文

原帖链接 · user2341534 · CC BY-SA 4.0

I have a case where I need to proxy pass a domain (domain1.com) to a different domain (domain2.com) hosted on a shared ip address (192.168.168.168), but domain2.com DNS is pointed other than the shared ip address, so domain2.com cannot be used as the proxy pass, only the shared ip address.

Since the shared ip address has multiple hostnames, is there a domain or hostname configuration option that can be used with proxypass to force the virtual host lookup on the other side? For example, using this apache conf file to proxy domain1.com to 192.168.168.168.

#Apache Reverse Proxy
SSLProxyEngine on

<Location />
ProxyPass http://192.168.168.168/
ProxyPassReverse http://192.168.168.168/
</Location>

Are there any changes that can be made to tell what domain to lookup on that ip?

已采纳解答

原帖链接 · Johhnie · CC BY-SA 4.0

The webserver on the shared IP-address (192.168.168.168) relies on the Host header with a known host/domain-name to display the correct content.

You can normally achieve that easily by actually using that host/domain-name in the ProxyPass directive :

<Location />
    ProxyPass http://domain2.com/
    ProxyPassReverse http://domain2.com/
</Location>

Since you state that the actual DNS entry for domain2.com is incorrect you override that by adding domain2.com with the 192.168.168.168 IP-address in your web servers hosts file

# /etc/hosts 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

# added for Apache reverse proxy 
192.168.168.168 domain2.com

The alternative is to configure Apache explicitly to set the correct Host header, with an RequestHeader Directive, something along the lines of:

<Location />
    RequestHeader set Host "domain2.com"
    ProxyPass http://192.168.168.168/
    ProxyPassReverse http://domain2.com/
</Location>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-11-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。