Setting up a subdomain with Apache on Linux

后端 未结 4 774
时光取名叫无心
时光取名叫无心 2020-12-25 13:18

I can\'t believe that I haven\'t done this before, but I would like a definitive answer so I\'m all set going forward.

I have an apache config file at /etc/apa

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-25 13:58

    You are telling Apache what IP and port you want to answer it on inside of the tag so here * means any IP, but accept requests for this site on port 80. Next you need to tell Apache where the document root is. ~/ means your default home directory, so if your DocumentRoot just happens to be the default home variable then it would work with your existing notation (depending on which user you're running the server as). Then you would declare the server name.

    Each domain name you're create a host for needs its own Virtual Host Directive unless you're using aliases.

    
        DocumentRoot /home/sam/public_html
        ServerName myproject.localhost
    
        # Other directives here
    
    
    
    
        DocumentRoot /home/sam/public_html/myproject
        ServerName myotherproject.localhost
    
        # Other directives here
    
    
    

    About Hosts In addition to this, any special name that you create for a host needs to go into a hosts file or in the DNS server as well. This way any web browser that is looking for your server can find it without having to type in the IP. Since you'll likely have multiple hosts on the same IP with your setup if you were to try and access the server with the IP only, you would only get the first host to respond on the IP (usually the top in the vhosts list).

提交回复
热议问题