VirtualHost always returns default host with Apache on Ubuntu 14.04

前端 未结 12 598
夕颜
夕颜 2021-01-30 07:16

I try to setup a virtual host besides the default localhost. Whenever I try to call my virtual host http://test I get the default Apache2 Index file t

12条回答
  •  不思量自难忘°
    2021-01-30 07:48

    I have seen this happen when using a fully qualified domain name (FQDN) in the /etc/hosts file that is the same as a site I was trying to connect to. To solve this problem I had to rename the FQDN to something other than one of my VirtualHost ServerName values.

    So in other words, if my /etc/hostname was:

    apple
    

    And in my /etc/hosts, I had:

    192.168.54.34 apple.example.com apple
    

    And in my /etc/apache2/sites-enabled/apple.example.com.conf I had:

    
        ServerAdmin blah@apple.example.com
        ServerName apple.example.com
        DocumentRoot /var/www/apple.example.com
        DirectoryIndex index.html index.php
    
    

    apple.example.com would be accepted by the 000-default.conf because it is also listed in the /etc/hosts file. To solve this I just changed the FQDN of my server as follows in the /etc/hostname file:

    server1
    

    and /etc/hosts file:

    192.168.54.34 server1.example.com server1
    

提交回复
热议问题