Three Virtual Host Configuration Methods Based on IP, port, and domain name

Source: Internet
Author: User
Article Title: three virtual host configuration methods: IP, port, and domain name. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
   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:
  
DocumentRoot/var/www/html/website1
  
  
DocumentRoot/var/www/html/website2
  
  
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> index.html < > Website1
> EOF
# Cd/var/www/html/website2
# Cat> index.html < > 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:
  
DocumentRoot/var/www/html/website1
  
  
DocumentRoot/var/www/html/website2
  
  
5) create directories and page files:
# Mkdir? P/var/www/html/website1
# Mkdir? P/var/www/html/website2
# Cd/var/www/html/website1
# Cat> index.html < > Website1
> EOF
# Cd/var/www/html/website2
# Cat> index.html < > 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
  
DocumentRoot/var/www/html/website1
ServerName www1.example.com
  
  
DocumentRoot/var/www/html/website2
ServerName www2.example.com
  
  
(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> index.html < > Website1
> EOF
# Cd/var/www/html/website2
# Cat> index.html < > 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
Related Article

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.