将 2 个子域反向代理到 Apache 中的单个服务器
Reverse proxy 2 subdomains to single server in Apache
我无法通过反向代理在同一台服务器上配置 2 个子域。
情况:3 台服务器 Raspbian Stretch 和 Apache 2.4:
- 服务器 #1 服务
somedomain.com
并为 otherdomain.com
、sub1.otherdomain.com
和 sub2.otherdomain.com
做反向代理
- 服务器 #2 服务
otherdomain.com
- 服务器 #3 服务于
sub1.otherdomain.com
和 sub2.otherdomain.com
somedomain.com
、otherdomain.com
和 sub1.otherdomain.com
工作正常,但我在使用 sub2.otherdomain.com
时遇到问题:它导致 somedomain.com
.
这就是我在服务器 #1 的 etc/apache2/sites-available/000-default.conf
中配置反向代理的方式:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName sub1.otherdomain.com
ProxyPass / http://192.168.1.111/
ProxyPassReverse / http://192.168.1.111/
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ServerName sub2.otherdomain.com
ProxyPass / http://192.168.1.111/
ProxyPassReverse / http://192.168.1.111/
</VirtualHost>
这就是我在服务器 #3 上配置 etc/apache2/sites-available/000-default.conf
的方式:
<VirtualHost *:80>
ServerName sub1.otherdomain.com
DocumentRoot /home/username/website1/public_html
RemoteIPHeader X-Forwarded-For
<Directory /home/username/website1/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName sub2.otherdomain.com
DocumentRoot /home/username/website2/public_html
RemoteIPHeader X-Forwarded-For
<Directory /home/username/website2/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
我想通了:这是 Google Chrome 的缓存。当我还在玩 Apache 配置文件时,它以某种方式缓存了重定向。
它在 Google Chrome 的 'normal mode' 中不起作用,但它在隐身模式和其他 browsers/devices.
中运行良好
我发现了一个关于 clearing this cache on superuser.com and this answer was helpful 的问题,用于在 Google Chrome 中清除缓存中的重定向而不清除整个缓存。
撰写本文时:
打开开发者工具面板(选项命令i 在 Mac 或 ctrlshifti在 Windows)
单击并按住重新加载图标
将打开一个菜单
从此菜单中选择第三个选项(“清空缓存并重新加载”)
我无法通过反向代理在同一台服务器上配置 2 个子域。
情况:3 台服务器 Raspbian Stretch 和 Apache 2.4:
- 服务器 #1 服务
somedomain.com
并为otherdomain.com
、sub1.otherdomain.com
和sub2.otherdomain.com
做反向代理
- 服务器 #2 服务
otherdomain.com
- 服务器 #3 服务于
sub1.otherdomain.com
和sub2.otherdomain.com
somedomain.com
、otherdomain.com
和 sub1.otherdomain.com
工作正常,但我在使用 sub2.otherdomain.com
时遇到问题:它导致 somedomain.com
.
这就是我在服务器 #1 的 etc/apache2/sites-available/000-default.conf
中配置反向代理的方式:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName sub1.otherdomain.com
ProxyPass / http://192.168.1.111/
ProxyPassReverse / http://192.168.1.111/
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ServerName sub2.otherdomain.com
ProxyPass / http://192.168.1.111/
ProxyPassReverse / http://192.168.1.111/
</VirtualHost>
这就是我在服务器 #3 上配置 etc/apache2/sites-available/000-default.conf
的方式:
<VirtualHost *:80>
ServerName sub1.otherdomain.com
DocumentRoot /home/username/website1/public_html
RemoteIPHeader X-Forwarded-For
<Directory /home/username/website1/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName sub2.otherdomain.com
DocumentRoot /home/username/website2/public_html
RemoteIPHeader X-Forwarded-For
<Directory /home/username/website2/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
我想通了:这是 Google Chrome 的缓存。当我还在玩 Apache 配置文件时,它以某种方式缓存了重定向。
它在 Google Chrome 的 'normal mode' 中不起作用,但它在隐身模式和其他 browsers/devices.
中运行良好我发现了一个关于 clearing this cache on superuser.com and this answer was helpful 的问题,用于在 Google Chrome 中清除缓存中的重定向而不清除整个缓存。
撰写本文时:
打开开发者工具面板(选项命令i 在 Mac 或 ctrlshifti在 Windows)
单击并按住重新加载图标
将打开一个菜单
从此菜单中选择第三个选项(“清空缓存并重新加载”)