在另一台服务器中使用 DocumentRoot 创建 VirtualHost

时间:2021-01-15 14:32:59

标签: apache centos7 virtualhost firewall hosts

我有两个带有 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 /var/www/html 创建了 VirtualHost 并开始工作。

然后

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

1 个答案:

答案 0 :(得分:0)

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

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

相关问题