Apache Virtual Hosting name based in CentOS

Apache Virtual Hosting name based in CentOS


edit
# vi /etc/httpd/conf/httpd.conf

find NameVirtualHost *:80 and un-command this line


<VirtualHost *:80>
    ServerAdmin admin mail id
    DocumentRoot /var/www/html/app1
    ServerName app1.example.in
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin admin mail id
    DocumentRoot /var/www/html/app2
    ServerName app2.example.in
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin admin mail id
    DocumentRoot /var/www/html/app3
    ServerName app3.example.in
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

save and exit the file

#service httpd restart
--------------------------------------------------------
one more Important note
if the sub domain page should be in a directory or folder, it wouldnt work when you put a single page instead of folder or directory

for example
not work when
DocumentRoot /var/www/html/index.html
work when
DocumentRoot /var/www/html/app3
//if index.html should be placed in app3 folder it would be work

------------------------------------------------------------
For centOS 7

## vi /etc/httpd/conf/httpd.conf  //edit
add following line at very end of the file

IncludeOptional sites-enabled/*.conf

# mkdir /etc/httpd/sites-available
# mkdir /etc/httpd/sites-enabled
# mkdir /etc/httpd/sites-available/booglenow.com

# vi /etc/httpd/sites-available/booglenow.com.conf
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    ServerName www.coolexample.com
    ServerAlias coolexample.com
    DocumentRoot /var/www/coolexample.com/public_html
    ErrorLog /var/www/coolexample.com/error.log
    CustomLog /var/www/coolexample.com/requests.log combined
</VirtualHost>

# sudo ln -s /etc/httpd/sites-available/booglenow.com.conf /etc/httpd/sites-enabled/booglenow.com.conf

#systemctl restart httpd.service




visit link download