Three configuration methods are available for apache Virtual Hosts and three for apache Virtual Hosts.

Source: Internet
Author: User

Three configuration methods are available for apache Virtual Hosts and three for apache Virtual Hosts.

Go straight to the topic !!!

To use a VM, you must comment out the httpd Host module, that is, modify the main configuration file of httd. conf, find <DirectoryROOT "XXXXXX">, and comment out the content.

Apche has three types of virtual host configurations: IP address, port-based, and domain name-based. For subsequent experiments, we need to configure two IP addresses (the current IP address of my host is 10.10.50.100). The command is as follows:

# Ip addr add 10.10.50.101/16 dev eth0

# Ip addr add 10.10.50.102/16 dev eth0

I will not go into details about how to configure IP addresses here. I will write an article about IP addresses later.

First: IP-based

When apache is installed silently, the main configuration file is httpd under/etc/httpd/conf. conf, you can add virtual hosts at the bottom of the file, but I am used to re-establishing a virtual host configuration file, which facilitates future management operations.

1. Create a VM configuration file

# Mkdir/etc/httpd/conf. d/virtual. conf

2. edit the file and add the following content:

<VirtualHost 10.10.50.100: 80>

ServerName www.longfei.com

DocumentRoot "/www/longfei.com"

</Virtualhost>

<VirtualHost 10.10.50.101: 80>

ServerName www.longfei2.com

DocumentRoot "/www/longfei2.com"

</Virtualhost>

------ Save and exit. This is the simplest configuration.

3. Create a directory file

# Mkdir/www/{longfei.com, longfei2.com}

4. Create a home page file under the directory file for subsequent access tests.

# Vi/www/longfei2.com/index.html,##content

<Title> Longfei </title>

<H1> This is longfei test

Save and exit. Edit the home page file under another directory.

# Vi/www/longfei2.com/index.html,##content

<Title> Longfei2 </title>

<H1> This is longfei2 test 5. Restart the httpd service. (before restarting the service, check whether the syntax is correct. httpd-t)

Service httpd restart

6. Client Access Test

Enter the following in the browser:

10.10.50.100 and

10.10.50.101

The homepage defined between us is displayed.

Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Second, Port-based Virtual Host

Use the vitual. conf created above as the configuration file. Assume that port 80 and port 8080 are used, and the IP address is 10.10.50.102.

1. Modify the main configuration file of httpd, vi/etc/httpd/conf/httpd. conf.

First, remove the comment before Listen 80, then add a row of Listen 8080, save and exit.

2. Modify the VM configuration file and add the following content:

<VirtualHost 10.10.50.102: 80>

ServerName www.a80.com

DocumentRoot "/www/a80.com"

</VirtualHost>

<VirtualHost 10.10.50.102: 8080>

ServerName www.a80.org

DocumentRoot "/www/a80.org"

</VirtualHost>

3. create the required root file

# Mkdir/www/{a80.com, a80.org}

4. Create the default access page for each root file. The creation process is the same as step 4. You can replace the content in it with what you can recognize. I use two specifiers, a80.com and a80.org.

5. Check the syntax

Httpd-t

6. Restart the service.

7. Access Test

Enter 10.10.50.102 and 10.10.50.102: 8080 in the browser respectively. Because the browser uses port 80 by default, you do not need to specify a port when accessing the website on port 80.


Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Third, domain name-based Virtual Host

1. Domain Name-based VMFirst, you must specify IP: PORT in the virtual configuration file, that is, modify the virtual configuration file. Add NameVirtualHost 10.10.50.100: 80 in the first line.

Add the following information below:

<VirtualHost 10.10.50.100: 80>

ServerName hello.longfei.com

DocumentRoot "/hello/longfei.com"

</VirtualHost>

<VirtualHost 10.10.50.100: 80>

ServerName hello.longfei.org

DocumentRoot "/hello/longfei.org"

</VirtualHost>

2. Create the required directory with the file

Mkdir/hello/{longfei.com, longfei.org}

3. Edit the home page file under the root file directory. Refer to the above method.

4. Modify the hosts file of the client host to ensure that the two domain names we set can be resolved normally.

The hosts file is located in/C/windows/Drivers/etc/hosts (it seems like yes, I do not know it clearly. You can Baidu for kids shoes)

Add the following two columns

10.10.50.100 hello.longfei.com

10.10.50.100 hello.longfei.org

5. Use the ping command to ensure normal resolution.

That is to say, ping hello.longfei.com and ping hello.longfei.org are both accessible and the return value is 10.10.50.100.

6. Restart the httpd service.

7. browser testing

Enter hello.longfei.com and hello.longfei.org in the browser respectively, and then check whether the homepage is our previous logo page.

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Supplement:

1. the VM also supports location redefinition of access logs and error logs, that is, you only need to add log information entries under DocumentRoot, for example, if you want to relocate the access log and error log of hello.longfei.org to the/hello/longfei.org/logdirectory, please refer to this line.

CutomLog "/hello.longfei.org/log" combined

ErrorLog "/hello/longfei.org/log"

After saving and exiting, create the log directory under longfei.org.

2. the VM can also return server status information.

For example, if you want to display the server, you only need to comment out the content of <Location/server-status> in the main configuration file of httpd and add your IP address after Allow from, in this way, you can only access and view it by yourself. View method: Enter hello.longfei.org/server-statusin the browser. That is, if Directory defines the file path, Location defines the URL path. server-status can be added to any path to view server information.

3. the VM also supports the same access restrictions as the real host. For details, see the http://blog.csdn.net/brad_chen/article/details/45749123

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.