Apache Virtual host Building (original)

Source: Internet
Author: User

The meaning of virtual hosting: Simulate a remote server's access environment, minimize the difference with the remote server environment, can be locally modified after uploading, rather than through the remote server in the modification;

And the virtual host can be used to simulate different domain name access effects.

I. Configuration of a domain-based virtual host

1. Notepad opens the Hosts file, which is in: \ C Windows\ system32\ drivers\etc This folder, write the following at the end of the file content:

127.0.0.1 www.lamp1018.com Function: Point the access address to local in the Hosts file

2. Notepad open the httpd-vhosts.conf file, the file in the Apache directory, such as: E:\WAMP\ Apache24\conf\extra, according to the original format of the file to add a virtualhost, only modify the following two comments As follows:

<virtualhost *:80>

ServerName www.lamp1018.com
DocumentRoot E:\WAMP\Apache24\lamp1018.com

</VirtualHost>

Note Keep the default localhost before

<virtualhost *:80>

ServerName localhost
DocumentRoot E:\WAMP\Apache24\WWW

</VirtualHost>

3. Notepad opens the httpd.conf file, which is located in the Apache directory, such as: E:\WAMP\ apache24\conf, modified as follows two:

LoadModule vhost_alias_module modules/mod_vhost_alias.so//Remove the front #, meaning to enable the Apache Virtual Host feature

Include conf/extra/httpd-vhosts.conf//Remove # means to import a virtual host configuration from httpd-vhosts.conf this file

4. Restart Apache and enter www.lamp1018.com in the browser to access it.

Two. Configuration of the port-based virtual host

1. Notepad open the httpd-vhosts.conf file, according to the format of the file and add a virtualhost, modify the port number and project path, as follows (note: The port number to ensure that the system has not been used in the port number conflicts, so try to set to 4 to 5 digits):

<virtualhost *:12345> #这里修改为自定义的端口号

DocumentRoot "E:\WAMP\Apache24\WWW\ecshop" #DocumentRoot后面修改为网站的根路径

ServerName localhost# here to keep localhost.

</VirtualHost>

2. Open the httpd.conf file and add the following code to let Apache listen to the ports above us:

Listen 12345

3. Save and restart Apache, then enter "localhost:12345" in the browser to access our project.

Note 1: The appearance of permission to access/on the this server is due to the fact that my virtual host directory is a non-Apache installation directory under Htdocs, so it violates the Apache default access rights to the site root.

The default virtual host root address for Apache is: Under the/apache24/htdocs directory, you need to modify the httpd.conf file to point to a different directory.

# Deny access to the entirety of your server ' s filesystem. You must
# explicitly permit access to Web content directories in other
# <Directory> blocks below.
#
<directory/>
AllowOverride All
Require all denied
</Directory>

Revision changed to

<directory/>
AllowOverride All
Require all granted
</Directory>

Note 2: Because 127.0.0.1 in the hosts file points to both localhost and www.lamp1018.com, it is best to use domain name access after the virtual host has been modified, such as 127.0.0.1 may not be able to access the page

Apache Virtual host Building (original)

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.