Virtual
Configure web server
Code: [Select]
Starting httpd: [warn] _default_ VirtualHost overlap on port 80, the first has precedence
# echo "NameVirtualHost *:80" >> /etc/httpd/conf/httpd.conf
--------------------------------
vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
# service httpd restart
Sample Apache 2 Virtual hosting configuration
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName mail.worldcm.net
# ServerAlias mail.worldcm.net
# ErrorLog /var/www/example.com/error.log
# CustomLog /var/www/example.com/requests.log
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/new
ServerName mail.worldcm.net/new
# ServerAlias example.com
# ErrorLog /var/www/example.com/error.log
# CustomLog /var/www/example.com/requests.log
</VirtualHost>
# My Virtual Hosts Config File for Two Domains NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin webmaster@theos.in DocumentRoot "/usr/local/docs/theos.in" ServerName www.theos.in ServerAlias theos.in ErrorLog "/var/log/theos.in-error_log" CustomLog "/var/log/theos.in-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@nixcraft.com DocumentRoot "/usr/local/docs/nixcraft.com" ServerName www.nixcraft.com ServerAlias nixcraft.com ErrorLog "/var/log/nixcraft.com-error_log" CustomLog "/var/log/nixcraft.com-access_log" common </VirtualHost>
####################################################################################
Vertual OR sub webpage creat
www.yourIP.net/new
[root@mail ~]# mkdir /var/www/new
[root@mail ~]# vi /etc/httpd/conf.d/new.conf
Alias /new /var/www/new
DocumentRoot "/var/www/new"
<Directory "/var/www/new">
allow from all
Options None
Require all granted
</Directory>
-----------------------------
/etc/httpd/conf.d/postfixadmin.conf
alias /mailadmin /usr/share/postfixadmin <Directory "/usr/share/postfixadmin"> AllowOverride AuthConfig </Directory>
------------------------------------
Name Based Virtual Hosts
Using Name Based Virtual Hosts is quite easy. The notable difference between IP-based and name-based virtual host configuration is the NameVirtualHost directive which specifies an IP address that should be used as a target for name-based virtual hosts.
For example, we use both www.akadia.ch and www.arkum.ch at the IP address 193.247.121.196. We simply add to one of the Apache configuration files (most likely httpd.conf) code similar to the following:
NameVirtualHost 193.247.121.196
<VirtualHost 193.247.121.196>
ServerName www.akadia.ch
DocumentRoot /www/akadia
</VirtualHost>
<VirtualHost 193.247.121.196>
ServerName www.arkum.ch
DocumentRoot /www/arkum
</VirtualHost>
Of course, any additional directives can (and should) be placed into the <VirtualHost> section. To make this work, all that is needed is to make sure that the names www.akadia.ch and www.arkum.ch are pointing to the IP address 193.247.121.196
When you specify an IP address in a NameVirtualHost directive then requests to that IP address will only ever be served by matching <VirtualHost>s. The "main server" will never be served from the specified IP address. If you start to use virtual hosts you should stop to use the "main server" as an independent server and rather use it as a place for configuration directives that are common for all your virtual hosts. In other words, you should add a <VirtualHost> section for every server (hostname) you want to maintain on your server.
In this example we will configure a web server.
necessary rpm for web server is httpd, httpd-devel and apr check them for install
Now configure the ip address to 192.168.0.254 and check it
start httpd daemons and verify its running status
Configure virtual hosting
In this example we will host a website www.vinita.com to apache web server. create a documents root directory for this website and a index page
for testing purpose we are writing site name in its index page
save file and exit
now open /etc/hosts file
in the end of file bind system ip with www.vinita.com
now open /etc/httpd/conf/httpd.conf main configuration file of apache server
locate virtual host tag
remove # from the beginning and add the IP of host
Now go in the end of file and copy last seven line [ virtual host tag ] and paste them in the end of file. change these seven lines as shown in image
now save this file and exit from it
you have done necessary configuration now restart the httpd service and test this configuration run links command
if links command retrieve your home page
means you have successfully configured the virtual host now test it with site name
In output of links command you should see the index page of site
Configure multiple site with same ip address
At this point you have configured one site www.vinita.com with the ip address 192.168.0.254. Now we will configure one more site www.nikita.com with same ip address
create a documents root directory for www.nikita.com website and a index page
for testing purpose we are writing site name in its index page
save file and exit
now open /etc/hosts file and bind system ip with www.nikita.com
now open /etc/httpd/conf/httpd.conf main configuration file of apache server
Now go in the end of file and copy last seven line [ virtual host tag ] and paste them in the end of file. change these seven lines as shown in image
now save this file and exit from it
you have done necessary configuration now restart the httpd service
test this configuration run links command
In output of links command you should see the index page of site
configure multiple site with multiple ip address
Now we will host multiple sites with multiple ip address. Create a virtual lan card on server and assign its an ip address of 192.168.0.253. we will create a testing sitewww.nidhi.com and will bind it with ip address of 192.168.0.253
create a documents root directory for www.nidhi.com website and a index page
for testing purpose we are writing site name in its index page
save file and exit
now open /etc/hosts file and bind system ip with www.nidhi.com
now open /etc/httpd/conf/httpd.conf main configuration file of apache server
Now go in the end of file and copy last seven line [ virtual host tag ] and paste them in the end of file. change these seven lines as shown in image
now save this file and exit from it
you have done necessary configuration now restart the httpd service
test this configuration run links command
In output of links command you should see the index page of site
How to create site alias
Now I will show you that how can you use site alias to configure more name of same site. we configure a site www.vinita.com in stating of example. now we will createwww.goswami.com site alias for this site so this site can be access with both name.
To create alias first make its entry in /etc/hosts file as shown here
Now open main apache configuration /etc/httpd/conf/httpd.conf
Now go in the end of file and copy last seven line [ virtual host tag ] and paste them in the end of file. change these seven lines as shown in image
now save this file and exit from it
you have done necessary configuration now restart the httpd service and test this configuration run links command
In output of links command you should see the index page of site