14. Three virtual hosts and 14 three virtual hosts

Source: Internet
Author: User

14. Three virtual hosts and 14 three virtual hosts

A vm provides Web Services for multiple individual domain names on a WWW server.

Apache supports Virtual Hosts in three ways:

1. IP-based VM:Multiple IP addresses are configured on one server. Each IP Address has a specific directory and configuration. Suitable for scenarios with sufficient IP addresses

 

1、[root@localhost root]#   vi  /etc/named.conf

zone "gr.org" IN {        type master;        file "gr.org.db";        allow-update { none; };};zone "170.168.192.in-addr.arpa" IN {       type master;       file "170.168.192.db";};


 

2. forward regional database file

[Root @ localhost root] # vi/var/named/gr.org. db

$TTL 86400@ IN SOA  ns.gr.org.    root.gr.org.(            20140308 ;serial            8H       ;refresh            4M       ;retry            1W       ;expiry            1D  )    ;minimum@      IN   NS      ns.gr.org.ns     IN   A       192.168.170.1host1  IN   A       192.168.170.1host2  IN   A       192.168.170.2host3  IN   A       192.168.170.3

 

Reverse region database file

[Root @ localhost root] # vi/var/named/170.168.192.db

$TTL 86400@ IN SOA ns.gr.org.  root.gr.org.(                     20150826                     8H                     4M                     1W                     1D)          IN   NS     ns.gr.org.1         IN   PTR    ns.gr.org.1         IN   PTR    host1.gr.org.2         IN   PTR    host2.gr.org.3         IN   PTR    host3.gr.org.

3. Set the DNS Client

[Root @ localhost root] # cat>/etc/resolv. conf
Nameserver 192.168.170.4

Service named start (start service)
If it has been started, run the rndc reload command to restart the service)

 

4. Configure the VM

[Root @ localhost conf. d] # vi/etc/httpd/conf. d/host_ip.conf

<VirtualHost 192.168.170.1:80>    DocumentRoot /var/www/host1    ServerName   host1.gr.org</VirtualHost><VirtualHost 192.168.170.2:80>    DocumentRoot /var/www/host2    ServerName   host2.gr.org</VirtualHost><VirtualHost 192.168.170.3:80>    DocumentRoot /var/www/host3    ServerName   host3.gr.org</VirtualHost>

5. Add the IP address of the sub-interface

[Root @ localhost conf. d] # ifconfig eth0: 1 192.168.170.1

[Root @ localhost conf. d] # ifconfig eth0: 2 192.168.170.2

[Root @ localhost conf. d] # ifconfig eth0: 3 192.168.170.3

 

6. Create a VM directory and a test Homepage

Mkdir/var/www/host {1, 2, 3}

Cd/var/www

Echo "this host1"> host1/index.html

Echo "this host2"> host2/index.html

Echo "this host3"> host3/index.html

 

7. Restart the service

Service httpd restart

 

The result is as follows:

2. Port-based VM:

1. Create the host_port.conf file in the/etc/httpd/conf. d directory and add the following content:

Listen  192.168.170.1:8000Listen  192.168.170.1:8888<VirtualHost  192.168.170.1:8000>      DocumentRoot   /var/www/host4      ServerName   host1.gr.org </VirtualHost> <VirtualHost  192.168.170.2:8888>     DocumentRoot   /var/www/host5     ServerName   host1.gr.org </VirtualHost>

 

2. Create a VM working directory and test Homepage

mkdir  /var/www/host{4,5}   echo  “this host1(8000)” > /var/www/host4/index.html   echo  “this host1(8888)” > /var/www/host5/index.html

3. Restart the service

Service httpd restart

 

Test

Iii. Name-based virtual hosts (most of which are used)

Access from multiple domain names corresponds to the same IP address

1. Add the following content to the forward regional database file

music   IN  A  192.168.170.1movie   IN  A  192.168.170.1

 

2. Add the following content to the reverse regional database file

1   IN   PTR    music.gr.org.1   IN   PTR    movie.gr.org.

 

3. Create the host_domain.conf file in the/etc/httpd/conf. d directory and add the following content:

<VirtualHost   music.gr.org:80> DocumentRoot   /var/www/musicServerName   music.gr.org</VirtualHost> <VirtualHost   movie.gr.org:80> DocumentRoot   /var/www/movie ServerName   movie.gr.org</VirtualHost>

 

4. Create a VM's working directory and test Homepage

cd    /var/wwwmkdir  music  movieecho “this  music” >  music/index.htmlecho “this  movie” >  movie/index.html

 

5. Restart the service

Rndc reload or service named restart

Service httpd start

 

6. Test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.