如何在 Ubuntu 上为 Apache2 配置子域?

发布于 2024-11-26 09:11:49 字数 573 浏览 4 评论 0原文

我按照这些为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

流云如水 2024-12-03 09:11:49

由于 Mark B 已经正确回答,问题是 /etc/hosts 中的配置错误。正确的配置是:

# /etc/hosts
127.0.0.1     test.localhost

As Mark B already answered correctly the problem was a misconfiguration in /etc/hosts. The correct configuration is:

# /etc/hosts
127.0.0.1     test.localhost
滥情稳全场 2024-12-03 09:11:49

您链接到的博客文章(来自我的博客)指示设置一个 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.

话少情深 2024-12-03 09:11:49

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文