一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

Linux|Centos|Ubuntu|系統(tǒng)進(jìn)程|Fedora|注冊(cè)表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服務(wù)器之家 - 服務(wù)器系統(tǒng) - Centos - CentOS7配置httpd虛擬主機(jī)教程

CentOS7配置httpd虛擬主機(jī)教程

2022-01-20 17:52Vathe Centos

這篇文章主要為大家詳細(xì)介紹了CentOS7配置httpd虛擬主機(jī)教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本實(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版本

?
1
2
3
4
5
[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,測(cè)試能否正常運(yùn)行

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[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命令訪問

?
1
2
3
4
5
6
7
8
9
10
11
12
[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)建指定文件目錄

?
1
2
3
4
[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ī)配置信息

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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頁面

?
1
2
3
4
5
6
[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配置文件

?
1
2
3
[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é)果

CentOS7配置httpd虛擬主機(jī)教程

圖1、訪問www1站點(diǎn)

CentOS7配置httpd虛擬主機(jī)教程

圖2、訪問www2站點(diǎn)

CentOS7配置httpd虛擬主機(jī)教程

圖3、查看www1站點(diǎn)的訪問狀態(tài)——正常

CentOS7配置httpd虛擬主機(jī)教程

圖4、查看www2站點(diǎn)的訪問狀態(tài)錯(cuò)誤

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

延伸 · 閱讀

精彩推薦
  • CentosCentOS 6.6實(shí)現(xiàn)永久修改DNS地址的方法

    CentOS 6.6實(shí)現(xiàn)永久修改DNS地址的方法

    這篇文章主要介紹了CentOS 6.6實(shí)現(xiàn)永久修改DNS地址的方法,涉及針對(duì)CentOS配置文件的相關(guān)設(shè)置技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下 ...

    Linux社區(qū)4472020-08-21
  • CentosCentOS7設(shè)置日期和時(shí)間方法以及基本概念介紹

    CentOS7設(shè)置日期和時(shí)間方法以及基本概念介紹

    這篇文章主要介紹了CentOS7設(shè)置日期和時(shí)間方法以及基本概念介紹,本文講解使用CentOS7中的新命令timedatectl設(shè)置日期時(shí)間方法,需要的朋友可以參考下 ...

    CentOS之家6522019-09-19
  • CentosCentOS下Uptime命令詳解

    CentOS下Uptime命令詳解

    在Linux下,我們可以使用uptime命令,而且此命令不必使用root權(quán)限。uptime命令在系統(tǒng)中已經(jīng)默認(rèn)安裝了。今天小編為大家?guī)淼氖荂entOS下Uptime命令詳解;希望...

    CentOS之家11482019-06-19
  • CentosCentos 7開啟網(wǎng)卡自動(dòng)獲取IP的詳細(xì)方法

    Centos 7開啟網(wǎng)卡自動(dòng)獲取IP的詳細(xì)方法

    本篇文章主要介紹了Centos 7開啟網(wǎng)卡自動(dòng)獲取IP的詳細(xì)方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧...

    凌鋒8972021-12-29
  • Centoscentos 安裝與操作方法

    centos 安裝與操作方法

    這篇文章主要介紹了centos 安裝與操作方法,需要的朋友可以參考下...

    centos之家5272019-07-11
  • CentosCentos7運(yùn)用/dev/shm進(jìn)行網(wǎng)站優(yōu)化

    Centos7運(yùn)用/dev/shm進(jìn)行網(wǎng)站優(yōu)化

    這篇文章主要介紹了LINUX中Centos7運(yùn)用/dev/shm進(jìn)行網(wǎng)站優(yōu)化相關(guān)知識(shí)點(diǎn),對(duì)此有興趣的朋友參考學(xué)習(xí)下。...

    彬菌9912022-03-02
  • Centoscentos不小心刪除/root目錄該如何解決?

    centos不小心刪除/root目錄該如何解決?

    一些朋友最近在問小編centos不小心刪除/root目錄該如何解決?今天小編就為大家分享centos不小心刪除/root目錄解決辦法;希望對(duì)大家會(huì)有幫助,有需要的朋友...

    腳本之家8022019-05-29
  • CentosCentOS6.5下Redis安裝與配置詳細(xì)步驟

    CentOS6.5下Redis安裝與配置詳細(xì)步驟

    本篇文章主要介紹了CentOS6.5下Redis安裝與配置詳細(xì)步驟,詳細(xì)介紹redis單機(jī)單實(shí)例安裝與配置,服務(wù)及開機(jī)自啟動(dòng)。有興趣的可以了解一下。...

    飛流11452021-12-24
主站蜘蛛池模板: 国产目拍亚洲精品一区二区三区 | 91精品国产高清久久久久久 | 人与动videos| 欧美人与日本人xx在线视频 | 疯狂激吻添下边小说 | 日韩欧美一区二区三区免费观看 | 国产亚洲欧美日韩综合综合二区 | 性做久久久久久久久老女人 | 99精品久久精品一区二区小说 | 91极品女神久色在线播放 | ckinese中国男同gay男男 | 日本私人影院 | 黄网国产 | 秋霞717理论片在线观看 | 我的好妈妈7中字在线观看韩国 | 大胸纲手被羞羞漫画网站 | 包射屋| 91精品国产91久久久久久麻豆 | acg火影忍者熟密姬纲手h | 波多野结衣之双方调教在线观看 | 美女张开大腿让男人桶 | 国产清纯白嫩大学生正在播放 | 麻豆最新| 国产99青草全福视在线 | 男女做污事 | 欧美z0z0人禽交 | 美女脱一净二净不带胸罩 | 男同精品视频免费观看网站 | 841995论坛网站2022年 | 亚洲福利一区二区三区 | 好男人资源免费播放 | 调教禽兽| b站免费网站入口 | 国产成人精品免费 | 亚洲AV 中文字幕 国产 欧美 | 日本护士handjob| 久久青草费线频观看国产 | 国产午夜亚洲精品一区网站 | 美女bbxx美女bbb | 手机在线免费观看高清 | 久9视频这里只有精品123 |