How to configure subdomains for Apache2 on Ubuntu?

狂风中的少年 提交于 2019-12-20 08:50:16

问题


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>

回答1:


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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6836725/how-to-configure-subdomains-for-apache2-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!