Apache default VirtualHost

前端 未结 9 1644
忘掉有多难
忘掉有多难 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 17:58

    Obligatory - none of the above worked for me. I inherited strange combination of ip based virtual hosts and * vhosts (not assigned/catch all ips) based virtual hosts in this Apache config messed by ISPConfig.

    I wanted Apache to serve not configured hosts with same page. What I had was - not configured hosts went to first vhost after 000-default.conf. No matter I had *:80 catch all defined as first vhost, instead of default Apache would load first defined site:

    
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
    
    

    Although it's not completely valid config, what finally worked was adding ip based virtualhost without ServerName/ServerAlias defined:

    
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
    
    
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
            SSLEngine On
            ...
    
    

    $ apachectl -S outputs ip based vhosts first, and * based vhosts later, and finally my default site is loaded before real site:

    AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/000-default.conf:50
    192.168.10.10:80        is a NameVirtualHost
             default server server.tld (/etc/apache2/sites-enabled/000-default.conf:34)
             port 80 namevhost server.tld (/etc/apache2/sites-enabled/000-default.conf:34)
             port 80 namevhost some-site.tld (/etc/apache2/sites-enabled/100-some-site.tld.vhost:7)
    
    ...
    
    46.23.86.103:443       is a NameVirtualHost
             default server server.tld (/etc/apache2/sites-enabled/000-default.conf:38)
             port 443 namevhost server.tld (/etc/apache2/sites-enabled/000-default.conf:38)
             port 443 namevhost some-site.tld (/etc/apache2/sites-enabled/100-some-site.tld.vhost:182)
    
    ...
    
    *:80                   is a NameVirtualHost
             default server server.tld (/etc/apache2/sites-enabled/000-default.conf:1)
             port 80 namevhost server.tld (/etc/apache2/sites-enabled/000-default.conf:1)
    

    Word of notice - in config like this, * vhosts won't work, so you need to apply ip's to all vhosts.

提交回复
热议问题