1

I have installed apache2, there is a config file in /etc/apache2/sites-available and sites-enabled has a soft link to it. on the server, however, i still see /var/www/html/index.html. I have tried restarting apache with no luck. If I stop apache, nothing shows up on the box, so I'm certain it's not a multiple dameon issue or something like that. Can anyone think of any reason why apache is not seeing the enabled site?

In /etc/apache2/apache2.con, I have

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

But other than that, I don't see why apache would be hard wired to show the default index.

Thanks for any help, Kevin

UPDATE

here is the site config file:

 <VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/var/www/sites/example.com/current/public"
    ErrorLog "/var/log/apache2/example.com-error_log"
    CustomLog "/var/log/apache2/example.com-access_log" common
    <Directory "/var/www/sites/example.com/current/public">
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    RewriteEngine On
    # Remove the www
    RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
    RewriteRule ^(.*)$ http://example.com/ [R=301,L]
</VirtualHost>

UPDATE

As an experiment, I removed the closing ">" to the config file to make it not well-formed, restarted apache and got no errors. This tells me the sites-enabled configs are not even being parsed.

1
  • 1
    Can you post the site config?
    – Hyppy
    May 8, 2015 at 16:34

3 Answers 3

2

Only accessing the site as http://example.com will trigger the host you have configured. Going to http://www.example.com , the server's IP, or any other method will fall back to Apache default.

Edit: For clarification, you can do one of the following:

  • If you want this as your default/only host, then don't even bother with VirtualHost tags, and apply your configuration at the server level
  • Add a Server Alias line like ServerAlias example.com *.example.com
  • Add a new VirtualHost for www.example.com and define the redirect there
4
  • I removed the rewrite rules and commented out the RewriteEngine on line, same outcome. May 8, 2015 at 17:33
  • 1
    That's not what I'm saying
    – Hyppy
    May 8, 2015 at 17:35
  • are you saying because of the ServerName directive, apache will only route those requests to this directory? If so, what's the point of the <VirtualHost *:80> line? May 8, 2015 at 17:48
1

The Debian version of Apache 2.4 specifically loads *.conf in the apache2.conf:

IncludeOptional sites-enabled/*.conf

It turns out my config file didn't end in .conf so it was never being loaded. Renaming it from example.com to example.conf fixed the problem.

1

You're lacking a ServerAlias directive, thus the HTTP request isn't hitting your virtual host and instead going to the default.

What's going on is that in the HTTP header includes the site the browser was looking for (e.g. www.example.com), and unless it matches the ServerName or ServerAlias directive, Apache won't serve up the configured page.

You can use:

ServerName example.com
ServerAlias www.example.com

Or, to catch all requests for *.example.com (which may or may not be desired given on your third level domain usage):

ServerAlias *.example.com

The rewrite rules aren't helping here because this configuration isn't catching the HTTP requests, they're going to the default virtual host -- which doesn't have those rewrite rules. Hope this makes sense.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .