Problem:
Spent hours going in circles following every guide I can find on the net.
I want to have two sites running on a single apache instance, something like this – 192.168.2.8/site1 and 192.168.2.8/site2
I’ve been going round in circles, but at the moment I have two conf files in ‘sites-available (symlinked to sites-enabled)’ that look like this-
<VirtualHost *:2000>
ServerAdmin webmaster@site1.com
ServerName site1
ServerAlias site1
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /home/user/site1/
# CGI Directory
ScriptAlias /cgi-bin/ /home/user/site1/cgi-bin/
Options +ExecCGI
# Logfiles
ErrorLog /home/user/site1/logs/error.log
CustomLog /home/user/site1/logs/access.log combined
</VirtualHost>
and
<VirtualHost *:3000>
ServerAdmin webmaster@site2.com
ServerName site2
ServerAlias site2
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /home/user/site2/
# CGI Directory
ScriptAlias /cgi-bin/ /home/user/site2/cgi-bin/
Options +ExecCGI
# Logfiles
ErrorLog /home/user/site2/logs/error.log
CustomLog /home/user/site2/logs/access.log combined
</VirtualHost>
http.conf looks like this-
NameVirtualHost *:2000
NameVirtualHost *:3000
At the moment I’m getting this error-
[error] VirtualHost *:80 — mixing * ports and non-* ports with a NameVirtualHostaddress is not supported, proceeding with undefined results
Ports.conf looks like this – (although no guides have mentioned any need to edit this)
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
Can anyone give some simple instructions to get this running? Every guide I’ve found says to do it a different way, and each one leads to different errors. I’m obviously doing something wrong but have found no clear explanation of what that might be.
Just want one site accessible on port 2000 and the other accessible on port 3000 (or whatever, just picked those ports to test with).
Solution:
Your question is mixing a few different concepts. You started out saying you wanted to run sites on the same server using the same domain, but in different folders. That doesn’t require any special setup. Once you get the single domain running, you just create folders under that docroot.
Based on the rest of your question, what you really want to do is run various sites on the same server with their own domain names.
The best documentation you’ll find on the topic is the virtual host documentation in the apache manual.
There are two types of virtual hosts: name-based and IP-based. Name-based allows you to use a single IP address, while IP-based requires a different IP for each site. Based on your description above, you want to use name-based virtual hosts.
The initial error you were getting was due to the fact that you were using different ports than the NameVirtualHost line. If you really want to have sites served from ports other than 80, you’ll need to have a NameVirtualHost entry for each port.
Assuming you’re starting from scratch, this is much simpler than it may seem.
The first thing you need to do is tell apache that you’re going to use name-based virtual hosts.
NameVirtualHost *:80
Now that apache knows what you want to do, you can setup your vhost definitions:
<VirtualHost *:80>
DocumentRoot "/home/user/site1/"
ServerName site1
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/home/user/site2/"
ServerName site2
</VirtualHost>
Note that you can run as many sites as you want on the same port. The ServerName being different is enough to tell Apache which vhost to use. Also, the ServerName directive is always the domain/hostname and should never include a path.