CentOS7配置httpd虛擬主機(jī)教程
本實(shí)驗(yàn)旨在CentOS7系統(tǒng)中,httpd-2.4配置兩臺(tái)虛擬主機(jī),主要有以下要求:
(1) 提供兩個(gè)基于名稱的虛擬主機(jī):
www1.stuX.com,頁面文件目錄為/web/vhosts/www1;錯(cuò)誤日志為/var/log/httpd/www1/error_log,訪問日志為/var/log/httpd/www1/access_log;
www2.stuX.com,頁面文件目錄為/web/vhosts/www2;錯(cuò)誤日志為/var/log/httpd/www2/error_log,訪問日志為/var/log/httpd/www2/access_log;
(2) 通過www1.stuX.com/server-status輸出其狀態(tài)信息,且要求只允許提供賬號(hào)的用戶訪問;
(3) www1不允許192.168.1.0/24網(wǎng)絡(luò)中的主機(jī)訪問;
查看系統(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)
啟動(dòng)httpd,測試能否正常運(yùn)行
[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 表示正常運(yùn)行 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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 # 訪問 <!DOCTYPE> <h1> CentOS 7.3 </h1>
創(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ù)要求填寫虛擬主機(jī)配置信息
# path /etc/httpd/conf.d/vir.conf # 配置文件全路徑 #virtual host 1 # 虛擬主機(jī)1的配置 <VirtualHost 192.168.55.128:80> 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 ip 192.168.1 </RequireAll> </Directory> </VirtualHost> # virtual host 2 # 虛擬主機(jī)2的配置 <VirtualHost 192.168.55.128:80> 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>
創(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
修改客戶端主機(jī)的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站點(diǎn)
圖2、訪問www2站點(diǎn)
圖3、查看www1站點(diǎn)的訪問狀態(tài)——正常
圖4、查看www2站點(diǎn)的訪問狀態(tài)錯(cuò)誤
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
linux下使用Apache+php實(shí)現(xiàn)留言板功能的網(wǎng)站
在linux下使用apache+php實(shí)現(xiàn)留言板功能的網(wǎng)站,首先需要我們的linux服務(wù)器上安裝apache和php,然后結(jié)合其他操作實(shí)現(xiàn)此功能,下文小編給大家介紹的非常詳細(xì),感興趣的朋友一起學(xué)習(xí)吧2016-10-10Linux上查看用戶創(chuàng)建日期的幾種方法總結(jié)
在Linux系統(tǒng)中,如何找到用戶創(chuàng)建的時(shí)間呢?下面這篇文章就來給大家介紹了關(guān)于在Linux上如何查看用戶創(chuàng)建日期的幾種方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05linux查看文件系統(tǒng)塊大小與內(nèi)存頁大小的簡單方法
下面小編就為大家?guī)硪黄猯inux查看文件系統(tǒng)塊大小與內(nèi)存頁大小的簡單方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11Linux啟動(dòng)與停止spring boot工程的腳本示例
這篇文章主要給大家介紹了關(guān)于Linux啟動(dòng)與停止spring boot工程的腳本的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09詳解如何實(shí)現(xiàn)Linux服務(wù)Crash后自動(dòng)重啟
近期碰到了一個(gè)?Linux?Systemd?服務(wù)?Crash,?Crash?后需要人工介入重啟.?那么,?有沒有辦法如何實(shí)現(xiàn)?Linux?服務(wù)?Crash?后自動(dòng)重啟,下面就來和大家分享一下2023-08-08