VirtualHost always returns default host with Apache on Ubuntu 14.04

前端 未结 12 593
夕颜
夕颜 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:37

    If you have already tried the following:
    1. Checked permissions of the document root and parent folder.
    2. a2dissite 000-default etc.
    3. Restarted apache with sudo service apache2 reload
    And it is still not working then do the following:

    1. Enable debug logging:
    vi /etc/apache2/apache2.conf
    LogLevel debug

    2. Restart apache2 and monitor the logs
    sudo service apache2 restart
    tail -f /var/log/apache2/*.log

    3. Notice if the IP of the server is showing in the logs as expected:

    ==> /var/log/apache2/other_vhosts_access.log <== ip-xxx-xx-xx-xx.eu-west-2.compute.internal:80 xx.78.xx.2xx - - [13/Sep/2017:18:40:44 +0100] "GET / HTTP/1.1" 200 3509 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"

    You'll notice that instead of xxx.xx.xx.xx:80 like a typical IP address
    I've got some FQDN like "ip-xxx-xx-xx-xx.eu-west-2.compute.internal:80"
    I'm using AWS Elastic IP's to make a fixed IP for my Amazon EC2 web server.

    4. Check the head of your virtual-hosts .conf file

    
    # Added from nessus to make more secure
    RewriteEngine on
    RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
    RewriteRule .* - [F]
    ServerName mydomain.com
    ...
    

    OK so what we see here is we're telling Apache to serve this vhost for requests from 127.0.0.1 or 11.22.33.44 on port 80. But the server never sees these IPs as it get's that weird FQDN and so it never matches! Eureka!

    SOLUTION:
    Add *:80 to the VirtualHost tag so it looks like this:

    
    


    AND restart apache. I hope this helps. There may be other reasons but if this is the cause of your problem then it's time to sit back, have a cuppa tea and relax! If not then I hope you find the solution.

    PS. Remember to put your logs back to warn rather than debug!

提交回复
热议问题