2

I’m trying to set up an Apache2 server, but I can’t get it to load my virtual hosts. Or to be more precise, it works fine as long as I write them in 000-default.conf, but whenever I try to use a separate file it seem to completely ignore it.

Why is this not working? And how do I make it work?

2
  • 2
    Check you httpd.conf file, it should contain a line like Include conf/*.conf. Check whether it is a wildcard or a fixed file (like 000-default.conf). Also, check that your new conf files match the wildcard patern and are stored on the same folder as the 000-default.conf. Finally, there are apache distributions where they have a available and a active conf files, so in some cases a soft link is needed in order for it to work.
    – NuTTyX
    Mar 22, 2015 at 17:27
  • NuTTyX was right though
    – Zlug
    Mar 22, 2015 at 18:04

2 Answers 2

5

Typically if one wants to setup separate virtual host configurations, you would place them in this directory:

/etc/apache2/sites-available/

So if you have a virtual host named www.example.com the config filename can be named www.example.com.conf like this:

/etc/apache2/sites-available/www.example.com.conf

You would then open that file in a text editor like this; I’m using nano as an example but feel free to use whatever text editor you prefer:

sudo nano /etc/apache2/sites-available/www.example.com.conf

And then place content similar to this into www.example.com.conf:

<VirtualHost *:80>
  ServerAdmin [email protected]
  ServerName example.com
  ServerAlias www.example.com
  DocumentRoot /var/www/example.com/
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Close and save that file and then use a2ensite like this to have the system set a symbolic link from sites-available to sites-enabled like this:

sudo a2ensite www.example.com.conf

Or—if you wanted to—you could manually use ln -s to set a symbolic link like this:

ln -s /etc/apache2/sites-available/www.example.com.conf /etc/apache2/sites-enabled/www.example.com.conf

When that’s done just reload Apache like this:

sudo service apache2 reload

And if for some reason reload doesn’t work, just force a restart like this:

sudo service apache2 restart

The benefit of using reload before restart is that if there is a typo in a config file, Apache will report an error but not load the config files. Meaning your Apache web server will still be up and running based on the last stable configuration file it loaded.

The risk is that if you force a restart and there is a typo in a configuration file, Apache will be dead because restart forces a complete service stop followed by a start. And if that start chokes, the server is dead until the config typo/issue is cleared up.

0
2

Check you httpd.conf file, it should contain a line like Include conf/*.conf. Check whether it is a wildcard or a fixed file (like 000-default.conf).

Also, check that your new conf files match the wildcard patern and are stored on the same folder as the 000-default.conf.

Finally, there are apache distributions where they have a available and a active conf files, so in some cases a soft link is needed in order for it to work

0

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