Question

I would like to host multiple websites with different domain names on one apache server.

Lets say I have the following websites:

www.site1.com
www.site2.com
www.site3.com

I have got an ip address (such as: 89.x.x.x) which is linked to my /var/www directory where I can access from outside, and the structure would be:

/var/www/index.html // for www.site1.com
/var/www/site2/index.html // for www.site2.com
/var/www/site3/index.html // for www.site3.com

In my domain name configurations I have pointed the A-Record for each website to the same ip address. (I would like to avoid forwarding e.g. http://89.x.x.x/site2, because of the iframe problem that kills the website's responsiveness!)

I have followed some examples of virtualhost and htaccess configurations, but none of them worked!

As I am not very experienced in server configurations, I would appreciate for any suggestions to resolve this issue!

Thanks heaps!

Was it helpful?

Solution

You cannot setup name-based virtual hosts in an .htaccess file (too late to do anything about source directories there), so you should add the settings somewhere in the main apache configuration file(s).

This following example is copied directly from https://httpd.apache.org/docs/2.2/vhosts/name-based.html:

NameVirtualHost *:80

<VirtualHost *:80> 
    ServerName www.domain.tld 
    ServerAlias domain.tld *.domain.tld 
    DocumentRoot /www/domain 
</VirtualHost>

<VirtualHost *:80>
    ServerName www.otherdomain.tld 
    DocumentRoot /www/otherdomain 
</VirtualHost>

OTHER TIPS

Append to krisku's answer, we should add addition lines in apache2 config file at somewhere like httpd/conf/httpd.conf:

<Directory "/www/domain">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride all

#
# Controls who can get stuff from this server.
#
Require all granted

<Directory "/www/otherdomain">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride all

#
# Controls who can get stuff from this server.
#
Require all granted

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top