您好,登錄后才能下訂單哦!
與套接字相關(guān)的配置
(1)server { ... }
配置一個(gè)虛擬主機(jī);
server {
listen address[:PORT]|PORT;
server_name SERVER_NAME;
root /PATH/TO/DOCUMENT_ROOT;
}
(2)listen PORT|address[:port]|unix:/PATH/TO/SOCKET_FILE
listen address[:port] [default_server] [ssl] [http2 | spdy] [backlog=number] [rcvbuf=size] [sndbuf=size]
default_server:設(shè)定為默認(rèn)虛擬主機(jī);
ssl:限制僅能夠通過(guò)ssl連接提供服務(wù);
backlog=number:后援隊(duì)列長(zhǎng)度;
rcvbuf=size:接收緩沖區(qū)大?。? sndbuf=size:發(fā)送緩沖區(qū)大小
(3)server_name name ...;
指明虛擬主機(jī)的主機(jī)名稱(chēng);后可跟多個(gè)由空白字符分隔的字符串;
支持*通配任意長(zhǎng)度的任意字符;server_name *.magedu.com www.magedu.*
支持~起始的字符做正則表達(dá)式模式匹配;server_name ~^www\d+\.magedu\.com$
匹配機(jī)制:
(a) 首先是字符串精確匹配;
(b) 左側(cè)*通配符;
(c) 右側(cè)*通配符;
(d) 正則表達(dá)式;
(4)tcp_nodelay on | off;
在keepalived模式下的連接是否啟用TCP_NODELAY選項(xiàng);表示在長(zhǎng)連接模式下一個(gè)個(gè)發(fā)包,不打包一起發(fā)
tcp_nopush on|off;
在sendfile模式下,是否啟用TCP_CORK選項(xiàng);表示等于用戶空間把http首部送過(guò)來(lái)一起發(fā)
(5)sendfile on | off;
是否啟用sendfile功能;表示把響應(yīng)報(bào)文首部和文件開(kāi)頭放在一個(gè)報(bào)文發(fā)送,在一個(gè)報(bào)文發(fā)送文件
2.定義路徑相關(guān)的配置:
(1)root path;
設(shè)置web資源路徑映射;用于指明用戶請(qǐng)求的url所對(duì)應(yīng)的本地文件系統(tǒng)上的文檔所在目錄路徑;可用的位置:http, server, location, if in location;
(2)location [ = | ~ | ~* | ^~ ] uri { ... }
在一個(gè)server中l(wèi)ocation配置段可存在多個(gè),用于實(shí)現(xiàn)從uri到文件系統(tǒng)的路徑映射;ngnix會(huì)根據(jù)用戶請(qǐng)求的URI來(lái)檢查定義的所有l(wèi)ocation,并找出一個(gè)最佳匹配,而后應(yīng)用其配置;
=:對(duì)URI做精確匹配;
location = / {
...
}
~:對(duì)URI做正則表達(dá)式模式匹配,區(qū)分字符大小寫(xiě);
~*:對(duì)URI做正則表達(dá)式模式匹配,不區(qū)分字符大小寫(xiě);
^~:對(duì)URI的左半部分做匹配檢查,不區(qū)分字符大小寫(xiě);
不帶符號(hào):匹配起始于此uri的所有的url;
匹配優(yōu)先級(jí):=, ^~, ~/~*,不帶符號(hào);
root /vhosts/www/htdocs/
http://www.www.com/index.html --> /vhosts/www/htdocs/index.html
server {
root /vhosts/www/htdocs/
location /admin/ {
root /webapps/app1/data/
}
}
(3)、alias path;
定義路徑別名,文檔映射的另一種機(jī)制;僅能用于location上下文;
注意:location中使用root指令和alias指令的意義不同;
(a) root,給定的路徑對(duì)應(yīng)于location中的/uri/左側(cè)的/;
(b) alias,給定的路徑對(duì)應(yīng)于location中的/uri/右側(cè)的/
(4)index file ...;
默認(rèn)資源;http, server, location;
(5)error_page code ... [=[response]] uri;
Defines the URI that will be shown for the specified errors.
3.定義客戶端請(qǐng)求的相關(guān)配置:
(1)keepalive_timeout timeout [header_timeout];(負(fù)載均衡短,后端服務(wù)器長(zhǎng))
設(shè)定保持連接的超時(shí)時(shí)長(zhǎng),0表示禁止長(zhǎng)連接;默認(rèn)為75s;
(2)keepalive_requests number;
在一次長(zhǎng)連接上所允許請(qǐng)求的資源的最大數(shù)量,默認(rèn)為100;
(3)、keepalive_disable none | browser ...;
對(duì)哪種瀏覽器禁用長(zhǎng)連接;
(4)send_timeout time;
向客戶端發(fā)送響應(yīng)報(bào)文的超時(shí)時(shí)長(zhǎng),此處,是指兩次寫(xiě)操作之間的間隔時(shí)長(zhǎng);
(5)client_body_buffer_size size;(post上傳大文件時(shí))
用于接收客戶端請(qǐng)求報(bào)文的body部分的緩沖區(qū)大??;默認(rèn)為16k;超出此大小時(shí),其將被暫存到磁盤(pán)上的由 client_body_temp_path指令所定義的位置;
(6)client_body_temp_path path [level1 [level2 [level3]]];
設(shè)定用于存儲(chǔ)客戶端請(qǐng)求報(bào)文的body部分的臨時(shí)存儲(chǔ)路徑及子目錄結(jié)構(gòu)和數(shù)量;
4.對(duì)客戶端進(jìn)行限制的相關(guān)配置:
(1)limit_rate rate;
限制響應(yīng)給客戶端的傳輸速率,單位是bytes/second,0表示無(wú)限制;
(2)limit_except method ... { ... }
限制對(duì)指定的請(qǐng)求方法之外的其它方法的使用客戶端;
limit_except GET {
allow 192.168.1.0/24;
deny all;
}
5.文件操作優(yōu)化的配置:
(1)aio on | off | threads[=pool];
是否啟用aio功能;
(2)directio size | off;
在Linux主機(jī)啟用O_DIRECT標(biāo)記,此處意味文件大于等于給定的大小時(shí)使用,例如directio 4m;
(3)open_file_cache off;(緩存元數(shù)據(jù))
open_file_cache max=N [inactive=time];
nginx可以緩存以下三種信息:
(a) 文件的描述符、文件大小和最近一次的修改時(shí)間;
(b) 打開(kāi)的目錄結(jié)構(gòu);
(c) 沒(méi)有找到的或者沒(méi)有權(quán)限訪問(wèn)的文件的相關(guān)信息;
max=N:可緩存的緩存項(xiàng)上限;達(dá)到上限后會(huì)使用LRU算法(最近最少使用)實(shí)現(xiàn)緩存管理;
inactive=time:緩存項(xiàng)的非活動(dòng)時(shí)長(zhǎng),在此處指定的時(shí)長(zhǎng)內(nèi)未被命中的或命中的次數(shù)少于open_file_cache_min_uses指令所指定的次數(shù)的緩存項(xiàng)即為非活動(dòng)項(xiàng);
(4)open_file_cache_valid time;
緩存項(xiàng)有效性的檢查頻率;默認(rèn)為60s;
(5)open_file_cache_min_uses number;
在open_file_cache指令的inactive參數(shù)指定的時(shí)長(zhǎng)內(nèi),至少應(yīng)該被命中多少次方可被歸類(lèi)為活動(dòng)項(xiàng);
(6)open_file_cache_errors on | off;
是否緩存查找時(shí)發(fā)生錯(cuò)誤的文件一類(lèi)的信息;
6.ngx_http_access_module模塊:
實(shí)現(xiàn)基于ip的訪問(wèn)控制功能
(1)allow address | CIDR | unix: | all;
(2)deny address | CIDR | unix: | all;
7.ngx_http_auth_basic_module模塊:
(1)auth_basic string | off;
(2)auth_basic_user_file file;
location /admin/ {
alias /webapps/app1/data/;
auth_basic "Admin Area";
auth_basic_user_file /etc/nginx/.ngxpasswd;
}
注意:htpasswd命令由httpd-tools所提供;
8.ngx_http_stub_status_module模塊:
用于輸出nginx的基本狀態(tài)信息;
Active connections: 291
server accepts handled requests
16630948 16630948 31070465
Reading: 6 Writing: 179 Waiting: 106
Active connections: 活動(dòng)狀態(tài)的連接數(shù);
accepts:已經(jīng)接受的客戶端請(qǐng)求的總數(shù);
handled:已經(jīng)處理完成的客戶端請(qǐng)求的總數(shù);
requests:客戶端發(fā)來(lái)的總的請(qǐng)求數(shù);
Reading:處于讀取客戶端請(qǐng)求報(bào)文首部的連接的連接數(shù);
Writing:處于向客戶端發(fā)送響應(yīng)報(bào)文過(guò)程中的連接數(shù);
Waiting:處于等待客戶端發(fā)出請(qǐng)求的空閑連接數(shù);
stub_status;
配置示例:
location /basic_status {
stub_status;
}
9.ngx_http_log_module模塊
(1)log_format name string ...;
string可以使用nginx核心模塊及其它模塊內(nèi)嵌的變量;
(2)access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];
access_log off;
訪問(wèn)日志文件路徑,格式及相關(guān)的緩沖的配置;
buffer=size
flush=time
(3)open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
緩存各日志文件相關(guān)的元數(shù)據(jù)信息;
max:緩存的最大文件描述符數(shù)量;
min_uses:在inactive指定的時(shí)長(zhǎng)內(nèi)訪問(wèn)大于等于此值方可被當(dāng)作活動(dòng)項(xiàng);
inactive:非活動(dòng)時(shí)長(zhǎng);
valid:驗(yàn)正緩存中各緩存項(xiàng)是否為活動(dòng)項(xiàng)的時(shí)間間隔;
10.ngx_http_gzip_module:
(1)gzip on | off;
Enables or disables gzipping of responses.
(2)gzip_comp_level level;
Sets a gzip compression level of a response. Acceptable values are in the range from 1 to 9.
(3)gzip_disable regex ...;
Disables gzipping of responses for requests with “User-Agent” header fields matching any of the specified regular expressions.
(4)gzip_min_length length;
啟用壓縮功能的響應(yīng)報(bào)文大小閾值;
(5)gzip_buffers number size;
支持實(shí)現(xiàn)壓縮功能時(shí)為其配置的緩沖區(qū)數(shù)量及每個(gè)緩存區(qū)的大小;
(6)gzip_proxied off | expired | no-cache | no-store | private | no_last_modified | no_etag | auth | any ...;
nginx作為代理服務(wù)器接收到從被代理服務(wù)器發(fā)送的響應(yīng)報(bào)文后,在何種條件下啟用壓縮功能的;
off:對(duì)代理的請(qǐng)求不啟用
no-cache, no-store,private:表示從被代理服務(wù)器收到的響應(yīng)報(bào)文首部的Cache-Control的值為此三者中任何一個(gè),則啟用壓縮功能;
(7)gzip_types mime-type ...;
壓縮過(guò)濾器,僅對(duì)此處設(shè)定的MIME類(lèi)型的內(nèi)容啟用壓縮功能;
示例:
gzip on;
gzip_comp_level 6;
gzip_min_length 64;
gzip_proxied any;
gzip_types text/xml text/css application/javascript;
8.ngx_http_ssl_module模塊:
(1) ssl on | off;
Enables the HTTPS protocol for the given virtual server.
(2)ssl_certificate file;
當(dāng)前虛擬主機(jī)使用PEM格式的證書(shū)文件;
(3)ssl_certificate_key file;
當(dāng)前虛擬主機(jī)上與其證書(shū)匹配的私鑰文件;
(4)ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2];
支持ssl協(xié)議版本,默認(rèn)為后三個(gè);
(5)、ssl_session_cache off | none | [builtin[:size]] [shared:name:size];
builtin[:size]:使用OpenSSL內(nèi)建的緩存,此緩存為每worker進(jìn)程私有;
[shared:name:size]:在各worker之間使用一個(gè)共享的緩存;
(6)ssl_session_timeout time;
客戶端一側(cè)的連接可以復(fù)用ssl session cache中緩存 的ssl參數(shù)的有效時(shí)長(zhǎng);
配置示例:
server {
listen 443 ssl;
server_name www.magedu.com;
root /vhosts/ssl/htdocs;
ssl on;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
ssl_session_cache shared:sslcache:20m;
}
9.ngx_http_rewrite_module模塊:
(1)rewrite regex replacement [flag]
將用戶請(qǐng)求的URI基于regex所描述的模式進(jìn)行檢查,匹配到時(shí)將其替換為replacement指定的新的URI;
注意:如果在同一級(jí)配置塊中存在多個(gè)rewrite規(guī)則,那么會(huì)自下而下逐個(gè)檢查;被某條件規(guī)則替換完成后,會(huì)重新一輪的替換檢查,因此,隱含有循環(huán)機(jī)制;[flag]所表示的標(biāo)志位用于控制此循環(huán)機(jī)制;
last:重寫(xiě)完成后停止對(duì)當(dāng)前URI在當(dāng)前l(fā)ocation中后續(xù)的其它重寫(xiě)操作,而后對(duì)新的URI啟動(dòng)新一輪重寫(xiě)檢查;提前重啟新一輪循環(huán);
break:重寫(xiě)完成后停止對(duì)當(dāng)前URI在當(dāng)前l(fā)ocation中后續(xù)的其它重寫(xiě)操作,而后直接跳轉(zhuǎn)至重寫(xiě)規(guī)則配置塊之后的其它配置;結(jié)束循環(huán);
redirect:重寫(xiě)完成后以臨時(shí)重定向方式直接返回重寫(xiě)后生成的新URI給客戶端,由客戶端重新發(fā)起請(qǐng)求;不能以http://或https://開(kāi)頭;(301)
permanent:重寫(xiě)完成后以永久重定向方式直接返回重寫(xiě)后生成的新URI給客戶端,由客戶端重新發(fā)起請(qǐng)求;(302)
(2)return
return code [text];
return code URL;
return URL;
Stops processing and returns the specified code to a client.
(3)rewrite_log on | off;
是否開(kāi)啟重寫(xiě)日志;
(4) if (condition) { ... }
引入一個(gè)新的配置上下文 ;條件滿足時(shí),執(zhí)行配置塊中的配置指令;server, location:
condition:
比較操作符:
==
!=
~:模式匹配,區(qū)分字符大小寫(xiě);
~*:模式匹配,不區(qū)分字符大小寫(xiě);
!~:模式不匹配,區(qū)分字符大小寫(xiě);
!~*:模式不匹配,不區(qū)分字符大小寫(xiě);
文件及目錄存在性判斷:
-e, !-e
-f, !-f
-d, !-d
-x, !-x
10.ngx_http_referer_module模塊
(1)valid_referers none | blocked | server_names | string ...;
定義referer首部的合法可用值;
none:請(qǐng)求報(bào)文首部沒(méi)有referer首部;
blocked:請(qǐng)求報(bào)文的referer首部沒(méi)有值;
server_names:參數(shù),其可以有值作為主機(jī)名或主機(jī)名模式;
arbitrary_string:直接字符串,但可使用*作通配符;
regular expression:被指定的正則表達(dá)式模式匹配到的字符串;要使用~打頭,例如 ~.*\.magedu\.com;
配置示例:
valid_referers none block server_names *.magedungx_http_proxy_module模塊:.com *.mageedu.com magedu.* mageedu.* ~\.magedu\.;
if($invalid_referer) {
return http://www.magedu.com/invalid.jpg;
}
if($invalid_referer) {
return 403;
}
11.ngx_http_proxy_module模塊:
(1)proxy_pass URL;
Context: location, if in location, limit_except
注意:proxy_pass后面的路徑不帶uri時(shí),其會(huì)將location的uri傳遞給后端主機(jī) server {
...
server_name HOSTNAME;
location /uri/ {
proxy http://host[:port];
}
...
}
http://HOSTNAME/uri --> http://host/uri
proxy_pass后面的路徑是一個(gè)uri時(shí),其會(huì)將location的uri替換為proxy_pass的uri;
server {
...
server_name HOSTNAME;
location /uri/ {
proxy http://host/new_uri/;
}
..
}
http://HOSTNAME/uri/ --> http://host/new_uri/
如果location定義其uri時(shí)使用了正則表達(dá)式的模式,或在if語(yǔ)句或limt_execept中使用proxy_pass指令,則 proxy_pass之后必須不能使用uri; 用戶請(qǐng)求時(shí)傳遞的uri將直接附加代理到的服務(wù)的之后;
server {
...
server_name HOSTNAME;
location ~|~* /uri/ {
proxy http://host;
}
...
}
(2)proxy_set_header field value;
設(shè)定發(fā)往后端主機(jī)的請(qǐng)求報(bào)文的請(qǐng)求首部的值;Context: http, server, location
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
(3)proxy_cache_path
定義可用于proxy功能的緩存;Context: http
proxy_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time];
(4)proxy_cache zone | off;
指明要調(diào)用的緩存,或關(guān)閉緩存機(jī)制;Context: http, server, location
(5)proxy_cache_key string;
緩存中用于“鍵”的內(nèi)容;
默認(rèn)值:proxy_cache_key $scheme$proxy_host$request_uri;
(6)proxy_cache_valid [code ...] time;
定義對(duì)特定響應(yīng)碼的響應(yīng)內(nèi)容的緩存時(shí)長(zhǎng);
定義在http{...}中;
proxy_cache_path /var/cache/nginx/proxy_cache levels=1:1:1 keys_zone=pxycache:20m max_size=1g;
定義在需要調(diào)用緩存功能的配置段,例如server{...};
proxy_cache pxycache;
proxy_cache_key $request_uri;
proxy_cache_valid 200 302 301 1h;
proxy_cache_valid any 1m;
proxy_cache_use_stale http_502;
(7)proxy_cache_use_stale(后端服務(wù)器出現(xiàn)了問(wèn)題,反向代理用緩存來(lái)響應(yīng))
proxy_cache_use_stale error | timeout | invalid_header | updating | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | off ...;
Determines in which cases a stale cached response can be used when an error occurs during communication with the proxied server.
(8)proxy_cache_methods GET | HEAD | POST ...;
If the client request method is listed in this directive then the response will be cached. “GET” and “HEAD” methods are always added to the list, though it is recommended to specify them explicitly.
(9)proxy_hide_header field;
By default, nginx does not pass the header fields “Date”, “Server”, “X-Pad”, and “X-Accel-...” from the response of a proxied server to a client. The proxy_hide_header directive sets additional fields that will not be passed.
(10)proxy_connect_timeout time;
Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.
默認(rèn)為60s;最長(zhǎng)為75s;
(11)proxy_read_timeout time;
Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, not for the transmission of the whole response.
(12)proxy_send_timeout time;
Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the proxied server does not receive anything within this time, the connection is closed.
12.ngx_http_headers_module模塊:
向由代理服務(wù)器響應(yīng)給客戶端的響應(yīng)報(bào)文添加自定義首部,或修改指定首部的值;
(1)add_header name value [always]
添加自定義首部;
add_header X-Via $server_addr;
add_header X-Accel $server_name;
(2)expires [modified] time;
expires epoch | max | off;
用于定義Expire或Cache-Control首部的值;
13.ngx_http_fastcgi_module模塊:
(1)fastcgi_pass address;
address為fastcgi server的地址; location, if in location;
http://www.ilinux.io/admin/index.php --> /admin/index.php (uri)
/data/application/admin/index.php
(2)fastcgi_index name;
fastcgi默認(rèn)的主頁(yè)資源;
(3)fastcgi_param parameter value [if_not_empty];
Sets a parameter that should be passed to the FastCGI server. The value can contain text, variables, and their combination.
配置示例1:
前提:配置好fpm server和mariadb-server服務(wù);
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
配置示例2:通過(guò)/pm_status和/ping來(lái)獲取fpm server狀態(tài)信息;
location ~* ^/(pm_status|ping)$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
(4)fastcgi_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number]
[purger_sleep=time] [purger_threshold=time];
定義fastcgi的緩存;緩存位置為磁盤(pán)上的文件系統(tǒng),由path所指定路徑來(lái)定義;
levels=levels:緩存目錄的層級(jí)數(shù)量,以及每一級(jí)的目錄數(shù)量;levels=ONE:TWO:THREE
leves=1:2:2
keys_zone=name:size
k/v映射的內(nèi)存空間的名稱(chēng)及大小
inactive=time
非活動(dòng)時(shí)長(zhǎng)
max_size=size
磁盤(pán)上用于緩存數(shù)據(jù)的緩存空間上限
(5)fastcgi_cache zone | off;
調(diào)用指定的緩存空間來(lái)緩存數(shù)據(jù);http, server, location
(6)fastcgi_cache_key string;
定義用作緩存項(xiàng)的key的字符串;
(7)fastcgi_cache_methods GET | HEAD | POST ...;
為哪些請(qǐng)求方法使用緩存;
(8)fastcgi_cache_min_uses number;
緩存空間中的緩存項(xiàng)在inactive定義的非活動(dòng)時(shí)間內(nèi)至少要被訪問(wèn)到此處所指定的次數(shù)方可被認(rèn)作活動(dòng)項(xiàng);
(9)fastcgi_cache_valid [code ...] time;
不同的響應(yīng)碼各自的緩存時(shí)長(zhǎng);
示例:
http {
...
fastcgi_cache_path /var/cache/nginx/fastcgi_cache levels=1:2:1 keys_zone=fcgi:20m inactive=120s;
...
server {
...
location ~* \.php$ {
...
fastcgi_cache fcgi;
fastcgi_cache_key $request_uri;
fastcgi_cache_valid 200 302 10m;
fastcgi_cache_valid 301 1h;
fastcgi_cache_valid any 1m;
...
}
...
}
...
}
(10)fastcgi_keep_conn on | off;(發(fā)請(qǐng)求時(shí))
By default, a FastCGI server will close a connection right after sending the response. However, when this directive is set to the value on, nginx will instruct a FastCGI server to keep connections open.
14.ngx_http_upstream_module模塊
(1)upstream name { ... }
定義后端服務(wù)器組,會(huì)引入一個(gè)新的上下文;Context: http
upstream httpdsrvs {
server ...
server...
...
}
(2)server address [parameters];
在upstream上下文中server成員,以及相關(guān)的參數(shù);Context: upstream
address的表示格式:
unix:/PATH/TO/SOME_SOCK_FILE
IP[:PORT]
HOSTNAME[:PORT]
parameters:
weight=number
權(quán)重,默認(rèn)為1;
max_fails=number
失敗嘗試最大次數(shù);超出此處指定的次數(shù)時(shí),server將被標(biāo)記為不可用;
fail_timeout=time
設(shè)置將服務(wù)器標(biāo)記為不可用狀態(tài)的超時(shí)時(shí)長(zhǎng);
max_conns
當(dāng)前的服務(wù)器的最大并發(fā)連接數(shù);
backup
將服務(wù)器標(biāo)記為“備用”,即所有服務(wù)器均不可用時(shí)此服務(wù)器才啟用;
down
標(biāo)記為“不可用”;
(3)least_conn;
最少連接調(diào)度算法,當(dāng)server擁有不同的權(quán)重時(shí)其為wlc;
(4)ip_hash;
源地址hash調(diào)度方法;
(5)hash key [consistent];
基于指定的key的hash表來(lái)實(shí)現(xiàn)對(duì)請(qǐng)求的調(diào)度,此處的key可以直接文本、變量或二者的組合;
作用:將請(qǐng)求分類(lèi),同一類(lèi)請(qǐng)求將發(fā)往同一個(gè)upstream server;
If the consistent parameter is specified the ketama consistent hashing method will be used instead.
示例:
hash $request_uri consistent;(提高命中率)
hash $remote_addr;
(6)keepalive connections;
為每個(gè)worker進(jìn)程保留的空閑的長(zhǎng)連接數(shù)量;每worker與后端服務(wù)保持的最大空閑長(zhǎng)連接數(shù)量
15.ngx_stream_core_module模塊:
(1)proxy_pass address;
(2)proxy_timeout timeout:默認(rèn)為10s,連接建立起來(lái)了,請(qǐng)求發(fā)出去的超時(shí)時(shí)間
(3)proxy_connect_timeout time:設(shè)置nginx與被代理的服務(wù)器嘗試建立連接的超時(shí)時(shí)長(zhǎng);默認(rèn)為60s;
示例:stream { ... }
定義stream相關(guān)的服務(wù);Context:main
stream {
upstream sshsrvs {
server 192.168.22.2:22;
server 192.168.22.3:22;
least_conn;
}
server {
listen 10.1.0.6:22022;
proxy_pass sshsrvs;
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。