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.
Related
I have a set up as follows:
All subdomains pointing to the server
sub1.example.com should load /var/www/sub1
sub2.example.com should load /var/www/sub2
Any random subdomain should load /var/www/shared
The problem is the shared.conf file is being ignored and instead using sub1 (or whichever one I move to the start of the .conf file list).
Here are my conf files in their order after running ls -lv
sub1.conf
sub2.conf
shared.conf
sub1.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName sub1.example.com
ServerAlias sub1.example.com
<Directory /var/www/sub1/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/sub1
</VirtualHost>
sub2.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName sub2.example.com
ServerAlias sub2.example.com
<Directory /var/www/sub2/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/sub2
</VirtualHost>
shared.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias *.example.com
<Directory /var/www/shared/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/shared
</VirtualHost>
I have also tried adding a random subdomain to the shared.conf file for Server Name, i.e.
ServerName shared-random.example.com
And also
ServerName *.example.com
I have also made sure to restart apache.
So when I put in any subdomain, e.g. blabla.example.com it always goes to sub1.conf.
I understand that the behaviour is to default to the first one, but only if there isnt a match. Why isnt shared.conf being considered a match?
change filename from shared.conf to 000-shared.conf
use below config for 000-shared.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/shared
<Directory /var/www/shared>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
</VirtualHost>
i have tried creating the virtual hosts via this following link
Digital Ocean Virtual Host
However it is using only first vhost settings. i have tried many tutorials but nothing is working.
Finally i have put the vhost settings in httpd.conf file
Listen 8000
<VirtualHost *:80>
ServerName abc.edu
ServerAlias www.abc.edu
DocumentRoot /var/www/html/abc/frontend/dist
<Directory /var/www/html/abc/frontend/dist>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8000>
ServerName apiabc.edu
ServerAlias www.apiabc.edu
Alias /static /var/www/html/abc/abc/static
<Directory /var/www/html/abc/abc/static>
Require all granted
</Directory>
<Directory /var/www/html/abc/abc/abc>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess abc python-path=/var/www/html/abc/abc python-home=/var/www/html/abc/env
WSGIProcessGroup abc
WSGIScriptAlias / /var/www/html/abc/abc/abc/wsgi.py
</VirtualHost>
I have an EC2 instance setup running Ubuntu 14.04 and Apache. I have a single elastic IP serving multiple domains and subdomains all of which point to individual folders on the server. The problem I am having is unless the subdomain is explicitly set in my .conf it will redirect to the main domain. I can't seem to find a definitive answer here or in google.
I have a single .conf file residing in /etc/apache2/sites-enabled/ serving all of the domains and subdomains like so:
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html/mydomain.com
<Directory /var/www/html/mydomain.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName sub1.mydomian.com
ServerAlias www.sub1.mydomain.com
DocumentRoot /var/www/html/sub1.com
<Directory /var/www/html/sub1.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName sub2.mydomian.com
ServerAlias www.sub2.mydomain.com
DocumentRoot /var/www/html/sub2.com
<Directory /var/www/html/sub2.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName mydomain2.com
ServerAlias www.mydomain2.com
DocumentRoot /var/www/html/mydomain2.com
<Directory /var/www/html/mydomain2.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
So if I go to sub1.mydomain.com or sub2.mydomain.com it gets properly routed. But if I type sub3.mydomain.com which does not exist in my .conf file it gets redirected to mydomain.com. I do not want this behavior. How do I resolve this?
You need to enable name based virtualhosts. Add below line before your first virtual host and restart apache.
NameVirtualHost :80
<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
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.