首页 > 解决方案 > 在另一台服务器中使用 DocumentRoot 创建 VirtualHost

问题描述

我有两台使用 centos 7 的服务器虚拟机。使用 IP 公用103.x.x.78和域one.example.go.id 此 IP 本地是192.168.10.200(服务器 A)。

我创建了另一个具有 IP 本地192.168.10.103(服务器 B)的 VM。计划指向我的另一个域two.example.go.id

这是我的配置:

one.example.go.id pointing to 103.x.x.78

我已经使用 DocumentRoot 创建了 VirtualHost/var/www/html并开始工作。

然后

two.example.go.id pointing to 103.x.x.78

我尝试打开这个域工作。打开网页。

在服务器 A 上创建 /etc/hosts:

192.168.10.103 two.example.go.id

并在服务器 B 创建 VirtualHost

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName www.two.example.go.id
    ServerAlias two.example.go.id
    DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:443>
    ServerName www.two.example.go.id
    ServerAlias two.example.go.id
    DocumentRoot /var/www/html
</VirtualHost>

我可以在服务器 A 中访问 IP 192.168.10.103 或 two.example.go.id,它可以完美加载。但是当我在其他设备(互联网)中使用 two.example.go.id 访问时,它不起作用。无法访问此站点。

我错过了一步吗?

*这是我英语不好的第一个问题。CMIIW

标签: apachecentos7virtualhostfirewallhosts

解决方案


/etc/hosts您是否还向服务器 B添加了一个?因为/etc/hosts仅适用于您添加它的设备。例如,如果您/etc/hosts在服务器 A 中添加指令,则它仅适用于服务器 A。您也必须为服务器 B 添加相同的指令。

或者,如果您因此不想使用 /etc/hosts,那么您可以在本地网络中设置自己的 DNS 服务器。


推荐阅读