The purpose of this experiment is to CentOS7 the system, httpd-2.4 configuration of two virtual hosts , the following requirements:
(1) Provide two name-based virtual hosts:
www1.stuX.com, the page file directory is/WEB/VHOSTS/WWW1; The error log is/var/log/httpd/www1/error_log, and the access log is/var/log/httpd/www1/access_log;
www2.stuX.com, the page file directory is/web/vhosts/www2; The error log is/var/log/httpd/www2/error_log, and the access log is/var/log/httpd/www2/access_log;
(2) Output its status information through Www1.stux.com/server-status, and require only the user to provide account access;
(3) WWW1 does not allow host access in the 192.168.1.0/24 network;
View system version and HTTPD version
[[Email protected] ~] $httpd-vServer version:apache/2.4. 6 (CentOS) Server built: - . : From:~] $cat/etc/centos-7.3. 1611
Start httpd and test to run properly
[[Email protected] ~] $systemctl start httpd.service [[email protected]~] $systemctl status Httpd.service httpd.service-The Apache HTTP Server loaded:loaded (/usr/lib/systemd/system/httpd.service; Vendor preset:disabled) Active:active (running) since Thu .- .- on Geneva:Geneva: ACST; 5s ago # active indicates normal operation DOCS:MAN:HTTPD (8) Man:apachectl (8) Process:6473Execstop=/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 on Geneva:Geneva: OneHost systemd[1]: Starting the Apache HTTP Server ... June on Geneva:Geneva: AHost systemd[1]: Started the Apache HTTP Server.
Using the Curl command to access
[[Email protected] ~] $ip a show ens38 # view IP3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU theQdisc Pfifo_fast State up Qlen +Link/etherxx: 0c: in:d C: -: 5f BRD ff:ff:ff:ff:ff:ff inet192.168.55.128/ -Brd192.168.55.255ScopeGlobal Dynamicens38 valid_lft 1752sec preferred_lft 1752sec inet6 fe80::20c:29ff:fedc:185f/ -scope link Valid_lft forever preferred_lft forever[[email protected]~] $curl http://192.168.55.128 # Access<! Doctype>CentOS7.3Create the specified file directory[[email protected] conf.d] $mkdir-pv/web/vhosts/www1[[email protected] conf.d] $mkdir-pv/web/vhosts/www2
[[email protected] CONF.D] $mkdir-pv/var/log/httpd/www2
[[email protected] CONF.D] $mkdir-PV/VAR/LOG/HTTPD/WWW1
Fill in the virtual host configuration information as required# path/etc/httpd/conf.d/vir.conf # config file full path #VirtualHost1 # Configuration of virtual Host 1<virtualhost192.168.55.128: the>errorlog"/var/log/httpd/www1/error_log"Customlog"/var/log/httpd/www1/access_log"combined<Location/server-status>SetHandler Server-Status</Location> <Directory/web/vhosts/www1> <RequireAll>Require All granted Require not IP192.168.1</RequireAll> </Directory></VirtualHost># VirtualHost2 # Configuration of Virtual Host 2<virtualhost192.168.55.128: the>ServerName www2.stuX.com DocumentRoot"/WEB/VHOSTS/WWW2"errorlog"/var/log/httpd/www2/error_log"Customlog"/var/log/httpd/www2/access_log"combined<Directory/web/vhosts/www2> <RequireAll>Require All granted</RequireAll> </Directory></VirtualHost>
Create index pages for WWW1 and WWW2[[email protected] conf.d] $cat/web/vhosts/www1/index.htmlwelcome to Www1thank You[[email protected] CONF.D] $cat /web/vhosts/www2/index.html Welcome to Www2thank
Overloading the httpd configuration file[[email protected] CONF.D] $HTTPD-
Modify the Hosts file of the client host so that the domain name can be resolvedThe path for the 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 results
Figure 1 Accessing the WWW1 site
Figure 2 Accessing the WWW2 site
Figure 3 Viewing the access status of the WWW1 site-Normal
Figure 4 Viewing the Access status error for the WWW2 site
CentOS7 Configuring HTTPD Virtual Hosts