ServerName not working in Apache2 and Ubuntu

5,826

Solution 1

I had almost the exact problem you're having. It stemmed from the default ServerName (in /etc/apache2/conf.d/servername.conf) and the ServerName in my VirtualHost definition file (/etc/apache2/sites-available/site.com) being equal.

Solution 2

for each subdomain, create a file just like the one you have listed above, except just give the subdomain as the servername. remove the *.mydomain.com as a server alias. enable the config files in apache, and restart apache.

Share:
5,826
CreativeNotice
Author by

CreativeNotice

Updated on September 17, 2022

Comments

  • CreativeNotice
    CreativeNotice almost 2 years

    Setting up a dev LAMP server and I wish to allow dynamic subdomains, aka ted.servername.com, bob.servername.com.

    Here's my sites-active file

    <VirtualHost *:80>
        # Admin Email, Server Name, Aliases
        ServerAdmin     [email protected]
        ServerName      happyslice.net
        ServerAlias     *.happyslice.net
    
        # Index file and Document Root
        DirectoryIndex  index.html
        DocumentRoot    /home/sysadmin/public_html/happyslice.net/public
    
        # Custom Log file locations
        LogLevel        warn
        ErrorLog        /home/sysadmin/public_html/happyslice.net/log/error.log
        CustomLog       /home/sysadmin/public_html/happyslice.net/log/access.log combined
    

    And here's the output from sudo apache2ctl -S

    VirtualHost configuration:
    wildcard NameVirtualHosts and _default_ servers:
    *:80                   is a NameVirtualHost
             default server happyslice.net (/etc/apache2/sites-enabled/000-default:1)
             port 80 namevhost happyslice.net (/etc/apache2/sites-enabled/000-default:1)
             port 80 namevhost happyslice.net (/etc/apache2/sites-enabled/happyslice.net:5)
    Syntax OK
    

    The server hostname is srv.happyslice.net.

    As you can see from apache2ctl when I use happyslice.net I get the default virtual host, when I use a subdomain, I get the happyslice.net host. So the later is working how I want, but the main url does not.

    I've tried all kinds of variations here, but it appears that ServerName just isn't being tied to the correct location.

    Thoughts? I'm stumped. FYI, I'm running Apache2.1 and Ubuntu 10.04 LTS

    • CreativeNotice
      CreativeNotice about 14 years
      NOTE, I just replaced *:80 with the IP and both the servername and serveralias now work. But am I going to run into the same thing if I setup a second site listing on the same IP?
    • risyasin
      risyasin about 14 years
      yes... with different servername & serveralias.
    • Anarko_Bizounours
      Anarko_Bizounours about 13 years
      have you uncomment the line with NameVirtualHost *:80?