Apache configures the port-based virtual host Apache Virtual Host Configuration is based on the port

Source: Internet
Author: User

There may be only one IP outlet, but there are multiple projects, then you need to set up a virtual host based on the port number.

Step 1:

Check whether the httpd-vhosts.conf is enabled

Apache/CONF/httpd. conf file

# Virtual hostsInclude conf/extra/httpd-vhosts.conf

If it is not enabled, it must be in httpd. CONF file; if enabled, you can set in Apache/CONF/extra/httpd-vhosts.conf file, of course, you can also httpd. the configuration in the conf file is also valid.

 

Step 2:

Httpd. in the conf file, DocumentRoot must be configured as the parent directory of the project of the VM, where DocumentRoot has the highest limit, the DocumentRoot directory level set in the VM can only be equal to or lower than the DocumentRoot directory here.

# symbolic links and aliases may be used to point to other locations.#DocumentRoot "D:\htdocs"<Directory "D:\htdocs">

 

Step 3:

Add a multi-port listener to the httpd. conf file.

## Listen: Allows you to bind Apache to specific IP addresses and/or# ports, instead of the default. See also the <VirtualHost># directive.## Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses.##Listen 12.34.56.78:80Listen 80Listen 81Listen 82

 

Step 4:

Follow the rules in step 1 to add the VM configuration.

<VirtualHost *:80>    DocumentRoot "D:\htdocs\project1\www"    ServerName 127.0.0.1:80    <Directory "D:\htdocs\project1\www">        Options Indexes FollowSymLinks Multiviews        AllowOverride All        Order Allow,Deny        Allow from all    </Directory></VirtualHost>
<VirtualHost *:81> DocumentRoot "D:\htdocs\project2" ServerName 127.0.0.1:81 <Directory "D:\htdocs\project2"> Options Indexes FollowSymLinks Multiviews AllowOverride All Order Allow,Deny Allow from all </Directory></VirtualHost>

 

Note:

The configuration of port 80 must be overwritten in the VM configuration. Otherwise, the DocumentRoot directory configured in httpd. conf will be used, and the project's parent directory will be exposed.

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.