CentOS 7 Operations Management notes (6)----Apache IP-based virtual host configuration

Source: Internet
Author: User
Tags echo command

Apache Configuration Virtual Host support 3 ways: IP-based virtual host configuration, Port-based virtual host configuration, domain-based virtual host configuration. This essay records your IP-based virtual host configuration.

If the same server has multiple IPs, you can use IP-based virtual host configuration to bind different services on different IPs.

(1) Bind IP:

The IP of the CentOS 7 server built in the virtual machine is set by itself for static IP 192.168.1.210, and is now bound with Ifconfig on the same network interface 192.168.1.211~213 these three IPs:

Ifconfig eth0:1192.168. 1.211/  upifconfig eth0:2192.168. 1.212/  upifconfig eth0:3192.168. 1.213/ up

(2) Set the name of the IP address in the/etc/hosts file:

Test the three IP addresses with the ping command:

You can see that the three addresses are open.

(3) Establish a virtual host to store Web pages and directories, and create home file index.html:

(i) The home address of the Apache server is/usr/local/apache2, at this address, the Htdocs folder for the default server hosts the root directory of the Web page, now in the/usr/local/apache2 directory new www folder, in The root directory for the new three virtual hosts under the WWW folder Nice1,nice2 and nice3:

cd/usr/local/apache2mkdir  wwwcd wwwmkdir  nic1 nice2 nice3

(ii) Use the echo command to generate a index.html file in the root directory of three virtual hosts:

Echo " This is Nice1, welcome. "> nice1/index.htmlecho"Thisis Nice2, welcome. "> nice2/index.htmlecho"Thisis Nice3, welcome. "> nice3/index.html

(4) Modify the/usr/local/apache2/conf/httpd.conf file to add the following at the end of the file:

192.168. 1.211:192.168. 1.212:192.168. 1.213:Include conf/vhost/*conf

(5) Edit the configuration file for each IP:

[Email protected]:/usr/local/apache2] # cd/usr/local/apache2/conf[[email protected]:mkdir  Vhost[[email protected]:/usr/local/apache2/conf] # CD Vhost

In the/usr/local/apache2/conf/vhost/directory with the VIM command to generate and edit nice1.conf, nice2.conf, nice3.conf three files, the contents are as follows:

Just cite nice1.conf as an example:

192.168. 1.211:>        ServerName nice1        documentroot    /usr/local/apache2/www/  Nice1        "/usr/local/apache2/www/nice1/">                Options Indexes FollowSymLinks                allowoverride    None                Require all granted        </directory></ Virtualhost>

(6) The Apache service can be started and tested after the configuration is complete:

(i)

(ii) Use the Curl command to view the contents of the three virtual hosts:

(iii) View the contents of the three virtual hosts using a Windows host browser:

Success!

CentOS 7 Operations Management notes (6)----Apache IP-based virtual host configuration

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.