1. 程式人生 > >Linux運維之道之ENGINEER1.2(HTTP服務基礎,網頁內容訪問,安全web)

Linux運維之道之ENGINEER1.2(HTTP服務基礎,網頁內容訪問,安全web)

達內 linux運維engineer

ENGINEER1.2

HTTP服務基礎

基於B/S架構的網頁服務

----服務端提供頁面;

----瀏覽器下載並顯示頁面;

----------------------------------------------------------------------------------------------------------------------------------------------

獨立wab主機的快速部署

  1. 安裝httpd

#yum -y install httpd

2啟動httpd服務,並設置開機自啟

#systemctl restart httpd

#systemctl enable httpd

3.書寫網頁:

#echo MY FIRST WEB > /var/www/htm/index.html

Desktop上:

#elinks -dump 172.25.0.11

------Servername:本站點註冊的DNS名稱

  1. vim /etc/httpd/conf/httpd.conf //修改主機配置文件

    vim 查找/ServerName

ServerName server0.example.com:80

2.重起httpd服務:

#systemctl restart httpd

Desktop上:

#elinks -dump server0.example.com

訪問web站點:

----Documentroot:網頁根目錄(/var/www/html)

服務端:/var/www/html/

  1. 修改主配文件的內容 #vim /etc/httpd/conf/httpd.conf

DocumentRoot “/var/www/abc”

2.創建目錄 #mkdir /var/www/abc

3.重起httpd服務 #systemctl restart httpd

4.書寫網頁文件

#echo wo shi abc > /var/www/abc/index.html

Desktop上

#elinks -dump server0.example.com

虛擬web主機

目的:省錢

由同一臺服務器提供多個不同的的web站點。

區分方式:

  1. 基於域名的虛擬機

  2. 基於端口的虛擬機

  3. 基於ip地址的虛擬機

幫助文檔: /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf

  1. 建立從配置文件

#vim /etc/httpd/conf.d/nsd01.conf

<VirtualHost * : 80>

DocumentRoot /var/www/test

ServerName www0.example.com

</VirtualHost>

<VirtualHost * : 80>

DocumentRoot /var/www/nsd

ServerName webapp0.example.com

</VirtualHost>

2.建立目錄及相應的網頁內容

#echo wo shi test > /var/www/test/index.html

#echo wo shi nsd > /var/www/nsd/index.html

3.重起httpd服務

#systemctl restart httpd

虛擬web,所有的站點都必須用虛擬地址

---------------------------------------------------------------------------------------------------------------------------

網頁訪問控制

配置目錄權限:

文件夾權限:

針對DocumentRoot網頁目錄的權限控制:

---httpd運行身份:apche

---能提取哪些網絡資源

#vim /etc/httpd/conf/httpd.conf

User Apche

Group Apache

客戶機地址限制:

使用<Directory>配置區段

---每個文件家自動繼承其父目錄的acl訪問權限

---除非針對子目錄有明確設置

禁止任何客戶機訪問

<Dirctory />

Require all denied

</Dirctory>

允許任何客戶機訪問

<Dirctory “/var/www/html”>

Require all granted

</Dirctory>

僅允許部分客戶機訪問

<Dirctory /var/www/html/private>

Require ip 127.0.0.1

</Dirctory>

--------------------------------------------------------------------------------------------------------------------------------------

SElinux策略保護

安全上下文(打上相同標簽)

#chcon -R --reference=/var/www /webroot

---------------------------------------------------------------------------------------------------------------------------------------

使用自定web訪問

  1. 修改配置文件

#vim /etc/httpd/conf.d/nsd01.conf

<VirtualHost *:80>

Document /webroot

ServerName server0.example.com

</VirtualHost>

2.創建目錄與網頁文件

#mkdir /webroot

#echo wo shi webroot >/webroot/index.html

3.修改訪問控制配置文件

#vim /etc/httpd/conf.d/nsd02.conf

<Directory "/webroot">

Require all granted

</Directory>

4.修改SElinux標簽值:

#chcon -R --reference=/var/www /webroot

5.重起httpd服務:

#systemctl restart httpd

6.在Desktop上:

#elinks -dumps server0.example.com




本文出自 “Linux運維之道” 博客,請務必保留此出處http://13401400.blog.51cto.com/13391400/1978949

Linux運維之道之ENGINEER1.2(HTTP服務基礎,網頁內容訪問,安全web)