一、I/O類型及與其相關概念:
1.1同步和異步:synchronous, asynchronous 【關注的是消息通知機制】
同步:調用發出不會立即返回,但一旦返回就可以返回最終結果;
異步:調用發出之後,被調用方立即返回消息,但返回的非最終結果;被調用者通過狀態、通知機制來通知調者,或通過回調函數來處理結果;
1.2阻塞和非阻塞:block, nonblock【關注的是調用等等調用結果(消息、返回值)時的狀態】
阻塞:調用結果返回之前,調用者(調用線程)會被掛起;調用者只有在得到結果之後纔會返回;
阻塞:調用結果返回之前,調用不會阻塞當前線程;
1.3五種I/O模型;
阻塞型IO [blocking IO]
非阻塞型IO [nonblocking IO]
複用型IO [IO multiplexing]【slect,poll複用器】pefork,worker
信號驅動型IO [signal driven IO]【epoll】 event
異步IO [asyncrhonous IO]
其工作流程如下:
可結合此博客圖文對比理解:http://www.xuebuyuan.com/1674303.html
1.4一個read操作:(1) 等待數據準備好;(2) 從內核向進程複製數據;
1.5 輪詢與觸發
(1)輪詢:用一個進程,但是使用非阻塞的I/O讀取數據,當一個I/O不可讀的時候立刻返回,檢查下一個是否可讀,這種形式的循環爲輪詢(polling),這種方法比較浪費CPU時間,因爲大多數時間是不可讀,但是仍花費時間不斷反覆執行read系統調用
(2)水平觸發:當條件滿足後會一直響應;信號驅動IO爲例;此處理解爲,當數據準備好後,內核會一直髮送消息通知進程,直到進程響應爲止
(3)邊緣觸發:當條件滿足的瞬間纔會響應;
1.5Select、Poll、Epoll
1.5.1 Select
(1)最大併發數限制,因爲一個進程所打開的 FD (文件描述符)是有限制的,由 FD_SETSIZE 設置,默認值是 1024/2048 ,因此 Select 模型的最大併發數就被相應限制了。文件描述符數FD_SETSIZE 此處無法更改
(2)效率問題,select 每次調用都會線性掃描全部的 FD 集合,這樣效率就會呈現線性下降,把 FD_SETSIZE 改大的後果就是,大家都慢慢來,什麼?都超時了。
(3)內核 / 用戶空間內存拷貝問題,如何讓內核把 FD 消息通知給用戶空間呢?在這個問題上select 採取了內存拷貝方法。
總結爲:1.連接數受限 2.查找配對速度慢 3.數據由內核拷貝到用戶態
1.5.2 Poll
基本上效率和 select 是相同的, select 缺點的 (2) 和 (3)它都沒有改掉。
1.5.3 Epoll
(1) Epoll 沒有最大併發連接的限制,上限是最大可以打開文件的數目,這個數字一般遠大於 2048, 一般來說這個數目和系統內存關係很大 ,具體數目可以 cat /proc/sys/fs/file-max 察看。
(2)效率提升,Epoll 最大的優點就在於它只管你“活躍”的連接 ,而跟連接總數無關,因此在實際的網絡環境中,Epoll 的效率就會遠遠高於 select 和 poll 。
(3)內存拷貝,Epoll 在這點上使用了“共享內存 ”,這個內存拷貝也省略了
更多資料請參考:http://blog.csdn.net/fanbird2008/article/details/16941217(模型內容來自此博客)
http://www.oschina.net/question/234345_40335
http://xingyunbaijunwei.blog.163.com/blog/static/76538067201241685556302/
http://blog.chinaunix.net/uid-24459558-id-2605975.html
1.6 prefork、worker、event
prefork:多進程模型,每個進程響應一個請求;穩定性好,但併發能力有限;預先生成多個空閒進程;select系統調用,最多1024個;
worker:多進程模型,每個進程可生成多個線程,每個線程響應一個請求;預先生成多個空閒線程;(select)
event:一個進程直接響應n個請求;可同時啓動多個進程
1.7 nginx支持的IO類型:
異步IO(aio)、信號驅動型(邊緣觸發)、內存映射、事件驅動 libevent:epoll
二、Nginx概念及特點簡介:
2.1 概念;
Nginx (讀作"engine X") 由IgorSysoev(俄羅斯)於2005年編寫,是一個免費、開源、高性能的HTTP服務器和反向代理,也可以作爲一個IMAP/POP3代理服務器。Nginx因爲穩定,豐富的功能集,配置簡單,資源佔用低而聞名世界。
2.2 Nginx的特性:
(1)模塊化設計、較好擴展性
(2)高可靠性:每個worker進程相對獨立,master進程在1個worker進程出錯時可以快速“拉起”新的worker子進程提供服務
(3)低內存消耗:10000個keep-alive連接在Nginx僅消耗2.5MB
(4)支持熱部署:master管理進程與worker工作進程的分離設計,使得Nginx能夠提供熱部署功能,即可以在7×24小時不間斷服務的前提下,升級Nginx的可執行文件。當然,它也支持不停止服務就更新配置項、更換日誌文件等功能。
2.3 基本功能:
(1)靜態資源的web服務器,能緩存打開的文件 描述符
(2)http, smtp, pop3協議的反向代理服務器,緩存、負載均衡;
(3)支持FastCGI (fpm)
(4)模塊化,非DSO機制,過濾器zip,SSI及圖像大小調整;
(5)支持SSL
2.4 擴展功能:
基於名稱和IP的虛擬主機訪問控制
支持keepalive
支持平滑升級
定製訪問日誌 ,支持使用日誌緩衝區提高日誌存儲性能
支持url rewrite(路徑重寫)
支持路徑別名
支持基於IP及用戶的訪問控制
支持速率限制,支持併發數限制
2.5 Nginx的基本架構:(非阻塞、事件驅動、一個master生成一個或多個worker, 每個worker響應n個請求)
一個master進程,生成一個或多個worker
事件驅動: epoll, kqueue,/dev/poll (event ports)
消息通知:select, poll, rtsignals
支持sendfile, sendfile64
支持AIO(異步IO)
支持mmap(內存映射)
2.6 模塊類型:
核心模塊:core modules
標準HTTP模塊:Standard HTTP modules
可選HTTP模塊:Optional HTTP modules
郵件模塊:Mail modules(作爲郵件反向代理服務器時用)
第三方模塊:3rd party modules
以上概念更多更詳細請參考:http://book.2cto.com/201304/19610.html
http://www.tuicool.com/articles/VV7nim6
三、安裝方法
3.1 RPM包安裝:http://nginx.org/en/linux_packages.html#stable
3.2 源碼安裝;
(1)下載源碼包
lftp ftp://172.16.0.1/pub/Sources/sources/nginx/nginx-1.6.2.tar.gz
mget http://nginx.org/en/download.html Stable version
(2)編譯環境準備
# yum groupinstall "Development Tools""Server Platform Development"
# yum install pcre-devel openssl-devel -y
(3)解壓安裝
# tar xf nginx-1.6.2.tar.gz
# cd nginx-1.6.2
# ./configure --prefix=/usr/local/nginx--conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx--error-log-path=/var/log/nginx/error.log--http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid--lock-path=/var/lock/nginx.lock --with-http_ssl_module--with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module--with-http_mp4_module --http-client-body-temp-path=/var/tmp/nginx/client--http-proxy-temp-path=/var/tmp/nginx/proxy--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi
# make && make install
# mkdir /var//tmp/nginx/{client,proxy,fastcgi} -pv
(4)啓動與關閉
# /usr/local/nginx/sbin/nginx -t #檢查語法
# /usr/local/nginx/sbin/nginx #啓動nginx,
# ss -tnlp #查看80端口,在瀏覽器上查看nginx成功啓動 [ps -elFH,查看nginx啓動的進程]
#killall nginx
(5)配置啓動服務腳本【腳本添加具體內容見附件Nginx服務啓動腳本】
# vim /etc/rc.d/init.d/nginx
# chmod +x /etc/rc.d/init.d/nginx
# chkconfig --add nginx
# chkconfig --list nginx
# service nginx restart
四、核心模塊相關配置文件(ngx_http_core_module);
4.1 語法着色【擴展插件】
(1)下載nginx.vim
wget http://www.vim.org/scripts/script.php?script_id=1886
lftp ftp://172.16.0.1/pub/Sources/sources/nginx/nginx.vim
(2)安裝nginx.vim
將nginx.vim放置於~/.vim/syntax/目錄,
# mkdir .vim/syntax/ -pv
# cp nginx.vim .vim/syntax/
(3)配置 nginx.vim
而後在~/.vim/filetype.vim中添加如下行:
au BufRead,BufNewFile/etc/nginx/*,/usr/local/nginx/conf/* if &ft == '' | setfiletype nginx |endif
其中“/etc/nginx”爲nginx配置文件的目錄
4.2核心配置段:Main 配置段
對應協議配置段:如http{...}
主體架構。如下圖所示
4.3 配置指令要以分號結尾,語法格式:
directivevalue1 [value2...];
4.4 支持使用變量:
模塊內置變量
自定義變量
setvar_name value
4.5 主配置段的指令的類別:
用於調試、定位問題
正常運行必備的配置
優化性能的配置
事件相關的配置
4.6 正常運行的必備配置:
(1) user USERNAME [GROUPNAME];
指定運行worker進程的用戶 和組,例如:user nginx nginx;s
(2)pid /path/to/pid_file;
指定nginx的pid文件;
(3) worker_rlimit_nofile #;
指定一個worker進程所能夠打開的最大文件句柄數(進程數);
(4)worker_rlimit_sigpending #;
指定每個用戶能夠發往worker的信號的數量;
4.7 優化性能相關的配置:
(1)worker_processes #:
worker線程的個數;通常應該爲物理CPU核心個數減1;
(2)worker_cpu_affinity cpumask ...;
綁定worker進程至指定的CPU上;
CPUMASK (假如有四顆cpu,表示法)
0001
0010
0100
1000
例如:worker_cpu_affinity 00000001 00000010 00000100;
(3)timer_resolution t;時間解析度:每隔多久更新一次緩存;在x86_64系統上不用配置
gettimeofday();
(4)worker_priority nice;範圍【-20, 19】
4.8 事件相關的配置:
(1)accept_mutex [on|off] 【做壓力測試時候用】
內部調用用戶 請求至各worker時用的負載均衡鎖;打開時表示能讓多個worker輪流地、序列化地與響應新請求;
(2)lock_file /path/to/lock_file; 鎖文件
(3)accept_mutex_delay #ms;
每個worker進程拿到互斥鎖可以相應請求,而此爲等待拿到互斥鎖的時間
(4)use [epoll|rgsig|select|poll];
定義使用的事件模型;建議讓Nginx自動選擇;
(5)worker_connections #;
每個worker進程所能夠響應的最大併發請求數;
4.9 用於調試、定位問題:
(1)daemon [off|on]
是否以守護進程方式啓動nginx;
(2)master_process on|off;
是否以master/worker模型來運行nginx;
(3)error_log /path/to/error_log level;
錯誤日誌文件及其級別;出於調試的目的,可以使用debug級別,但此級別只有在編譯nginx時使用了--with-debug選項纔有效;
更多詳細信息參考:http://nginx.org/en/docs/ngx_core_module.html
4.10 虛擬主機相關的配置:【虛擬機及其他練習及演示信息參照附件Nginx配置練習】
(1) 定義一個虛擬主機;寫在server {}配置段
(2)listen
監聽的端口
完整格式 :listenaddress[:port] [default_server] [ssl] [spdy] [proxy_protocol] [setfib=number][fastopen=number] [backlog=number] [rcvbuf=size] [sndbuf=size][accept_filter=filter] [deferred] [bind] [ipv6only=on|off][so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]];
常用格式:listenaddress[:port] [default_server] ssl
解析:
backlog=number:指明TCP協議backlog隊列的大小。默認爲-1,表示不設置;
rcvbuf=size:設定監聽句柄的SO_RCVBUF參數;【接收緩衝大小】
[sndbuf=size]【發送緩衝大小】
[bind] 【表示一個端口綁定監聽多個地址】
[ssl] 表示當前監聽的端口需要支持ssl功能
Sets the address and port for IP, or the path for a UNIX-domain socket on which the server will accept requests. Both address and port, or only address or only port can be specified. An address may also be a hostname, for example:
listen 127.0.0.1:8000;
listen 127.0.0.1;
listen 8000;
listen *:8000;
listen localhost:8000;
(3)server_name name [...];【服務器名稱或主機名】
後可跟多個主機名;名稱還可以使用通配符和正則表達式(~);如果被匹配到,則可以響應
匹配規則:
(a) 先做精確匹配;例如:www.magedu.com:
(b) 左側通配符匹配,例如:*.magedu.com;
(c) 右側通配符匹配,例如:www.*;
(d) 正則表達式匹配,例如: ~^.*\.magedu\.com$
(e)default_server;如果都沒有被匹配到,則顯示默認主機
(4) location【多個優先級相同,靠前的locationn匹配】
(a)[=|~|~*|^~] /uri {...}
功能:允許根據用戶請求的URI來匹配定義的各location,匹配到時,此請求將被相應的location塊中的配置所處理;
=: 精確匹配檢查;
~: 正則表達式模式匹配,區分字符大小寫;
~*:正則表達式模式 匹配,不區分字符大小寫;
^~:URI的前半部分匹配,不檢查正則表達式;
匹配優先級:精確匹配(=)、^~、~和~*、由不帶符號的URL進行左側匹配;
Let’sillustrate the above by an example:
location = / {
[ configuration A]
}
location / { #以/爲起始的所有路徑
[ configuration B]
}
location /documents/ {
[ configuration C]
}
location ^~ /images/ {
[ configuration D]
}
location ~* \.(gif|jpg|jpeg)$ {
[ configuration E]
}
The“/” request will match configuration A, the“/index.html” request will match configuration B, the“/documents/document.html”request will match configuration C, the“/images/1.gif” request will match configuration D, and the “/documents/1.jpg”request will match configuration E.
(b)location @name
前綴“@”定義了命名[指定]路徑。這種路徑不在一般的請求處理中使用,而是用在請求重定向中。這些路徑不能嵌套,也不能包含嵌套路徑。
(5)root
設置web資源路徑映射;用於指明請求的URL所對應的文檔的根目錄路徑;
location /images/ { #【locations中也可省略】
root "/web/imgs/"; #【images的訪問路徑爲/web/imgs/images;images目錄必須存在,index.html在images目錄下】
}
(6)alias path
用於location配置段,定義路徑別名
location /images/ {
alias /www/pictures/; #【images的訪問路徑爲/www/pictures/index.html】
}
注意:root表示指明路徑爲對應location的“ /” URL;alias表示路徑映射,即location中的URL是相對於alias所指明的路徑而言;
(7)index file 【默認主頁面】
indexindex.html;
放置位置:http,server,location 都可以,放在http,對所有server有效;放在server中,對所有location生效;放置location,則只對location有效
(8)error_page code [...] [=code]URI | @name【有名稱的location,反向代理時會用到】
根據http狀態碼重定向錯誤頁面
error_page 404 /404.html
=[code]: 以指定的響應碼進行響應;省略code表示以新資源的響應碼爲響應碼;
(9)try_files
try_filespath1[,path2,...] URI
用在location中,定義多個路徑,當用戶訪問一個路徑時;如果第一個path找不到第一個,找第二個,…,如果都找不到,則重定向至最後一個參數的URI-path(瞭解即可)
4.11 網絡連接相關的配置:
(1)keepalive_timeout time;
保持連接的超時時長,默認爲75s;
(2)keepalive_requests #;
在一次保持連接上允許承載最大資源請求數;
(3)keepalive_disable [msie6|safari|none]
爲指定類型的瀏覽器禁用長連接;
(4)tcp_nodelay on|off
對長連接是否使用TCP_NODELAY選項;【當客戶請求的資源少而小的時候,啓用,客戶體驗好】
(5)client_header_timeout time;
讀取http請求報文首部的超時時長;【對於較慢的網絡連接,不怎麼去響應】
(6)client_body_timeout time;
讀取http請求報文body部分的超時時長;【一般不會超時;對於上傳網速慢的不利,可能上傳不成功,所以建議設置時長稍長一點】
(7)send_timeout time;
發送響應報文的超時時長;
4.12 對客戶端請求進行限制:【通常用於http、server、location中】
(1)limit_except METHOD {...} 【在方法上做安全限制】
指定對範圍之外的其它方法的訪問控制;
limit_exceptGET { #【指定範圍之外的其他方法訪問控制】
allow172.16.0.0/16;
deny all;
} 【只允許172.16網段的主機使用除GET以外的其他方法請求】
2、client_body_max_size SIZE; 【對用戶上傳文件的限制】
限制請求報文中body部分的上限;通過檢測請求報文首部中的"Content_Length"來判定;
3、limit_rate speed;
限制客戶端每秒種傳輸的字節數,默認爲0,表示無限制;
4.13 對內存或磁盤資源進行分配【一般情況下,都不需要調整】
(1)client_body_in_file_only on|clean|off;
請求報文的body部分是否可暫存於磁盤【對於body較大者】;on表示允許,並且即使請求結束,也不會刪除暫存的內容;clean表示會刪除;off不允許暫存;
(2)client_body_in_single_buffer on|off
請求報文的body部分是否可暫存在內存【內核內存】的buffer中,默認off;允許會提高性能
(3)client_body_buffer_size size;
如果(2)爲on時,定義暫存空間大小
(4)client_body_temp_path DIR [level1 [level2[level3 [level4]]]]
如果(2)爲on時【Client_body的】暫存文件存儲路徑
例如:client_body_temp_path/var/tmp/nginx/client 1 2 【一級子目錄中,用2個字符定義路徑,如ab,ac,ad…】
(5)client_header_buffer_size size:
接收用戶請求報文的首部部分指定【分配】的內存空間的大小
4.14 MIME類型相關的配置:
1、types {}
定義MIME types至文件的擴展名;
例如:types {
text/html.html; 【如果本地加載的資源爲text/html類型的,都當作爲.html的子類型】
image/jpeg .jpg;
}
2、default_type MIME-TYPE;
指定默認MINE類型
4.15 文件操作優化相關的配置:
(1)sendfile on|off;
【由內核代爲完成系統調用;對於文件大小有限制,所以sendfile64可支持更大文件系統調用】【更詳細概念參考博客sendfile】
(2)aio on|off;
是否啓用內核級別的異步IO功能
(3)directio size|off; 【直接IO】
是否使用O_DIRECT選項去請求讀取文件;與sendfile功能互斥;【數據不經過內核,直接加載至磁盤,與sentfile互斥;一般關閉;開啓影響性能,但數據安全】
(4)open_file_cache max=N[inactive=time] |off;【是否打開緩存大小,在交互式模式下;】
nginx可以緩存以下三種信息:
(a) 文件句柄、文件大小和最近一次修改時間;
(b) 打開目錄的目錄結構;
(c) 沒有找到的或者沒有權限操作的文件的相關信息;
max=N表示可緩存的最大條目上限;一旦到達上限,則會使用LRU從緩存中刪除最近最少使用的條目;
inactive=time:在inactive指定的時長內沒有被訪問過的緩存條目就會淘汰【刪除】inactive 默認時間60s;;
如果內存空間足夠用,打開會提高nginx性能
(5)open_file_cache_errors on|off;
是否緩存在文件緩存中緩存打開文件時出現找不到路徑,沒有權限等的錯誤信息;
(6)open_file_cache_min_uses time;
每隔多久檢查一次緩存中緩存條目的有效性;默認60s;
重點關注:server{},location{}, listen, server_name, root, alias, keepalive_timeout,keepalive_requests, error_page
五、其他模塊相關配置【編譯時若默認沒有,想啓用,則編譯進nginx】
5.1 基於IP的訪問控制:【ngx_http_access_module】【編譯時默認有此模塊】
指令:Derectives:allow, deny
指令適用控制段:Context: http,server, location, limit_except
ExampleConfiguration
location / {
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/16;
deny all;
}
The rulesare checked in sequence until the first match is found. In this example, accessis allowed only for IPv4 networks 10.1.1.0/16 and 192.168.1.0/24 excluding the address 192.168.1.1
5.2基於用戶的basic認證配置: 【ngx_http_auth_basic_module】
ExampleConfiguration
location / {
auth_basic "closed site";【禁止訪問的區域】
auth_basic_user_file conf/htpasswd;【用戶賬號文件】
}
htpasswd命令創建用戶賬號文件;
5.3 基於gzip實現響應報文壓縮:【ngx_http_gzip_module】
The ngx_http_gzip_module module is a filter that compressesresponses using the “gzip” method. This often helps to reduce thesize of transmitted data by half or even more.
Directives:gzip,gzip_proxied,gzip_types,etc.
Context:http,server,locaion
ExampleConfiguration
gzip on; #功能開啓
gzip_min_length 1024; #起始壓縮爲1K
gzip_proxied expired no-cache no-store private auth; #對於私人認證信息不使用緩存壓縮
gzip_types text/plain application/xml; 對text/plainapplication/xml 類型文件壓縮
5.4 定製響應首部【ngx_http_headers_module】
The ngx_http_headers_module module allows adding the “Expires” and “Cache-Control” header fields, and arbitrary fields, to a response header.
Example Configuration
expires 24h; 定義respose headers 緩存有效期
expires modified +24h; 修改時間向後延長24h
expires @24h; 指定緩存有效期到當天幾點幾分
add_header Cache-Control private;
Syntax:add_header name value [always];
Default:—Context:http, server, location, if in location
5.5 定製訪問日誌
ExampleConfiguration
log_format compression '$remote_addr - $remote_user [$time_local] ' 【遠程/客戶端地址;遠程用戶;本地時間】
'"$request" $status $bytes_sent ' 【請求的URL及相關信息;狀態碼;發送字節】
'"$http_referer" "$http_user_agent" "$gzip_ratio"'; 【上一級的頁面是從哪裏跳轉過來的;瀏覽器類型;壓縮比】
access_log /spool/logs/nginx-access.log compression buffer=32k;
5.6 定義合法引用:【ngx_http_referer_module】【防盜鏈】
Context: server,location
Example Configuration
valid_referers none blocked server_names
*.example.com example.* www.example.org/galleries/
~\.google\.; 【以上定義的都爲合法引用】
if ($invalid_referer) {
return 403;
}
Parameters can be as follows:
None: ”the “Referer” field is missing in the request header;
Blocked:the “Referer” field is present in the request header, but its value has been deleted by a firewall or proxy server; such values are strings that do not start with “http://” or “https://”;
Server_names :the “Referer” request header field contains one of the server names;
5.7 URL rewrite:【ngx_http_rewrite_module】【網站某模塊遷移了;做鏡像站點;多個域名,但一個站點】
(1)Syntax:rewrite regex replacement [flag];
Context: server, location, if
Flag: last、break、redirect、permanent
Example:
server {
...
rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;
rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;
return 403;
...
}
解析:【以/download開頭的的,後面跟任意文件,中間有media,後面跟任意文件,以任意文件結尾;替換爲$1不變,還是download,之後跟把.*替換爲mp3;其他同理】
Rewrite更多標誌位信息:http://www.76ku.cn/articles/archives/317
(2)Syntax: if (condition) {...}
Context: server, location
比較表達式:
= :等值比較
!= :不等值比較
~ :模式匹配區分大小寫
~* :不區分大小寫
!~ :是否不匹配,不匹配爲真,匹配則爲假(不區分大小寫)
!~* :是否不匹配(區分大小寫)
-f, !-f :判斷文件是否存在與不存在
-d, !-d :判斷是否爲目錄與不爲目錄
-e, !-e :判斷文件、目錄、符號鏈接是否存在與不存在
-x, !-x :判斷文件是否能執行與不能執行
Examples
if ($invalid_referer) {
return 403;
}
(3)Syntax: return code [text];
return code URL ;
return URL
Context: server, location, if
(4)Syntax: set $variable value
Context: server, location, if
5.8 Status 【Sngx_http_stub_status_module】
The ngx_http_stub_status_module module provides access to basic statusinformation.
This moduleis not built by default, it should be enabled with the --with-http_stub_status_moduleconfigurationparameter.
ExampleConfiguration
location/basic_status {
stub_status;
}
Thisconfiguration creates a simple web page with basic status data which may looklike as follows:
Activeconnections: 291
serveraccepts handled requests
16630948 16630948 31070465
Reading:6 Writing: 179 Waiting: 106
5.9 SSL 【ngx_http_ssl_module】
Syntax:
ssl on | off;
ssl_certificate file;
ssl_certificate_key file;
ssl_ciphers ciphers;
ssl_session_cache off | none | [builtin[:size]] [shared:name:size];
ssl_prefer_server_ciphers on | off;
ssl_protocols [SSLv2] [SSLv3] [TLSv1][TLSv1.1] [TLSv1.2];
ssl_session_timeout time;
Context:http, server
ExampleConfiguration
To reducethe processor load it is recommended to
set thenumber of worker processes equal to the number of processors,
enablekeep-alive connections,
enable theshared session cache,
disable thebuilt-in session cache,
andpossibly increase the session lifetime (by default, 5 minutes):
worker_processesauto;
http {
...
server {
listen 443 ssl;
keepalive_timeout 70;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
ssl_certificate /usr/local/nginx/conf/cert.pem;
ssl_certificate_key/usr/local/nginx/conf/cert.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
...
}
更多資料請參考以下網站
Nginx英文官方網站:http://nginx.org/
Nginx中文官方網站:http://nginx.org/cn/
Nginx中文文檔http://nginx.com/doc/