Apache configuration virtual host based on name (name-based)

Source: Internet
Author: User
Tags fully qualified domain name

    • Based on name-based
    • Based on IP
    • Based on port
    • Combine

First, based on the name (name-based)

Need to configure hosts,httpd.conf

Lab Environment Requirements:

2 domains: www1.example.com www2.example.com

ip:192.168.136.140

PORT: 80

File directory. The structure under the/VAR/WWW directory is as follows.

tree. ├──cgi-bin├──html├──logs│├──www1││├──access_log││└──error_log│└──www2│└ ──error_log└──vhosts    ├──www1    │└──index.html    └──www2        └──index.html3 Files

The contents of index.html are as follows

cat /var/www/vhosts/www[]/*

Holle world!
Welcome to www1.example.com site.
Holle world!
Welcome to www2.example.com site.

# Edit local DNS   /etc/  hosts# Adding records for multi-domain names  192.168. 136.140   www1.example.com www2.example.com# Add Name-Based Virtual host block configuration   /etc/httpd/ conf/httpd.conf
# # Name-Based ####################################################<virtualhost *: the># This first-listed Virtual Host is also the default for*:80 The first virtual host is the default hostServerName www1.example.com serveralias example1.com documentroot"/VAR/WWW/VHOSTS/WWW1"</virtualhost><virtualhost *: the>ServerName www2.example.com #ServerAlias example2.com documentroot"/VAR/WWW/VHOSTS/WWW2"</VirtualHost>#################################################################### checking configuration syntax*: theis a namevirtualhost here can parse normally, syntax Ok[[email protected] vhosts]# httpd - SVirtualHost configuration:*: theIs a namevirtualhost default server www1.example.com (/etc/httpd/conf/httpd.conf: the) Port theNamevhost www1.example.com (/etc/httpd/conf/httpd.conf: the) alias Example1.com Port theNamevhost www2.example.com (/etc/httpd/conf/httpd.conf: the) ServerRoot:"/etc/httpd"Main DocumentRoot:"/var/www/html"Main errorlog:"/etc/httpd/logs/error_log"Mutex Proxy:using_defaultsmutex authn-Socache:using_defaultsmutex Default:dir="/run/httpd/"mechanism=default Mutex mpm-Accept:using_defaultsmutex authdigest-Opaque:using_defaultsmutex Proxy-balancer-Shm:using_defaultsmutex rewrite-Map:using_defaultsmutex authdigest-Client:using_defaultspidfile:"/run/httpd/httpd.pid"Define:DUMP_VHOSTSDefine:DUMP_RUN_CFGUser:name="Apache" ID= -Group:name="Apache" ID= -[[ Email protected] vhosts]# # restart httpdsystemctl restart httpd.servicesystemctl status Httpd.service[[ Email protected] vhosts]# systemctl status Httpd.service - lhttpd.service-The Apache HTTP Server loaded:loaded (/usr/lib/systemd/system/httpd.service; Vendor preset:disabled) Active:active (running) since Wed .- A- -  the: About: -CST; 26min ago Docs:Mans: httpd (8)           Mans: Apachectl (8) Process:5951execstop=/bin/Kill-winch ${mainpid} (code=exited, status=0/SUCCESS) Main PID:5957(httpd) Status:"Total requests:9; Current requests/sec:0; Current traffic:0 b/sec"Memory:4.1MCGroup:/system.slice/httpd.service├─5957/USR/SBIN/HTTPD-dforeground├─5958/USR/SBIN/HTTPD-dforeground├─5959/USR/SBIN/HTTPD-dforeground├─5960/USR/SBIN/HTTPD-dforeground├─5962/USR/SBIN/HTTPD-dforeground├─5975/USR/SBIN/HTTPD-dforeground├─5978/USR/SBIN/HTTPD-dforeground├─5979/USR/SBIN/HTTPD-dforeground├─5980/USR/SBIN/HTTPD-dforeground├─5981/USR/SBIN/HTTPD-dforeground└─6233/USR/SBIN/HTTPD-Dforegrounddec -  the: About: -Docker1 systemd[1]: Starting the Apache HTTP Server ... Dec -  the: About: -Docker1 httpd[5957]: AH00558:httpd:Could not reliably determine the server's fully qualified domain name, using 192.168.136.140. Set the'ServerName'directive globally to suppress this messageDec -  the: About: -Docker1 systemd[1]: Started the Apache HTTP Server. [[Email protected] vhosts]# # Verify access by domain name [[email protected] vhosts]# Curl  127.0. 0.1 

Holle world!
Welcome to www1.example.com site.

Curl www1.example.com

Holle world!
Welcome to www1.example.com site.

Curl www2.example.com

Holle world!
Welcome to www2.example.com site.

Now the hostname-based configuration is complete.

attached: http://httpd.apache.org/docs/2.4/vhosts/name-based.html

650) this.width=650; "title=" image_thumb[2] "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" image_thumb[2] "src=" http://s3.51cto.com/wyfs02/M01/8B/92/ Wkiom1hrfwvxjjjfaavqdmudxao854.png "width=" 1122 "height=" 663 "/>

Apache configuration virtual host based on name (name-based)

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.