[web-applications] How to run multiple sites on one apache instance

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 [email protected]
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 [email protected]
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).

I’m running Ubuntu server 12.04…

=============

EDIT

Followed another 'guide'...

I've now set this up in sites-available:

<VirtualHost *:80>
    DocumentRoot "/home/user/site1/"
    ServerName 192.168.2.10/site1
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/home/user/site2/"
    ServerName 192.168.2.10/site2
</VirtualHost>

Have set this in apache2.conf:

ServerName site1
ServerName site2

Have added this to ports.conf:

Listen 192.168.2.10:80

==============

EDIT

It now works, I put this in a conf file in site-enabled:

<VirtualHost *:81>
    DocumentRoot "/home/user/site1/"
    ServerName site1
</VirtualHost>

<VirtualHost *:82>
    DocumentRoot "/home/user/site2/"
    ServerName site2
</VirtualHost>

I have this in ports.conf:

Listen *:80
Listen *:81
Listen *:82

I have this in apache2.conf:

ServerName site1
ServerName site2

I didn't find this in any guides I just got it working through an entire day of trial and error so I don't know if this is a good solution. But it's at least working how I want it to now.

This question is related to web-applications configuration apache2

The answer is


Yes with Virtual Host you can have as many parallel programs as you want:

Open

/etc/httpd/conf/httpd.conf

Listen 81
Listen 82
Listen 83

<VirtualHost *:81>
    ServerAdmin [email protected]
    DocumentRoot /var/www/site1/html
    ServerName site1.com
    ErrorLog logs/site1-error_log
    CustomLog logs/site1-access_log common
    ScriptAlias /cgi-bin/ "/var/www/site1/cgi-bin/"
</VirtualHost>

<VirtualHost *:82>
    ServerAdmin [email protected]
    DocumentRoot /var/www/site2/html
    ServerName site2.com
    ErrorLog logs/site2-error_log
    CustomLog logs/site2-access_log common
    ScriptAlias /cgi-bin/ "/var/www/site2/cgi-bin/"
</VirtualHost>

<VirtualHost *:83>
    ServerAdmin [email protected]
    DocumentRoot /var/www/site3/html
    ServerName site3.com
    ErrorLog logs/site3-error_log
    CustomLog logs/site3-access_log common
    ScriptAlias /cgi-bin/ "/var/www/site3/cgi-bin/"
</VirtualHost>

Restart apache

service httpd restart

You can now refer Site1 :

http://<ip-address>:81/ 
http://<ip-address>:81/cgi-bin/

Site2 :

http://<ip-address>:82/
http://<ip-address>:82/cgi-bin/

Site3 :

http://<ip-address>:83/ 
http://<ip-address>:83/cgi-bin/

If path is not hardcoded in any script then your websites should work seamlessly.


Examples related to web-applications

Spring - No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call How do I choose the URL for my Spring Boot webapp? Difference between MEAN.js and MEAN.io External VS2013 build error "error MSB4019: The imported project <path> was not found" How to unpackage and repackage a WAR file IntelliJ, can't start simple web application: Unable to ping server at localhost:1099 Using form input to access camera and immediately upload photos using web app Pass user defined environment variable to tomcat ASP.NET: HTTP Error 500.19 – Internal Server Error 0x8007000d Best practices when running Node.js with port 80 (Ubuntu / Linode)

Examples related to configuration

My eclipse won't open, i download the bundle pack it keeps saying error log Getting value from appsettings.json in .net core pgadmin4 : postgresql application server could not be contacted. ASP.NET Core configuration for .NET Core console application Turning off eslint rule for a specific file PHP Warning: Module already loaded in Unknown on line 0 How to read AppSettings values from a .json file in ASP.NET Core How to store Configuration file and read it using React Hadoop cluster setup - java.net.ConnectException: Connection refused Maven Jacoco Configuration - Exclude classes/packages from report not working

Examples related to apache2

Only variable references should be returned by reference - Codeigniter 413 Request Entity Too Large - File Upload Issue Site does not exist error for a2ensite How to convert .pem into .key? Apache: Restrict access to specific source IP inside virtual host CodeIgniter removing index.php from url Failed Apache2 start, no error log Apache2: 'AH01630: client denied by server configuration' what does it mean "(include_path='.:/usr/share/pear:/usr/share/php')"? How to check is Apache2 is stopped in Ubuntu?