Apache default VirtualHost

前端 未结 9 1626
忘掉有多难
忘掉有多难 2020-12-05 17:53

how can I set a default VirtualHost in apache? Preferably, I want the default host not to be the same as the ip address host. Now I have something like this:



        
相关标签:
9条回答
  • 2020-12-05 18:15

    If you are using Debian style virtual host configuration (sites-available/sites-enabled), one way to set a Default VirtualHost is to include the specific configuration file first in httpd.conf or apache.conf (or what ever is your main configuration file).

    # To set default VirtualHost, include it before anything else.
    IncludeOptional sites-enabled/my.site.com.conf
    
    # Load config files in the "/etc/httpd/conf.d" directory, if any.
    IncludeOptional conf.d/*.conf
    
    # Load virtual host config files from "/etc/httpd/sites-enabled/".
    IncludeOptional sites-enabled/*.conf
    
    0 讨论(0)
  • 2020-12-05 18:17

    The solution is:

    NameVirtualHost *:80
    Listen 80
    
    (...)
    
    <VirtualHost *:80>
            ServerName host1
            DocumentRoot /someDir
    </VirtualHost>
    
    <VirtualHost *:80>
            ServerName host2
            DocumentRoot /someOtherDir
    </VirtualHost>
    
    <VirtualHost *:80>
            ServerName aaaa.com
            DocumentRoot /defaultDir
    </VirtualHost>
    

    In my case, to work, I created a VirtualHost (n.e. VirtualHost per CNAME) called aaaa.com since I have different files for different VirtualHost and knowing that apache2 (n.a. Apache HTTP Server) reads them in alphabetical order.

    0 讨论(0)
  • 2020-12-05 18:20

    NameVirtualHost option would be a good option.

    0 讨论(0)
提交回复
热议问题