简体   繁体   English

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

[英]How to configure subdomains for Apache2 on Ubuntu?

I followed these instructions to configure subdomains for apache . 我按照这些说明为apache配置子域 I can access the subdomain using http://localhost/test though I cannot access it via http://test.localhost . 我可以使用http://localhost/test访问子域,但我无法通过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>

As Mark B already answered correctly the problem was a misconfiguration in /etc/hosts . 由于Mark B已经正确回答,问题是/etc/hosts的配置错误。 The correct configuration is: 正确的配置是:

# /etc/hosts
127.0.0.1     test.localhost

Configuring subdomain is very easy when working with apache tomcat 7 and ubuntu server. 使用apache tomcat 7和ubuntu服务器时,配置子域非常容易。

http://javatute.com/javatute/faces/post/tomcat/2014/configuring-subdomain-in-server.xml.xhtml 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. 实际上子域需要时间来配置,因为我们使用cPanel添加它至少2-3天然后配置server.xml并重新启动tomcat我们可以按预期运行它。

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. 您链接到的博客文章(来自我的博客)指示设置ip为127.0.0.2的新VirtualHost元素,以便您可以轻松创建多个子域。

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. 您使用127.0.0.1设置将适用于一个子域,但如果您计划添加更多,我建议设置新的VirtualHost元素,如帖子中所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM