新聞中心
本實驗旨在CentOS7系統(tǒng)中,httpd-2.4配置兩臺虛擬主機,主要有以下要求:

10年積累的成都網(wǎng)站設計、成都做網(wǎng)站經(jīng)驗,可以快速應對客戶對網(wǎng)站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡服務。我雖然不認識你,你也不認識我。但先網(wǎng)站制作后付款的網(wǎng)站建設流程,更有柳林免費網(wǎng)站建設讓你可以放心的選擇與我們合作。
(1) 提供兩個基于名稱的虛擬主機:
www1.stuX.com,頁面文件目錄為/web/vhosts/www1;錯誤日志為/var/log/httpd/www1/error_log,訪問日志為/var/log/httpd/www1/access_log;
www2.stuX.com,頁面文件目錄為/web/vhosts/www2;錯誤日志為/var/log/httpd/www2/error_log,訪問日志為/var/log/httpd/www2/access_log;
(2) 通過www1.stuX.com/server-status輸出其狀態(tài)信息,且要求只允許提供賬號的用戶訪問;
(3) www1不允許192.168.1.0/24網(wǎng)絡中的主機訪問;
查看系統(tǒng)版本和httpd版本
[root@host ~]$httpd -v Server version: Apache/2.4.6 (CentOS) Server built: Nov 14 2016 18:04:44 [root@host ~]$cat /etc/centos-release CentOS Linux release 7.3.1611 (Core)
啟動httpd,測試能否正常運行
[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 表示正常運行
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 -DFOREGROUND
Jun 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.
使用curl命令訪問
[root@host ~]$ip a show ens38 # 查看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/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 # 訪問 CentOS 7.3
創(chuàng)建指定文件目錄
[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
根據(jù)要求填寫虛擬主機配置信息
# path /etc/httpd/conf.d/vir.conf # 配置文件全路徑 #virtual host 1 # 虛擬主機1的配置ErrorLog "/var/log/httpd/www1/error_log" CustomLog "/var/log/httpd/www1/access_log" combined # virtual host 2 # 虛擬主機2的配置SetHandler server-status Require all granted Require not ip 192.168.1 ServerName www2.stuX.com DocumentRoot "/web/vhosts/www2" ErrorLog "/var/log/httpd/www2/error_log" CustomLog "/var/log/httpd/www2/access_log" combined Require all granted
創(chuàng)建www1和www2的index頁面
[root@host conf.d]$cat /web/vhosts/www1/index.html welcome to www1 thank you [root@host conf.d]$cat /web/vhosts/www2/index.html welcome to www2 thank you
重載httpd配置文件
[root@host conf.d]$httpd -t Syntax OK [root@host conf.d]$systemctl reload httpd.service
修改客戶端主機的hosts文件,以便能解析域名
hosts在windows環(huán)境下的路徑為C:\Windows\System32\drivers\etc。在該文件中添加兩行
192.168.55.128 www1.stuX.com 192.168.55.128 www2.stuX.com
訪問結(jié)果
圖1 訪問www1站點
圖2 訪問www2站點
圖3 查看www1站點的訪問狀態(tài)——正常
圖4 查看www2站點的訪問狀態(tài)錯誤
網(wǎng)站名稱:CentOS7配置httpd虛擬主機
轉(zhuǎn)載來源:http://www.dlmjj.cn/article/djcodog.html


咨詢
建站咨詢
