大网数据广告活动
网站运营与故障问答

Proxy a domain from one server to another and retain domain name

· 52CE 我爱测

I have a single external address that points to a server that is serving multiple domains using virtual hosts. I would like to serve one of the virtual hosts on a new physical machine and am trying to use a reverse proxy to make …

问题原文

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

I have a single external address that points to a server that is serving multiple domains using virtual hosts. I would like to serve one of the virtual hosts on a new physical machine and am trying to use a reverse proxy to make this happen.

On the main server the configuration looks like this (names changed to protect the guilty):

<VirtualHost *:80>
    DocumentRoot /abc/htdocs/virtual/swnc
    ServerName swnc.org
    <Directory "/abc/htdocs/virtual/swnc">
        Options FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

On the new physical machine I have the domain referenced above configured with:

<VirtualHost *:80>
    ServerName swnc.org
    ProxyPass "/" "http://www.example.org/virtual/swnc"
    ProxyPassReverse "/" "http://www.example.org/virtual/swnc"
</VirtualHost>

This configuration works but the resulting URL is what is specified in the ProxyPass statement above rather than the "real" URL which should be swnc.org.

I tried adding ProxyPreserveHost On in the configuration but it did not make any difference. Is there something I am missing or is it simply not possible to proxy the request to the new machine and retain the "real" domain name?

Update:

Here are the Apache configuration files on the old server and the new server using the suggestions from Stephen's answer.

Old Server

<VirtualHost *:80>
    ServerName ncdrought.org
    ProxyPass "/" "http://new.ncdrought.org"
    ProxyPassReverse "/" "http://new.ncdrought.org"
</VirtualHost>

New Server

<VirtualHost *:80>
    ServerName   new.ncdrought.org
    DocumentRoot /var/www/ncdrought.org
    <Directory "/var/www/ncdrought.org">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
</VirtualHost>

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 4.0

The proxy directives have to go on the the old machine. The machine that is acting like the pass-through needs to be configured as the proxy.

On your new machine, you need to set it up with a different host name, like a sub-domain, .local domain, or IP address that can be accessed on your internal network.

So the configuration should like like this:

old machine

<VirtualHost *:80>
    ServerName swnc.org
    ProxyPass "/" "http://swnc-backend.local/"
    ProxyPassReverse "/" "http://swnc-backend.local/"
</VirtualHost>

new machine

<VirtualHost *:80>
    DocumentRoot /abc/htdocs/virtual/swnc
    ServerName swnc-backend.local
    <Directory "/abc/htdocs/virtual/swnc">
        Options FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

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

资料来源与适用范围

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

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

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