Apache Configuring multi-site Access "Assigning a two-level domain name to a project"

Source: Internet
Author: User
Tags domain name definition

A first-level domain name (baidu.com) is also called a top-level domain name, and registering a domain name requires a fee.

The level two domain name (image.baidu.com) is the extension of a domain name, so as long as the purchase of a domain name, level two domain name can be arbitrarily configured.

In fact (www.baidu.com) is also a two-level domain name, but everyone has been accustomed to use the WWW as the prefix of the two-level domain name as the site's main domain.

With DNS resolution providers, you can bind different host IPs for each level two domain name, so that you can set up multiple sites even if there is only one primary domain name.

If you have only one host, and you want to build multiple projects on it, and you have to access it through a subdomain, then you need to configure Apache.

=================== Configuring the local domain name =====================

If only as a local access, you only need to configure hosts and httpd.conf to

1. Add "127.0.0.1 custom domain name in the host file (C:\WINDOWS\SYSTEM32\DRIVERS\ETC)"

127.0. 0.1    Test.host.com

With the above steps, you can use test.host.com to access the local server. But only to do these meager jobs, the server will not know the difference between localhost and test.host.com. Therefore, it is also necessary to configure the virtual host for Apache to assign different processing paths for different domain name requests.

2. In the httpd.conf file (C:\wamp64\bin\apache\apache2.4.17\conf), add

Namevirtualhost *:<virtualhost test.host.com: >    "c:/users/ Administrator/desktop/test"    ServerName test.host.com    "c:/users/ Administrator/desktop/test">        Require local    

In this step you will need to modify the DocumentRoot (project path) and ServerName (custom domain name) to your own. Directory is a catalog that users can access, and the project path remains consistent. Note that the parameters in Directory Require Local, which means that only local access is allowed, and if you change it to Require all granted, then anyone can access the directory.

================== assigning site domain names =====================

If it is intended to be deployed in the actual project, then the situation will be relatively troublesome, but the idea is still all the two-level domain name requests to the same server processing, and then through the virtual host for different domain requests to assign different processing paths.

1. Assign subdomains to the primary domain by the cloud resolution provider, and then bind the host IP to the sub-domain name.

2. Modify the httpd.conf file to remove the comments in front of the Include conf/extra/httpd-vhosts.conf.

3. Note All the content in the httpd-vhosts.conf file (C:\wamp64\bin\apache\apache2.4.17\conf\extra), and then add

<directory/>    allowoverride all    Require all granted</Directory>*: <virtualhost *:>  serveradmin"admin Mailbox"  documentroot"project Root"  servername"level Two domain name"  serveralias"domain alias"  errorlog"error Log"  customlog"access log"</VirtualHost>

Directory tags are used to set access permissions for all directories

  AllowOverride all allows. htaccess to override the URL/allowoverride none to ignore. htaccess files

  Require all granted allow external access/Require all denied prohibit external access

Namevirtualhost is a fixed form for the VirtualHost tag to take effect

VirtualHost tags to bind a virtual host to a level two domain name

  Each two-level domain name corresponds to a VirtualHost tag, how many two-level domain names, how many VirtualHost tags are required

DocumentRoot and ServerName are required and the rest are optional

Note: Because the WWW domain name belongs to a special level two domain name, it also needs to be registered in the httpd-vhosts.conf file.

================== Precautions ======================

Two-level domain name definition rules

WWW: main entrance to the website (www.baidu.com)

Mail: Typically used to resolve mailbox servers (mail.baidu.com)

M: Domain name for mobile website (m.baidu.com)

Apache Access Control permissions

The 2.2 release allows all requests: the Order Allow,deny #排序, allow after deny allowed from all #允许所有

Version 2.4 allows all requests: Require all granted #允许所有

Restarting the server

After modifying the Apache configuration file, you must restart the server configuration to take effect

Apache Configuring multi-site Access "Assigning a two-level domain name to a project"

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.