如何在 Ubuntu 上为 Apache2 配置子域?
我按照这些为 apache 配置子域的说明。我可以使用 http://localhost/test
访问子域,但无法通过 http://test.localhost
访问它。我怎样才能实现后者?
# /etc/apache2/sites-available/test.localhost
<VirtualHost *:80>
# Server name
ServerName test.localhost
# Document root
DocumentRoot /var/www/test/
# Custom log file locations
ErrorLog /var/www/test/logs/error.log
CustomLog /var/www/test/logs/access.log combined
</VirtualHost>
I followed these instructions to configure subdomains for apache. I can access the subdomain using http://localhost/test
though I cannot access it via http://test.localhost
. How can I realize the latter?
# /etc/apache2/sites-available/test.localhost
<VirtualHost *:80>
# Server name
ServerName test.localhost
# Document root
DocumentRoot /var/www/test/
# Custom log file locations
ErrorLog /var/www/test/logs/error.log
CustomLog /var/www/test/logs/access.log combined
</VirtualHost>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于 Mark B 已经正确回答,问题是
/etc/hosts
中的配置错误。正确的配置是:As Mark B already answered correctly the problem was a misconfiguration in
/etc/hosts
. The correct configuration is:您链接到的博客文章(来自我的博客)指示设置一个 IP 为 127.0.0.2 的新 VirtualHost 元素,以便您可以轻松创建多个子域。
您使用 127.0.0.1 进行设置将非常适合一个子域,但如果您计划添加更多子域,我建议按照帖子中所述设置新的 VirtualHost 元素。
The blog post you linked to (from my blog) instructs to set up a new VirtualHost element with an ip of 127.0.0.2 so you can create multiple subdomains easily.
You're setup using 127.0.0.1 will work great for one subdomain, but if you plan on adding more, I'd suggest setting up the new VirtualHost elements as described in the post.
使用 apache tomcat 7 和 ubuntu 服务器时配置子域非常简单。
http://javatute.com/javatute /faces/post/tomcat/2014/configuring-subdomain-in-server.xml.xhtml
实际上子域需要时间来配置,因为我们使用 cPanel 添加它至少需要 2-3 天,并且然后配置server.xml并重新启动tomcat,我们就可以按预期运行它了。
Configuring subdomain is very easy when working with apache tomcat 7 and ubuntu server.
http://javatute.com/javatute/faces/post/tomcat/2014/configuring-subdomain-in-server.xml.xhtml
Actually subdomain takes time to configure as we add it using cPanel at least 2-3 days and then configuring server.xml and restarting tomcat we can run it as expected.