Tag Archives: vhost

How to Solve: a2ensite “Error, Site does not exist!” Tips, Tricks and Tutorials 04 JUL 2015

To enable a virtual vhost website on your Ubuntu Server running Apache, you need to first create a vhost configuration file (just copy 000-defaul.conf as a quick way to start), and then run the a2ensite command to enable it so that Apache knows about it.

However, nowadays attempting to run a2ensite might just pop up with this particular error message:

ERROR: Site [YOURSITE] does not exist!

This is not a problem that used to occur, but in newer versions of Ubuntu it does – the reason for this is simple – your configuration file is probably missing a .conf extension, and the a2ensite perl script now only works with filenames ending in .conf!

So to fix, simply add the .conf your site vhost configuration file and run a2ensite again.

sudo a2ensite YOURSITE.conf

This time around you should be all good, and can jump straight into the next step of reloading Apache’s configuration with:

sudo service apache2 reload

Nifty.

Apache attack helicopter

Apache: Simple way to Force a Domain Redirect Tips, Tricks and Tutorials 22 JUL 2014

I was decommissioning an old server the other day, and in the process of moving the system to a new server I learned that the old domain was in fact one that we didn’t directly control. In other words, time to enforce a new domain on our clients! Of course, getting anyone to change URLs or domains on their personal machines is never an easy thing, so of course there has to be a small period of playing nice, in which you need to seamlessly redirect from one domain to the other. In other words, if an old URL is oldserver.com/about/ then I want anyone hitting that URL to be redirected to the new URL at newserver.com/about/.

To do this on your LAMP server is pretty easy thanks to the powerful mod_rewrite Apache module. Simply open up your relevant vhost declaration file in /etc/apache2/sites-available and add the following to the bottom of it (obviously using your own domains in place of the sample ones):

<IfModule mod_rewrite.c>
rewriteEngine on
rewriteCond %{HTTP_HOST} ^oldserver.com$
rewriteRule ^(.*) http://newserver.com$1 [L,R=301]
</IfModule>

Reload your apache configuration with

sudo service apache2 reload

and try to hit “oldserver.com/about” now.

Works well, doesn’t it? (And it wasn’t even difficult to do!)

apache-logo-banner

[UPDATE: Lately I’ve switch to placing this in the virtual host file:]

<VirtualHost *:80>
Options +FollowSymLinks
RewriteEngine on
RewriteRule .? http://newserver.com%{REQUEST_URI} [L,R=301]
....

XAMPP on Windows 7: Solving “client denied by server configuration” VirtualHost Error CodeUnit 05 FEB 2013

I don’t normally use Windows as my development environment, but after being handed a Windows 7 Fujitsu laptop at work, I set about getting my development environment up and running as fast as possible. XAMPP appears to be a popular way of setting up an Apache, MySQL and PHP stack, so I duly installed and then whipped open the C:\xampp\apache\config\extra\httpd-vhosts.conf file in order to add all my virtual hosts.

Nothing too complicated in there, pretty much only defining a DocumentRoot and ServerName directive, along with a simple Directory block containing an Order and an Allow directive. Next up with the C:\Windows\System32\drivers\etc\hosts file which was edited to allow for my subdomain and that should have been that. I fired up the XAMPP console, started both Apache and MySQL, and pleasingly http://localhost/ worked first time in my browser. Then I attempted to access my virtualhost – and nothing. Or rather a 403 denied access error message courtesy of my browser.

What followed was more than a hour of searching and tinkering with my setup, exploring folder security properties, directory name structures, config file alterations, all to no avail. Instead the “client denied by server configuration” error continued to taunt me at every turn.

I went to bed a frustrated man, and the next morning after an early rise and shine, I pulled out my chair and tackled the problem anew. And success!

The problem lies in the restrictive XAMPP httpd.conf file where it specified the “default” with a very restrictive set of features, the troublemaker here being a Directory block containing “Require all denied” (an authentication feature rolled out with Apache 2.4). What this means is that all incoming requests are denied. So back to our virtualhost specification, where we need to edit our Directory block and add a new rule to override the default setting.

Now we could go for “Require all granted”, but this is a little bit too open and not necessarily a practice that should be encouraged if you don’t need it. Instead, because this is for my local development environment, I’ll open up my vhost for the internal IP of 127.0.0.1, using the “Require ip xxx.xxx.xxx.xxx” directive.

So now my vhosts.conf entry looks like this:

<VirtualHost *:80>
DocumentRoot "C:\vhosts\surveythumb"
ServerName surveythumb
DirectoryIndex index.php
<Directory "C:\vhosts\surveythumb">
AllowOverride none
Require ip 127.0.0.1
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Solved!

Ubuntu: How to set up an Apache Virtual Host (vhost) CodeUnit 28 SEP 2011

To set up a virtual host (vhost) under Apache on your Ubuntu server is relatively simple. First you need to create a config file under the /etc/apache2/sites-available directory. A good practice is to name this file the same as the folder you want to use to hold this virtual host’s web pages.

For this example we want to serve up traffic coming in for www.mydomain.com, so we create a file called mydomain:

sudo nano /etc/apache2/sites-available/mydomain

The contents of which looks like this:

<VirtualHost *:80>
DocumentRoot /home/www/mydomain
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/www/mydomain>
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
ServerName mydomain.com
ServerAlias www.mydomain.com

ErrorLog /var/log/apache2/mydomain-error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/mydomain-access.log combined

ErrorDocument 404 /error_documents/404.php
ErrorDocument 403 /error_documents/403.php

</VirtualHost>

With the file saved, next we enable the site by running:

sudo a2ensite mydomain

Finally, reload the Apache configuration with:

sudo /etc/init.d/apache2 reload

Done.

(And if you are in the process of looking for a hosting server, you may want to check out different web hosting companies first to help you compare and find the most appropriate hosting account for you.)