Apache Configuration Virtual host 2--based on IP

Source: Internet
Author: User
Tags web hosting

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

Second, IP-based

Configure Hosts,httpd.conf,eno

1, assume that the server has an IP of, use Ifconfig to bind an additional 2 IPs on the same network interface eno16777736 (or eth0), or with Nmtui configuration. Ping detection is possible.

ifconfig eno16777736:192.168. 136.143
ifconfig eno16777736:192.168. 136.144
2, modify the/etc/hosts file, add one by one corresponding domain name
# ip-based
192.168. 136.143     www3.example.com
1921.68. 136.144    Www4.example.com

3. Establish the root directory of the web hosting of the virtual host

#/var/tree├──cgi-bin├──html├──logs│├──www1││├──access_log││└──error_log│├─ ─www2││├──access_log││└──error_log│├──www3││├──access_log││└──error_log│└──www4│├─ ─access_log│└──error_log└──vhosts    ├──www1    │└──index.html    ├──www2    │└──index.html    ├──ww W3    │└──index.html    └──www4        └──index.html

Index.html content is as follows

Cat index.html. /www4/index.html HolleWorld!  www3.example.comIP  -  Based. HolleWorld!  www4.example.comIP  -based.

4. Include additional profile httpd-vhosts.conf in httpd.conf, then modify httpd-vhosts.conf configuration

# ip-based
<virtualhost192.168.136.143: the>ServerAdmin [email protected] ServerName www3.example.com documentroot"/VAR/WWW/VHOSTS/WWW3"errorlog"/Var/www/logs/www1/error_log"Customlog"/Var/www/logs/www1/access_log"combined</virtualhost><virtualhost192.168.136.144: the>ServerAdmin [email protected] ServerName www4.example.com documentroot"/Var/www/vhosts/www4"errorlog"/Var/www/logs/www4/error_log"Customlog"/Var/www/logs/www4/access_log"combined</VirtualHost>

5, configuration grammar check httpd-s, you can see name-based and ip-based coexist.

[Email protected] www]#httpd- SVirtualHost configuration: theWww3.example.com (/etc/httpd/conf/httpd.conf:98) theWww4.example.com (/etc/httpd/conf/httpd.conf:106)*: 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 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_defaultsmutex proxy:using_defaultspidfile:"/run/httpd/httpd.pid"Define:DUMP_VHOSTSDefine:DUMP_RUN_CFGUser:name="Apache" ID= -Group:name="Apache" ID= -

6, restart the service systemctl restart Httpd.service, and then visit 4 sites.

 [[email protected "www]#  Curl www1.example.com www2.example.com www3.example.com www4.example.com  Holle World ! welcome to www1.example.com site with Name - Based.holle World ! welcome to www2.example.com site with Name - Based.holle World ! welcom to www3.example.com site with IP - Based.holle World ! welcom to www4.example.com site with IP -based. 
 # access via IP or domain name 3,4  [[email protected] www ]#  Curl www3.example.com    192.168 . 136.143 : 80  www4.example.com 192.168 . 136.144 : 80   holle World ! welcom to www3.example.com site with IP - Based.holle World ! welcom to www3.example.com site with IP - Based.holle World ! welcom to www4.example.com site with IP - Based.holle World ! welcom to www4.example.com site with IP -based. 

The ip-based configuration has been completed.

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

650) this.width=650; "title=" image "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 "src=" http://s3.51cto.com/wyfs02/M00/8B/92/wKiom1hRFtjgaraUAAJZgR_ 1e9s225.png "width=" 1591 "height=" 924 "/>

Issue: How users are configured and managed.

Apache Configuration Virtual host 2--based on IP

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.