-1

I have a web server running on my home computer to serve up my personal website.

I recently switched from Ubuntu to Fedora. I enabled httpd and it showed the default page on http://localhost. I added an index.html to /var/www/html, and that showed up fine.

Next, I added a VirtualHost (in /etc/httpd/conf.d/example.conf for example.com and added it to my hosts file. My second site shows up fine at example.com, but it also shows up at localhost.

I haven't made any changes at all to the default httpd.conf, so DocumentRoot is still /var/www/html.

Here is the contents of my example.conf file:

<VirtualHost *:80>
    ServerAdmin webmaster@example.com

    ServerName example.com
    ServerAlias *.example.com

    # Indexes + Directory Root.
    # DirectoryIndex index.html
    DocumentRoot /home/user/example/

    # CGI Directory
    # ScriptAlias /cgi-bin/ /home/drj/wordpress/cgi-bin/
    # <Location /cgi-bin>
        # Options +ExecCGI
    # </Location>

    # Logfiles
    ErrorLog  logs/wordpress-error.log
    CustomLog logs/wordpress-access.log combined
</VirtualHost>

<Directory /home/drj/wordpress>
    AllowOverride All
    Require all granted
</Directory>

I copied this directly from my original config in Ubuntu, changing only the paths for the logs.

Dan Jones
  • 103
  • 1
  • 5
  • 1
    Possible duplicate of [How does ServerName and ServerAlias work?](http://serverfault.com/questions/520195/how-does-servername-and-serveralias-work) – Jenny D Jul 24 '16 at 18:36

1 Answers1

1

The first VirtualHost defined is also the default VirtualHost for any requests to domains that are not specifically listed as a separate VirtualHost. If your configuration does not include any other VirtualHost statements you need to create one like this.

<VirtualHost *:80>
ServerName apache.example.com
DocumentRoot /var/www/html
</VirtualHost>

The servername is not important, I just like to call it apache.mydomain.net

Important is that this is the FIRST one in the configuration. So if you are putting it as a separate .conf file in /etc/httpd/conf.d/ like your example.conf, make sure that its name is alphabetically in front of example.conf so that the include directive gets to it first! Or just put it in front of the VirtualHost directive of the existing example.conf.

Gerald
  • 51
  • 2
  • Thanks! That's it. I guess I just assumed that would already be set up by default, as it is in Debian-based distros. – Dan Jones Jul 24 '16 at 17:36