Apache Configure virtual directories and multi-Host headers

Source: Internet
Author: User

Er, quite old topic, but the information on the internet is really too pit dad, helpless can only do a memo on their own ...
Here does not mention the virtual directory and host the difference between the head, do not know children's shoes to wall detention bar

Multiple virtual directories

First install Apache into the D:\Program files\apache2.2 directory, the port number is set to 8080, after the installation is complete the default Web site root directory is D:\Program Files\apache2.2\htdocs, Usually we can create a folder under Htdocs MySite, and then in the browser input: Http://localhost:8080/MySite So we can see our own site. However, sometimes we want to put the site under other directories, then we need to configure the virtual directory
For example, we set up the following folder in the D disk D:\Code\WebSite, and then through the Http://localhost:8080/DemoSite to access the site

Open the httpd.conf file, search for the <ifmodule alias_module> node, and enter the following within the node:

#下面是虚拟目录声明格式 #alias is used to define the virtual directory and the virtual directory path, where the virtual directory name is used for URL access to the path alias, can be different from the virtual directory name #<directory/> node is used to define the directory access rights, etc. # #Alias Virtual directory name virtual directory path #<directory virtual directory path >#   Options Indexes followsymlinks#   allowoverride all#   Order Allow, deny# allow   from all#</directory> #下面是具体的示例,/demosite is the directory alias "D:/code/website" is the actual path of the virtual directory Alias/demosite "d:/ Code/website "<directory" D:/code/website ">    Options Indexes followsymlinks    allowoverride    All Order Allow,deny allow from    all</directory>

After restarting the Apache service, the browser input http://localhost:8080/DemoSite will be able to access the normal
It is important to note that the directory should use "/" instead of "\" for the reason that "\" means that the escape character can lead to inexplicable errors in some cases, with the complete <ifmodule alias_module> node attached below for reference.

<ifmodule alias_module> # # Redirect:allows You-tell-clients about documents, used to # exist in Y Our servers ' s namespace, but does not anymore.    The client # would make a new request for the document at its new location. # Example: # Redirect Permanent/foo Http://localhost/bar # # Alias:maps Web paths into filesystem paths and is    Used to # Access content this does not live under the documentroot. # Example: # alias/webpath/full/filesystem/path # # IF you include a trailing/on/webpath and then the server wil  L # require it to is present in the URL.    You'll also likely # need to provide a <Directory> sections to allow access to # the filesystem path.     # # Scriptalias:this controls which directories contain server scripts. # scriptaliases is essentially the same as Aliases, except that # documents in the target directory is treated as app Lications and # Run by the server when requested rather than as doCuments sent to the # client.    The same rules about trailing '/' Apply to Scriptalias # directives as to Alias.  # scriptalias/cgi-bin/"D:/program files/apache2.2/cgi-bin/" Alias/demosite "D:/code/website" <Directory  "D:/code/website" > Options Indexes followsymlinks allowoverride all Order allow,deny allow From all </Directory></IfModule>

Multi-Host header bindings
(is to bind multiple domain names on one port, and then each domain name can point to a different directory for access, the host header is the word inside IIS), open the httpd.conf file, add the following at the end of the file

#多主机头配置无需放在特定的节点下面, generally directly at the bottom of the configuration file can be added #namevirtualhost addr[:p ort] to a domain-based virtual host to specify an IP address (and port) #声明主机头必须加这条指令, No person host header configuration does not take effect #virtualhost node below servername is the domain name to bind, DocumentRoot indicates that this domain name points to the directory # Native test, please do in the hosts domain binding such as 127.0.0.1  Www.mysite1.com
Namevirtualhost *:8080<virtualhost *:8080> ServerName www.mysite1.com documentroot "D:\Program files\ Apache2.2\htdocs "</virtualhost><virtualhost *:8080> ServerName www.mysite2.com documentroot" D:\Code\MySite "</VirtualHost>

After configuration, restart the Apache service, the browser input www.mysite1.com:8080, will be automatically directed to the D:\Program Files\apache2.2\htdocs site

The input www.mysite2.com:8080 is automatically directed to the D:\Code\MySite site, so you can run multiple sites concurrently on a single server

Apache Configure virtual directories and multi-Host headers

Related Article

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.