【问题标题】:How to forward 80 port to 2 server based on donain如何根据域将80端口转发到2台服务器
【发布时间】:2018-04-18 00:48:26
【问题描述】:
我有 2 台 apache 服务器连接到路由器。从路由器设置中,我可以将 80 和 443 端口转发到单个机器/内部 IP。然后我可以从我的外部 IP 地址访问它。我的域有指向该 IP 地址的记录。所以,我可以使用我的域访问那台机器。
但我想将我的两个 apache 服务器用于两个不同的域。假设 domain1.com 将连接到 server1,domain2.com 将连接到 server2。
有什么办法吗?
【问题讨论】:
标签:
apache
multiple-domains
【解决方案1】:
如果您有一个包含两个网站和两个域的服务器,您可以简单地在您的 vhost 配置文件中创建两个 VirtualHost 块。两者可能看起来很相似,但您必须更改 DocumentRoot 和 ServerName 条目。
该文件将类似于以下内容:
<VirtualHost *:80>
DocumentRoot "/var/www/Website1"
ServerName Website1.com
<Directory "/var/www/Website1/public">
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/Website2"
ServerName Website2.com
<Directory "/var/www/Website2/public">
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
当然,您也可以在此文件中处理 https 连接。
此外,还有一些很好的方法可以使用所需根文件夹中的.htaccess 文件来处理连接重定向。