What is Virtual Host
virtual Host is used to serve multiple websites from individual waiter. virtual server used to enclose a group of directives that will apply only to a particular virtual host .
How to Set Up Virtual Hosts in Apache on Mac OS
Let ’ s set up our virtual host. To start with, Open httpd.conf file in your editor. I am using end with energy editor .
If you are not companion with energy editor program then check my former tutorial on Vim editor steer.
1 |
sudo vim
/ etc / apache2 / httpd . conf |
search for httpd-vhosts.conf and uncomment this line. search and replace in Vim editor program .
1 2 3 |
// Uncomment this line. Include
/ private / etc / apache2 / extra / httpd – vhosts . conf |
now open httpd-vhosts.conf file in energy ( or any editor you prefer ) .
1 |
sudo vim
/ private / etc / apache2 / extra / httpd – vhosts . conf |
Directives and their Meaning used in Virtual Host
DocumentRoot – It specify which file to serve by Apache for a given request. In my font one have pointed my raw project directory ( /Library/WebServer/Documents/first_project/ ) .
ServerName – ServerName is used to uniquely identify a virtual host when using name based virtual hosts .
ServerAlias – It sets the understudy name for a host. It may include wildcards ampere well ( ServerName *.local.com ) .
AllowOverride All – This directing leave .htaccess file directives to apply on your project. If you don ’ thyroxine want to apply .htaccess directives then set AllowOverride None .
complete explanation of htaccess is explained in my previous htaccess tutorials .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
< VirtualHost
* : 80 >
DocumentRoot
/ Library / WebServer / Documents / first_project /
ServerName local . com
ServerAlias www . local . com
ErrorLog
“/private/var/log/apache2/local.com-error_log”
CustomLog
“/private/var/log/apache2/local.com-access_log”
common
ServerAdmin admin @local . com
< Directory
“/Library/WebServer/Documents/first_project/” >
Options Indexes FollowSymLinks
AllowOverride All
Order allow , deny
Allow from all
< / Directory > < / VirtualHost > |
now we have set up our virtual host. Let ’ s map information science address to domain name in hosts file .
1 |
sudo vim
/ etc / hosts |
Add following submission in hosts file .
1 |
127.0.0.1
local . com www . local . com |
now everything is done. Let ’ s resume apache server .
1 |
sudo apachectl restart |
Reference Link
Apache virtual host software documentation
Share
0
Shares