Virtual Host RHEL

Source: Internet
Author: User

IP-based, Port-based, and domain-based Virtual Host Configuration Methods


1. Virtual Hosts With the same IP address and different ports

1) vi/etc/HTTP/CONF/httpd. conf

2) Change the listen field

Listen 80

Listen 8888.

(The preceding settings indicate port 80 and port 8888 are used)

3) change the VM part:

<Virtualhost 192.168.0.1: 80>;

DocumentRoot/var/www/html/website1

</Virtualhost>;

<Virtualhost192.168.0.1: 8888>;

DocumentRoot/var/www/html/website2

</Virtualhost>;

4) Save the preceding settings.

5) create directories and page files:

# Mkdir-P/var/www/html/website1

# Mkdir-P/var/www/html/website2

# Cd/var/www/html/website1

# Cat> ingress index.html <EOF

>; Website1

>; EOF

# Cd/var/www/html/website2

# Cat> ingress index.html <EOF

>; Website2

>; EOF

(Note: in/etc/httpd/CONF/httpd. conf, there are directoryindex index.html index.html.var. the handler only reads index.html but does not read index.htm. Remember)

6) Service httpd restart

After completing the preceding settings, you can access them in the following ways:

1) Open a browser

2) Enter http: // 192.168.0.1: 80 and http: // 192.168.0.1: 8888.

2. VM based on different IP addresses of the same port

1) configurations of different IP addresses:

# Cd/etc/sysconfig/network-Scripts

# Cp ifcfg-eth0 ifcfg-eth0: 1

# Vi ifcfg-eth0: 1

Change eth0: 1:

Device = eth0: 1

Onboot = Yes

Bootproto = static

Ipaddr = 192.168.0.2

Netmask = 255.255.255.0

2) Service Network restart

3) vi/etc/httpd/CONF/httpd. conf

4) change the VM part:

<Virtualhost 192.168.0.1: 80>;

DocumentRoot/var/www/html/website1

</Virtualhost>;

<Virtualhost 192.168.0.2: 80>;

DocumentRoot/var/www/html/website2

</Virtualhost>;

5) create directories and page files:

# Mkdir-P/var/www/html/website1

# Mkdir-P/var/www/html/website2

# Cd/var/www/html/website1

# Cat> ingress index.html <EOF

>; Website1

>; EOF

# Cd/var/www/html/website2

# Cat> ingress index.html <EOF

>; Website2

>; EOF

After completing the preceding settings, you can access them in the following ways:

1) Open a browser

2) Enter http: // 192.168.0.1: 80 and http: // 192.168.0.2: 80.

3. Access to a domain name-based VM

1) vi/etc/HTTP/CONF/httpd. conf

2) Change the VM part:

Namevirtualhost 192.168.0.1

<Virtualhost www1.example.com>;

DocumentRoot/var/www/html/website1

Servername www1.example.com

</Virtualhost>;

<Virtualhost www2.example.com>;

DocumentRoot/var/www/html/website2

Servername www2.example.com

</Virtualhost>;

(Note: namevirtualhost cannot be omitted in the preceding settings)

3) create directories and page files:

# Mkdir-P/var/www/html/website1

# Mkdir-P/var/www/html/website2

# Cd/var/www/html/website1

# Cat> ingress index.html <EOF

>; Website1

>; EOF

# Cd/var/www/html/website2

# Cat> ingress index.html <EOF

>; Website2

>; EOF

4) after completing the preceding settings, you can access the service in the following ways:

1) Open a browser

2) Enter http://www1.example.com and http://www2.example.com

 

 

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.