A detailed explanation of Apache virtual Host configuration method

Source: Internet
Author: User

Instance one, Apache configure localhost virtual host steps
1, with Notepad open the Apache directory httpd files (such as: d:wampbinapacheapache2.2.8conf), find the following modules

# Virtual Hosts
#Include conf/extra/httpd-vhosts.conf

Remove the front # so that the Httpd-vhosts virtual host file is turned on. This time reboot WAMP environment, cannot open localhost, need to configure in httpd-vhosts.conf.

2, with Notepad to open the Httpd-vhosts file, configure the localhost virtual host, refer to the Httpd-vhosts file instance, modified as follows:

The code is as follows Copy Code

<virtualhost *:80>
ServerAdmin Webmaster@dummy-host.localhost
DocumentRoot "D:wampwww"
ServerName localhost
Serveralias localhost
ErrorLog "Logs/dummy-host.localhost-error.log"
Customlog "Logs/dummy-host.localhost-access.log" common
</VirtualHost>

Modify the configuration as follows:
DocumentRoot modified to a local WAMP environment in the WWW directory (such as: d:wampwww)
ServerName changed to localhost

3, restart Apache, found localhost can be opened normally, configuration localhost relatively simple.

Instance two, Apache configure www.111cn.net Virtual host steps

1, the method above, the replication configuration code modified as follows:

The code is as follows Copy Code

<virtualhost *:80>
ServerAdmin test@biuuu.com
DocumentRoot e:webrootbiuuu
ServerName www.111cn.net
ErrorLog "Logs/dummy-host2.localhost-error.log"
Customlog "Logs/dummy-host2.localhost-access.log" common
</VirtualHost>

2, open the host file (c:windowssystem32driversetchosts), add one line of code

127.0.0.1 www.111cn.net

3, open www.111cn.net in the browser, find the following error 403 Forbidden Error
Forbidden
You don ' t have permission to access/on this server.

Analysis: This is mainly directory access permissions are not set, you need to set access to the directory!

4, open the httpd file and find the following statement

The code is as follows Copy Code

<directory/>
Options FollowSymLinks
AllowOverride None
Order Deny,allow
Deny from all
</Directory>

Copy the above code, and make a directory modification, replace it with E:WEBROOTBIUUU, modify the VirtualHost code as follows

The code is as follows Copy Code

<virtualhost *:80>
ServerAdmin test@biuuu.com
DocumentRoot e:webrootbiuuu
ServerName www.111cn.net
ErrorLog "Logs/dummy-host2.localhost-error.log"
Customlog "Logs/dummy-host2.localhost-access.log" common

<directory e:webrootbiuuu>
Options FollowSymLinks
AllowOverride None
Order Deny,allow
Deny from all
</Directory>

</VirtualHost>

The test found in the browser is still not open, prompted as 403 Forbidden error, modify the deny from all to allow from all

5, restart Apache, the virtual host configuration success!

Attention matters
1, directory path, such as E:webrootbiuuu
2, access rights, such as upper deny from all modified to allow from all
3,host file, configuring the virtual domain name host to point to
4,HTTPD file, open include conf/extra/httpd-vhosts.conf module
5,httpd-vhosts files, configuring virtual hosts

Using Apache configuration httpd-vhosts Virtual host is simpler for developers, but is very important for reference only!

Ps:d:wampalias can also configure the virtual domain name, and the same effect as the case two

The code is as follows Copy Code

<virtualhost *:80>
ServerName blog.cc
Serveralias blog.cc
DocumentRoot "D:wampwwwblog"
<directory "D:wampwwwblog" >
Options all FollowSymLinks includesnoexec Indexes
DirectoryIndex index.html index.htm default.htm index.php default.php index.cgi default.cgi index.shtml index.aspx Default.aspx
AllowOverride All
Order Deny,allow
Allow from all
</Directory>
</VirtualHost>

Finally, let's do a security php.ini.

  code is as follows copy code


Disable _functions = Here you can restrict the PHP function

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.