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

Apache reverse proxy not keeping domain name

· 52CE 我爱测

I have a site e.g. example.wordpress.com (a subsite wordpress multisite) but I want users to see the content of that site under a different domain e.g. cooking.com . I have A record setup for both domains to forward to same IP, a…

问题原文

原帖链接 · Gitnik · CC BY-SA 3.0

I have a site e.g. example.wordpress.com (a subsite wordpress multisite) but I want users to see the content of that site under a different domain e.g. cooking.com. I have A record setup for both domains to forward to same IP, and I have read that if I want to keep domain name in the URL that I need to use mod_proxy. This is my setup:

<VirtualHost *:80>
    ServerName cooking.com

    ProxyRequests Off
    <Proxy *>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Proxy>
    ProxyPass / http://example.wordpress.com/
    ProxyPassReverse / http://example.wordpress.com/
</VirtualHost>

However, when I type cooking.com in my browser, it redirects me to example.wordpress.com and displays its URL instead of cooking.com. What's wrong with my apache file?

I have also tried using mod_rewrite instead, but I still get the same result:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^cooking.com$ [NC]
RewriteRule ^(.*)$ http://example.wordpress.com/$1 [L,P,NC]

I have enabled mod_proxy and mod_proxy_http, and I'm using Apache 2.4 on Ubuntu 16.04.

已采纳解答

原帖链接 · Gitnik · CC BY-SA 3.0

I've resolved the issue. For reasons unknown to me original site was forcing HTTPS (although I didn't configure it). As user ezra-s suggested (upon examining the Location in response headers) I have changed ProxyPassReverse to redirect to HTTPS domain (which lead into infinite loop). However, upon examining the apache logs, and googling, the solution was to add SSLProxyEngine on. It works now, and it redirects to the site but without changing URL in the browser.

Note for beginners like me

You can look at response headers in the developers console in your browser, just go to the network tab, and (re)load the page.

Note for wordpress multisite users

Although the domain for subsite is changed, site still contains links to it's pages addressed to the old domain.

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

资料来源与适用范围

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

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

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