Apache Virtual Host Configuration

Source: Internet
Author: User
Tags tld

<VirtualHost *: 80>

ServerAdmin webmaster@example.com-Administrator mailbox (you can write one)
DocumentRoot "/home/phpok-com" -- website directory
ServerName example.com -- the domain name to bind
ServerAlias www.example.com -- alias to be bound. Separate multiple aliases with commas (,).
CustomLog logs/example.com _ custom_log -- user log format (this line can also be empty)
ErrorLog logs/example.com _ error_log -- Error Log (can also be empty)
</VirtualHost>
 
Steps:
1. Modify httpd. conf
Remove the # Include conf/extra/httpd-vhosts.conf in front of #, which means to let the httpd. conf file Include the httpd-vhosts.conf configuration file, which is a manifestation of apache configuration modularization, not to mention here.
 
Find httpd. serverName in conf. If ServerName is not set as the domain name www.abc1.com, change it to ServerName www.abc1.com. If you want to use something like ssl, change it to ServerName www.abc1.com: 80 and add a port.
 
2. Modify httpd-vhosts.conf
 
Add the following code (some files may exist. You can change it ):
 
NameVirtualHost *
 
<VirtualHost *>
DocumentRoot "C:/aic"
ServerName www.abc1.com
ServerAlias abc1.com * .abc1.com
</VirtualHost>
 
<VirtualHost *>
DocumentRoot "c:/aic/mybbonline"
ServerName www.efg2.com
ServerAlias efg2.com * .efg2.com
</VirtualHost>
 
It is worth noting that VirtualHost is ordered, and our default website domain name is ranked first in VirtualHost. Both DocumentRoot and ServerName must be the same as that in httpd. conf, including ports.
 
DocumentRoot is the path of the VM.
 
ServerAlias is the alias of the domain name. With this configuration, some second-level domain names can be resolved on the virtual host. For example, * .efg2.com can represent bbs.efg2.com or news.efg2.com.
 
-----------------------------------------------------------------
 
The general form of the VM, such as (extra/httpd-vhosts.conf ):
 
NameVirtualHost *: 80
 
<VirtualHost *: 80>
ServerName www. domain. tld
ServerAlias domain. tld *. domain. tld
DocumentRoot/www/domain
</VirtualHost>
 
<VirtualHost *: 80>
ServerName www. otherdomain. tld
DocumentRoot/www/otherdomain
</VirtualHost>
 
This is an example in apache2.2 Chinese reference manual. Generally, this configuration is correct in earlier versions. But now it's different. When you access a page under a VM, the following error occurs: "403 (Access prohibited). You cannot view this page ..." . Obviously, this is a prompt to reject access. According to experience, it is easy to find the content below (httpd. conf:
 
<Directory/>
 
Options FollowSymLinks
 
AllowOverride None
 
Order deny, allow
 
// Deny from all
// Reject all access requests </Directory>
 
 
This part controls access to directories. Obviously, this setting is very strict. Therefore, we must manually add the permission control block to the Virtual Machine directory, allows users to access the Virtual Machine directories and page files normally. There are two places to add the virtual directory access permission control block: The main configuration file httpd. conf and virtual machine configuration file httpd-vhost.conf, there is no doubt we choose virtual machine configuration file, mainly to maintain more convenient. Then we insert the Directory Access control block into the virtual machine configuration file, so that our virtual host configuration file is written like this:
 
<VirtualHost *: 80>
 
DocumentRoot "E:/web"
ServerName www. domain. tld
<Directory "E:/web">
// Insert start
Options-Indexes FollowSymLinks
AllowOverride None
Order allow, deny
Allow from all
</Directory>
// Insert end </VirtualHost>
 
After the configuration is complete, we use the apachectl command and related parameters to check whether the configuration file is faulty. After confirmation, restart the apache service. Then use the browser to test the access (haha! It's nonsense again !). If not, check whether the permission settings of your page file are too high, resulting in access failure! Of course, this situation is rare in windows and may usually occur in linux.

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.