在 Apache 服务器中设置子域 ubuntu 16.04 lts
Setup subdomain in Apache server ubuntu 16.04 lts
如何在 ubuntu 服务器上的 Apache 中设置子域。
我的 apache.conf 文件:
<VirtualHost *:80>
ServerName www.hello.com
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:81>
ServerName bye.hello.com
DocumentRoot /var/www/html/other
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
现在我的访问是通过 IP:10.20.20.34:80 (www.hello.com) 和 10.20.20.34:81 (bye.hello.com)。 80 端口很好用,但我无法为 81 端口设置子域。
我们不需要 public 访问权限,一切都在 Intranet 上。我们修改了路由器中的 DNS 记录。
重要:我必须保留两个访问权限:10.20.20.34:81 和 bye.hello.com
以下是所发生情况的摘要:
- 10.20.20.34:80 - 好的。
- 10.20.20.34:81 - 好的。
- www.hello.com - 好的。
- bye.hello.com - 失败,告诉我 www.hello.com
您需要在 /etc/apache2/ports.conf
中添加 listen directive。在该文件中,您将看到:
Listen 80
在下面添加第二行:
Listen 80
Listen 81
然后重启Apache:
apache2ctl restart
否则,我没有发现您的虚拟主机设置有任何问题。
更新
Apache 不会通过 DNS 为您做这件事。您可以阅读 this 了解更多信息。最好的办法是将第二个虚拟主机指令更改为:
<VirtualHost *:80>
ServerName bye.hello.com
它应该可以正常工作。使用两个端口没有任何优势。如果您有架构限制,那么上面的 link 有一些高级解决方案。
如何在 ubuntu 服务器上的 Apache 中设置子域。
我的 apache.conf 文件:
<VirtualHost *:80>
ServerName www.hello.com
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:81>
ServerName bye.hello.com
DocumentRoot /var/www/html/other
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
现在我的访问是通过 IP:10.20.20.34:80 (www.hello.com) 和 10.20.20.34:81 (bye.hello.com)。 80 端口很好用,但我无法为 81 端口设置子域。
我们不需要 public 访问权限,一切都在 Intranet 上。我们修改了路由器中的 DNS 记录。
重要:我必须保留两个访问权限:10.20.20.34:81 和 bye.hello.com
以下是所发生情况的摘要:
- 10.20.20.34:80 - 好的。
- 10.20.20.34:81 - 好的。
- www.hello.com - 好的。
- bye.hello.com - 失败,告诉我 www.hello.com
您需要在 /etc/apache2/ports.conf
中添加 listen directive。在该文件中,您将看到:
Listen 80
在下面添加第二行:
Listen 80
Listen 81
然后重启Apache:
apache2ctl restart
否则,我没有发现您的虚拟主机设置有任何问题。
更新
Apache 不会通过 DNS 为您做这件事。您可以阅读 this 了解更多信息。最好的办法是将第二个虚拟主机指令更改为:
<VirtualHost *:80>
ServerName bye.hello.com
它应该可以正常工作。使用两个端口没有任何优势。如果您有架构限制,那么上面的 link 有一些高级解决方案。