correct setup of apache to handle multiple domains - apache

hello i have 2 domains domain1.com,domain2.com
both are in the same server under domain1.com
i want to set the VirtualHost to handle them both
like this:
<VirtualHost domain1.com:80>
DocumentRoot /var/www/html
ServerName domain1.com
<Directory /var/www/html>
AllowOverride AuthConfig
Order allow,deny
Allow from all
Options -Indexes
</Directory>
</VirtualHost>
<VirtualHost domain2.com:80>
DocumentRoot /var/www/domain2
ServerName domain2.com
<Directory /var/www/domain2>
AllowOverride AuthConfig
Order allow,deny
Allow from all
Options -Indexes
</Directory>
</VirtualHost>.
but for some reason the server send me only to the first one
i also tryed it like this
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName domain1.com
<Directory /var/www/html>
AllowOverride AuthConfig
Order allow,deny
Allow from all
Options -Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/domain2
ServerName domain2.com
<Directory /var/www/domain2>
AllowOverride AuthConfig
Order allow,deny
Allow from all
Options -Indexes
</Directory>
</VirtualHost>.
anyone have any idea how to fix this problem ?

I think you are missing the NameVirtualHost directive.
NameVirtualHost *:80
<VirtualHost *>
DocumentRoot /var/www/html
ServerName domain1.com
<Directory /var/www/html>
AllowOverride AuthConfig
Order allow,deny
Allow from all
Options -Indexes
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot /var/www/domain2
ServerName domain2.com
<Directory /var/www/domain2>
AllowOverride AuthConfig
Order allow,deny
Allow from all
Options -Indexes
</Directory>
</VirtualHost>
Without it your first VirtualHost will be used for all access when using name-based virtual hosting.

Related

VHost for Subdomain Website

I'm using a Linux Server for my website www.domain.com
I want to create the subdomain www.test.domain.com for a test environment.
I started configuring the vhost-file.
<Directory /var/www/domain/>
AllowOverride None
Order Deny, Allow
Deny from all
</Directory>
<VirtualHost *:80>
DocumentRoot /var/www/domain/
ServerName domain.com
ServerAlias domain.com
ServerAlias www.domain.com
ServerAdmin support#domain.com
ErrorLog /var/ww/domain/
<IfModule mod_ssl.c>
</IfModule>
<Directory /var/www/domain/
Options FollowSymLinks
AllowOverride All
Order allow, deny
Allow from all
</Directory>
How can I edit the Vhost file for the subdomain www.test.domain.com in directory ,,/var/www/test/"?
A Sub-Domain is actually a separate domain. You will need to create a new VHost for Sub-Domain.
<Directory /var/www/test/>
AllowOverride None
Order Deny, Allow
Deny from all
</Directory>
<VirtualHost *:80>
DocumentRoot /var/www/test/
ServerName test.domain.com
ServerAlias testdomain.com
ServerAlias www.test.domain.com
ServerAdmin support#test.domain.com
ErrorLog /var/ww/test/
<IfModule mod_ssl.c>
</IfModule>
<Directory /var/www/test/
Options FollowSymLinks
AllowOverride All
Order allow, deny
Allow from all
</Directory>
You can set all your parameters as you like, separately for Sub-Domain.

Apache2 how to working www.example.com

I need help. I am sorry wrong write. My LAMP server i created virtual host working http://example.com a NOT WORKING http://www.exaple.com
<VirtualHost *:80>
DocumentRoot "/var/www/example/1/public_html"
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#localhost
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
UseCanonicalName on
<Directory "/usr/lib/cgi-bin">
AllowOverride all
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
<Directory "/var/www/example/1/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
Considering that you have put a local mapping to example.com in /etc/hosts. Do you have same entry for www.example.com also?
example of the /etc/hosts entry:
127.0.0.1 example.com www.example.com
or
xxx.xxx.xxx.xxx example.com www.example.com
(xxx.xxx.xxx.xxx being your hosting server IP)

XAMPP Windows Apache vhosts not redirecting properly

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
<Directory "C:/xampp/htdocs/">
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/gl"
ServerName gl.dev
<Directory "C:/xampp/htdocs/gl">
Order allow,deny
allow from all
</Directory>
</VirtualHost>
The above is what I currently have in my vhosts file. When I hit localhost I want my root to open, but when I load gl.dev I want the individual site to open. Any ideas?
hosts file:
127.0.0.1 localhost
# ::1 localhost
127.0.0.1 gl.dev
I think in windows you have to use backslash when specifying document root. please try the following
<VirtualHost *:80>
ServerName localhost
ServerAlias *.localhost
DocumentRoot "C:\xampp\htdocs\"
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName gl.dev
ServerAlias *.gl.dev
DocumentRoot "C:\xampp\htdocs\gl"
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Restart WAMP server

Apache2 Dynamic vHost with multiple ServerAlias

I am trying to set up a dynamic vHost, but have run into some trouble. It will not allow me to set multiple ServerAlias.
<VirtualHost *:80>
ServerAlias *.com
ServerAdmin michael.ian.curry#gmail.com
VirtualDocumentRoot /var/www/%1/production/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel warn
</VirtualHost>
The above vHost only works for '.com' i need it to work for 'www..com' and '*.com'
I assumed that setting the ServerAlias to would fix it, but it is not working.
ServerAlias *.com www.*.com
If you have any insight, please respond
--MichaelCurry
==EDIT 1==
Example redcrusher.com and www.redcrusher.com
==EDIT 2==
The code below does not work either
ServerAlias www.*.com *.com
Figured it out!
'www.*.com' must execute before '*.com' This is because ServerAlias is setting a dynamic domain and must exist before a "smaller" alias exists.
Example: 'www.*.com', 'dev.*.com', 'asdf.*.com' THEN '*.com'
vHost File [production.conf]:
<VirtualHost *:80>
ServerAlias www.*.com
VirtualDocumentRoot /var/www/%2/production/html
ServerAdmin michael.ian.curry#gmail.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel warn
</VirtualHost>
<VirtualHost *:80>
ServerAlias *.com
VirtualDocumentRoot /var/www/%1/production/html
ServerAdmin michael.ian.curry#gmail.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel warn
</VirtualHost>
I hope this helps anyone else that is having this problem!
--MichaelCurry
you must use like this
ServerAlias www.domain.com domain.com
ServerAlias *.domain.com
if You want use That Way You Must Follow Order
ServerAlias www.*.com *.com
the problem is of
VirtualDocumentRoot /var/www/%1/production/html
you Use a Dynamic VirtualDocumentRoot that mean
for redcrusher.com VirtualDocumentRoot is
/var/www/redcrusher/production/html
and for www.redcrusher.com VirtualDocumentRoot is
/var/www/www.redcrusher/production/html
I think with split ServerAlias in Three part it solve
ServerAlias www.*.com
VirtualDocumentRoot /var/www/%1/production/html/
ServerAlias *.*.com
VirtualDocumentRoot /var/www/%2/production/html/%1
ServerAlias *.com
VirtualDocumentRoot /var/www/%1/production/html
i think should Work
VirtualDocumentRoot :
redcrusher.com
/var/www/redcrusher/production/html
www.redcrusher.com
/var/www/redcrusher/production/html/
sub.redcrusher.com
/var/www/redcrusher/production/html/sub

Apache Multi-sites

I've created two virtual hosts. tester.ly and tucnak.me
/sites-available/Lab:
<VirtualHost tucnak.me:80>
ServerAdmin kovalevskiy11#gmail.com
ServerName tucnak.me
DocumentRoot /home/tucnak/Web/Lab/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/tucnak/Web/Lab/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
#... here smth skipped.
</VirtualHost>
And /sites-available/Tester:
<VirtualHost tester.ly:80>
ServerAdmin kovalevskiy11#gmail.com
ServerName tester.ly
DocumentRoot /home/tucnak/Web/Tester/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/tucnak/Web/Tester/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
# skipped too.
</VirtualHost>
And my apache2 output:
[Mon Feb 13 20:17:07 2012] [warn] VirtualHost tucnak.me:80 overlaps with VirtualHost tester.ly:80, the first has precedence, perhaps you need a NameVirtualHost directive
I think that smthing wrong directive cause this problem. So, I need help.
You may have a NameVirtualHost *:80 or NameVirtualHost * directive in your configuration.
This mean your starting VirtualHost directives should be:
<VirtualHost *:80>
(...)
<VirtualHost *:80>
(...)
And not :
<VirtualHost tester.ly:80>
(...)
<VirtualHost tucnak.me:80>
(...)
The name of the VirtualHost is given by the ServerName directive inside the VirtualHost, not by the name used in the <VirtualHost xxx>. And this xxx should match one of the NameVirtualHost declarations in main configuration.