RHCE試題EX300詳解(十五)配置 web 內容訪問

題目要求:配置 web 內容訪問

在您 server0 上的 web 服務器的 DocumentRoot 目錄下創建一個名為 private 的目錄,要求:

  • l 從 http://classroom.example.com/content/permission.html 下載文件到這個目錄,
  • l 並重命名為 index.html,不要修改文件內容。
  • l 從 server0 上,任何人都可以瀏覽 private 的內容,但是從其他系統不能訪問這個目錄的內容

知識點小貼士:

Apache是Linux下的Web服務器,Apache用的是靜態頁面,需要加載模塊來支持動態頁面,會動態實時的調整進程來處理,最合理的使用多核CPU資源,支持虛擬主機應用,多個Web站點共享一個IP地址。

Apache和Selinux之間的關係,我們進入/var/www/html/目錄下,通過ll –Z查看目錄下index.html Selinux屬性,通過命令ps –auxZ|grep http查看httpd的進程,這些http進程都有httpd_t的Selinux上下文屬性,Selinux就規定了http_t這類的進程上下文屬性可以訪問httpd_sys_content_t這類文件的上下文屬性,從而保證了網站的內容可以被訪問。

解題步驟:

(1)創建目錄:

<code>[root@server0 ~]# mkdir /var/www/{html,virtual}/private/<code>

(2)下載文件到指定的目錄:

<code>[root@server0 ~]# wget -O /var/www/html/private/index.html http://classroom.example.com/content/permission.html
--2020-03-26 08:25:25--  http://classroom.example.com/content/permission.html

Resolving classroom.example.com (classroom.example.com)... 172.25.254.254
Connecting to classroom.example.com (classroom.example.com)|172.25.254.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9 [text/html]
Saving to: ‘/var/www/html/private/index.html’
100%[=====================>] 9           --.-K/s   in 0s     
2020-03-26 08:25:25 (842 KB/s) - ‘/var/www/html/private/index.html’ saved [9/9]/<code>
<code> [root@server0 ~]# wget -O /var/www/virtual/private/index.html http://classroom.example.com/content/permission.html
--2020-03-26 08:25:46--  http://classroom.example.com/content/permission.html
Resolving classroom.example.com (classroom.example.com)... 172.25.254.254
Connecting to classroom.example.com (classroom.example.com)|172.25.254.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9 [text/html]
Saving to: ‘/var/www/virtual/private/index.html’
100%[=====================>] 9           --.-K/s   in 0s     
2020-03-26 08:25:46 (766 KB/s) - ‘/var/www/virtual/private/index.html’ saved [9/9]/<code>

(3)新建一個配置文件:

<code>[root@server0 ~]# vim /etc/httpd/conf
conf/           conf.d/         conf.modules.d/
[root@server0 ~]# vim /etc/httpd/conf
conf/           conf.d/         conf.modules.d/
[root@server0 ~]# vim /etc/httpd/conf.d/
autoindex.conf         vhos-server0-ssl.conf
README                 vhost-server0.conf
ssl.conf               webapp0.conf
userdir.conf           welcome.conf/<code>
<code>[root@server0 ~]# vim /etc/httpd/conf.d/server0-private.conf/<code>


RHCE試題EX300詳解(十五)配置 web 內容訪問


註釋:在配置文件中輸入以下內容

<code><directory>
   Require host server0.example.com
/<directory>
<directory>
   Require host server0.example.com
/<directory>/<code>

(4)重啟httpd服務:

<code>[root@server0 ~]# systemctl restart httpd.service/<code>

(5)在Server0上驗證:

<code>[root@server0 ~]# firefox http://www0.example.com/private/<code>


RHCE試題EX300詳解(十五)配置 web 內容訪問


<code>[root@server0 ~]# firefox http://webapp0.example.com/private/<code>


RHCE試題EX300詳解(十五)配置 web 內容訪問


(6)在desktop0上驗證:

<code>[root@desktop0 ~]# firefox http://www0.example.com/private/<code>


RHCE試題EX300詳解(十五)配置 web 內容訪問


<code>[root@desktop0 ~]# firefox http://webapp0.example.com/private/<code>


RHCE試題EX300詳解(十五)配置 web 內容訪問


分享到:


相關文章: