Jump to content

Hosting multiple websites off of one server

Go to solution Solved by mariushm,

use virtualhosts

 

edit httpd-vhosts.conf and do something like this

 

<VirtualHost *:80>
    ServerAdmin webmaster@example.org
    DocumentRoot c:/www/!root
    ServerName default.example.org
    ErrorLog c:/logs/apache/default-error.log
    CustomLog c:/logs/apache/default-access.log common

</VirtualHost>

<VirtualHost *:80>
    RewriteEngine On
    ServerAdmin contact@example.org
    DocumentRoot c:/www/example.org
    ServerName example.org
    ServerAlias www.example.org
    Alias /pages c:/www/example.org/wiki/index.php
    ErrorLog c:/logs/apache/example.org-error.log
    CustomLog c:/logs/apache/example.org-access.log common

    <Directory "c:/www/example.org">
	AllowOverride All
	Order allow,deny
	Allow from all
    Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@example.org
    DocumentRoot c:/www/subdomain.example.org
    ServerName subdomain.example.org
    ErrorLog d:/logs/apache/subdomain.example.org-error.log
    CustomLog d:/logs/apache/subdomain.example.org-access.log common
    
    <Directory "c:/www/subdomain.example.org">
    Order allow,deny
    Allow from all
    Require all granted
    </Directory>
</VirtualHost>

 

First virtualhost is the default one - think of it like a catch all / default error page - it's telling the web server what should serve if user enters the IP address in a browser, like http://1.2.3.4 or answers requests from ancient browsers which aren't able to tell the server what domain they want content from.

 

The second virtualhost is for a default example.org (with or without www. in front, you can make separate vhosts for them if you want to) and has some additional rules that are common for mediawiki installations ( converts www.example.org/wiki/index.php?title=Something to www.example.org/pages/Something )

 

The third Virtualhost is for a subdomain of example.org domain

 

Of course, you'll have to edit the paths to be Linux specific like /var/vhost1 , /var/vhost2 or whatever.

 

later edit: 

 

And of course, in order for this conf/extra/httpd-vhosts.conf file to be parsed by apache when it starts, you must load it from the main httpd.conf file so make sure the lines don't have a # in front  (# comments out a line)

 

somewhere near the top of the httpd.conf file

 

LoadModule vhost_alias_module modules/mod_vhost_alias.so

 

further down :

 

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

use virtualhosts

 

edit httpd-vhosts.conf and do something like this

 

<VirtualHost *:80>
    ServerAdmin webmaster@example.org
    DocumentRoot c:/www/!root
    ServerName default.example.org
    ErrorLog c:/logs/apache/default-error.log
    CustomLog c:/logs/apache/default-access.log common

</VirtualHost>

<VirtualHost *:80>
    RewriteEngine On
    ServerAdmin contact@example.org
    DocumentRoot c:/www/example.org
    ServerName example.org
    ServerAlias www.example.org
    Alias /pages c:/www/example.org/wiki/index.php
    ErrorLog c:/logs/apache/example.org-error.log
    CustomLog c:/logs/apache/example.org-access.log common

    <Directory "c:/www/example.org">
	AllowOverride All
	Order allow,deny
	Allow from all
    Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@example.org
    DocumentRoot c:/www/subdomain.example.org
    ServerName subdomain.example.org
    ErrorLog d:/logs/apache/subdomain.example.org-error.log
    CustomLog d:/logs/apache/subdomain.example.org-access.log common
    
    <Directory "c:/www/subdomain.example.org">
    Order allow,deny
    Allow from all
    Require all granted
    </Directory>
</VirtualHost>

 

First virtualhost is the default one - think of it like a catch all / default error page - it's telling the web server what should serve if user enters the IP address in a browser, like http://1.2.3.4 or answers requests from ancient browsers which aren't able to tell the server what domain they want content from.

 

The second virtualhost is for a default example.org (with or without www. in front, you can make separate vhosts for them if you want to) and has some additional rules that are common for mediawiki installations ( converts www.example.org/wiki/index.php?title=Something to www.example.org/pages/Something )

 

The third Virtualhost is for a subdomain of example.org domain

 

Of course, you'll have to edit the paths to be Linux specific like /var/vhost1 , /var/vhost2 or whatever.

 

later edit: 

 

And of course, in order for this conf/extra/httpd-vhosts.conf file to be parsed by apache when it starts, you must load it from the main httpd.conf file so make sure the lines don't have a # in front  (# comments out a line)

 

somewhere near the top of the httpd.conf file

 

LoadModule vhost_alias_module modules/mod_vhost_alias.so

 

further down :

 

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Edited by mariushm
Link to post
Share on other sites

1 minute ago, TheComputerdude said:

@mariushm Just to double check will this work for 2 completely separate domains? Ex. example.com and coolExample.com.

I'm not mariushm, but assuming you follow the example they provided, yes.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×