基于B/S架構,其實是C/S架構的衍生版本。
服務端提供網頁
浏覽器下載下傳并顯示網頁
端口号:80/tcp
Hyper Text Markup Language(HTML) 超文本标記語言
Hyper Text Transfer Protocol(HTTP) 超文本傳輸協定
服務端:httpd、nginx、tomcat
用戶端:elinks、firefox、IE、chrome
prefork模式使用多個子程序,每個子程序隻有一個線程。每個程序在某個确定的時間隻能維持一個連接配接。在大多數平台上,Prefork MPM在效率上要比Worker MPM要高,但是記憶體使用大得多。prefork的無線程設計在某些情況下将比worker更有優勢:它可以使用那些沒有處理好線程安全的第三方子產品,并且對于那些線程調試困難的平台而言,它也更容易調試一些。
worker模式使用多個子程序,每個子程序有多個線程。每個線程在某個确定的時間隻能維持一個連接配接。通常來說,在一個高流量的HTTP伺服器上,Worker MPM是個比較好的選擇,因為Worker MPM的記憶體使用比Prefork MPM要低得多。但worker MPM也有不完善的地方,如果一個線程崩潰,整個程序就會連同其所有線程一起"死掉".由于線程共享記憶體空間,是以一個程式在運作時必須被系統識别為"每個線程都是安全的"。
httpd的全局主配置檔案
42行,Listen ip:port #監聽ip位址和端口号
95行,ServerName #設定伺服器的域名
119行,DocumentRoot #設定網站的根目錄
檢查主配置檔案的文法是否有錯誤
由同一台伺服器提供多個不同的web站點
那麼一台伺服器如何區分不同的站點呢?有三種方式
基于域名(必須掌握)
基于端口(了解)
基于IP位址(不用)
由全局主配置檔案來定義,一般存放自定義配置檔案。
具體在第353行
<VirtualHost *:@@Port@@>
ServerAdmin [email protected]
DocumentRoot "@@ServerRoot@@/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost>
httpd的虛拟主機格式幫助檔案
一旦啟用了虛拟web主機以後,外部的DocumentRoot、ServerName會被忽略。虛拟web主機配置檔案中第一個虛拟站點被視為預設站點,如果用戶端通路的URL不屬于任何虛拟主機,則用預設站點回應。是以,之前在主配置檔案裡面定義的ServerName必須在虛拟web主機配置檔案裡面增加一個虛拟主機,否則将無法通路
主配置檔案定義了/禁止所有人通路;同時又定義了隻有/var/www全部允許通路。這樣的結果就是隻有/var/www目錄才能給所有人通路,/下的其他目錄都不能通路
僅允許本機通路,禁止其他系統通路
<Directory "/var/www/abc/private">
Require ip 172.25.0.11 127.0.0.1
</Directory>
允許通路/webroot目錄
<Directory "/webroot">
Require all granted
允許所有人通路,但禁止172.34.0.0/24通路
<Directory "/var/www/html/doc">
Require not ip 172.34.0.0/24
首先防火牆是否限制
其次服務本身的通路控制
再次看SELinux是否限制
SELinux使用安全上下文(security context)的方式對系統的所有檔案進行管理
SELinux限制了httpd隻允許通路下面的檔案,為他們打上了httpd的标簽:
/etc/httpd/conf/httpd.conf
/etc/http/conf.d/*.conf
/etc/www
檢視SELinux标簽
ls -Zd /var/www
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www
以/var/www為模闆,把/webroot的SELinux标簽修改為和/var/www一樣,而且是遞歸修改
PKI(Public Key Infrastructure)
公鑰
私鑰
證書
證書頒發機構
通過PKI體系,使用公私鑰提供加密,可以確定消息的的私有性和完整性
端口443/tcp
HTTPS(Security Hyper Text Transfer Protocol) 安全超文本傳輸協定
SSL(Secure Socket Layer) 安全套接字層
TLS(Transport Layer Security) 安全傳輸層協定
安裝TLS協定支援,安裝之後會增加一個檔案/etc/httpd/conf.d/ssl.conf
部署根證書、網站的證書到/etc/pki/tls/cert下
部署私鑰到/etc/pki/tls/private下
59行,把DocumentRoot改為/webroot
60行,把ServerName改為server0.example.com:443
100行,修改證書檔案名為server0.cert
107行,修改密鑰檔案名為server0.key
122行,修改CA憑證檔案名為example-ca.cert
安裝支援python引擎的軟體包
WSGI功能的介紹文檔
下載下傳動态網站,内容如下:
#!/usr/bin/env python
import time
def application (environ, start_response):
response_body = 'UNIX EPOCH time is now: %s\n' % time.time()
status = '200 OK'
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', '1'),
('Content-Length', str(len(response_body)))]
start_response(status, response_headers)
return [response_body]
Listen 8909
<VirtualHost *:8909>
DocumentRoot /var/www/nsd
ServerName webapp0.example.com
wsgiscriptAlias / /var/www/nsd/webinfo.wsgi #讓浏覽器找wsgi去翻譯網頁
httpd服務重新開機失敗,檢視詳細日志。
Nov 03 17:23:40 localhost.localdomain python[4200]: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket .
* Plugin bind_ports (92.2 confidence) suggests ****
If you want to allow /usr/sbin/httpd to bind to network port 8909
Then you need to modify the port type.
Do
#semanage port -a -t PORT_TYPE -p tcp 8909
where PORT_TYPE is one of the following: http_cache_port_t, http_port_t, jboss_management_port_t, jboss_messaging_port_t, ntop_po
* Plugin catchall_boolean (7.83 confidence) suggests **
If you want to allow nis to enabled
Then you must tell SELinux about this by enabling the 'nis_enabled' boolean.
setsebool -P nis_enabled 1
* Plugin catchall (1.41 confidence) suggests **
If you believe that httpd should be allowed name_bind access on the tcp_socket by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
allow this access for now by executing:
#grep httpd /var/log/audit/audit.log | audit2allow -M mypol
#semodule -i mypol.pp
又是SELinux搞的鬼!
檢視SELinux允許http的哪些端口
設定SELinux添加允許http使用8909端口,耗費資源比較大
本文轉自 goldwinner 51CTO部落格,原文連結:http://blog.51cto.com/355665/2068711,如需轉載請自行聯系原作者