Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CentOS7 configuration httpd Virtual Host tutorial

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The purpose of this lab is to configure two virtual hosts for httpd-2.4 in a CentOS7 system, with the following requirements:

(1) provide two name-based virtual hosts:

Www1.stuX.com, page file directory is / web/vhosts/www1; error log is / var/log/httpd/www1/error_log, access log is / var/log/httpd/www1/access_log

Www2.stuX.com, page file directory is / web/vhosts/www2; error log is / var/log/httpd/www2/error_log, access log is / var/log/httpd/www2/access_log

(2) output its status information through www1.stuX.com/server-status, and only users who provide account numbers are required to access it.

(3) www1 does not allow hosts in the 192.168.1.0 Universe 24 network to access.

View system version and httpd version

[root@host ~] $httpd-vServer version: Apache/2.4.6 (CentOS) Server built: Nov 14 2016 18:04:44 [root@host ~] $cat / etc/centos-releaseCentOS Linux release 7.3.1611 (Core)

Start httpd to test whether it can run properly

[root@host ~] $systemctl start httpd.service [root@host ~] $systemctl status httpd.service ● httpd.service-The Apache HTTP Server Loaded: loaded (/ usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2017-06-01 03:03:12 CST 5s ago # active indicates normal operation Docs: man:httpd (8) man:apachectl (8) Process: 6473 ExecStop=/bin/kill-WINCH ${MAINPID} (code=exited, status=0/SUCCESS) Main PID: 6485 (httpd) Status: "Processing requests..." CGroup: / system.slice/httpd.service ├─ 6485 / usr/sbin/httpd-DFOREGROUND ├─ 6486 / usr/sbin/httpd-DFOREGROUND ├─ 6487 / usr/sbin/httpd-DFOREGROUND ├─ 6489 / usr/sbin/httpd-DFOREGROUND ├─ 6490 / usr/sbin/httpd-DFOREGROUND └─ 6572 / usr/sbin/httpd-DFOREGROUNDJun 01 03:03:11 host systemd [1]: Starting The Apache HTTP Server...Jun 01 03:03 : 12 host systemd [1]: Started The Apache HTTP Server.

Access using the curl command

[root@host ~] $ip a show ens38 # View ip 3: ens38: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:dc:18:5f brd ff:ff:ff:ff:ff:ff inet 192.168.55.128 brd 24 brd 192.168.55.255 scope global dynamic ens38 valid_lft 1752sec preferred_lft 1752sec inet6 fe80::20c:29ff:fedc:185f/64 scope link valid_lft forever preferred_lft forever [root@host ~] $curl Http://192.168.55.128 # access CentOS 7.3

Create the specified file directory

[root@host conf.d] $mkdir-pv / web/vhosts/www1 [root@host conf.d] $mkdir-pv / web/vhosts/www2 [root@host conf.d] $mkdir-pv / var/log/httpd/www2 [root@host conf.d] $mkdir-pv / var/log/httpd/www1

Fill in the virtual host configuration information as required

# path / etc/httpd/conf.d/vir.conf # configuration file full path # virtual host 1 # configuration of virtual host 1 "/ var/log/httpd/www1/error_log" CustomLog "/ var/log/httpd/www1/access_log" combined SetHandler server-status Require all granted Require not ip 192.168.1 # virtual host 2 # configuration ServerName www2.stuX of virtual host 2 .com DocumentRoot "/ web/vhosts/www2" ErrorLog "/ var/log/httpd/www2/error_log" CustomLog "/ var/log/httpd/www2/access_log" combined Require all granted

Create index pages for www1 and www2

[root@host conf.d] $cat / web/vhosts/www1/index.htmlwelcome to www1thank you [root@host conf.d] $cat / web/vhosts/www2/index.html welcome to www2thank you

Reload httpd configuration file

[root@host conf.d] $httpd-tSyntax OK [root@host conf.d] $systemctl reload httpd.service

Modify the hosts file of the client host so that the domain name can be resolved

The path to hosts in the windows environment is C:\ Windows\ System32\ drivers\ etc. Add two lines to the file

192.168.55.128 www1.stuX.com

192.168.55.128 www2.stuX.com

Access result

Figure 1. Visit the www1 site

Figure 2. Visit the www2 site

Figure 3. Check the access status of the www1 site-- normal

Figure 4. Viewing the access status error of the www2 site

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report