"/>

2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?/h1>

Posted 渚犳ⅵ鐨勫紑鍙戠瑪璁?/a>

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?/h1>

相关的知识,希望对你有一定的参考价值。




鍓嶈█

浣滀负涓€鍚嶅墠绔紑鍙戜汉鍛橈紝浣犳槸涓嶆槸缁忓父纰板埌棰嗗璁╀綘涓婃湇鍔″櫒鍘讳慨鏀?nbsp;nginx 閰嶇疆锛岀劧鑰屼綘浼氫互鈥滄垜鏄墠绔紝杩欎釜鎴戜笉浼氣€濅负鐞嗙敱鎼杩囧幓鍛紒浠婂ぉ灏辫鎴戜滑涓€璧峰憡鍒繖绉嶅按灏紝鍚戔€滅湡姝b€濈殑绋嬪簭鍛樿繄杩涳紒锛侊紒

濡傛灉鏈枃瀵逛綘鏈夋墍甯姪锛岃鐐逛釜馃憤 馃憤 馃憤 鍚э紒

Nginx 姒傝堪

Nginx 鏄紑婧愩€侀珮鎬ц兘銆侀珮鍙潬鐨?nbsp;Web 鍜屽弽鍚戜唬鐞嗘湇鍔″櫒锛岃€屼笖鏀寔鐑儴缃诧紝鍑犱箮鍙互鍋氬埌 7 * 24 灏忔椂涓嶉棿鏂繍琛岋紝鍗充娇杩愯鍑犱釜鏈堜篃涓嶉渶瑕侀噸鏂板惎鍔紝杩樿兘鍦ㄤ笉闂存柇鏈嶅姟鐨勬儏鍐典笅瀵硅蒋浠剁増鏈繘琛岀儹鏇存柊銆傛€ц兘鏄?nbsp;Nginx 鏈€閲嶈鐨勮€冮噺锛屽叾鍗犵敤鍐呭瓨灏戙€佸苟鍙戣兘鍔涘己銆佽兘鏀寔楂樿揪 5w 涓苟鍙戣繛鎺ユ暟锛屾渶閲嶈鐨勬槸锛?nbsp;Nginx 鏄厤璐圭殑骞跺彲浠ュ晢涓氬寲锛岄厤缃娇鐢ㄤ篃姣旇緝绠€鍗曘€?/p>

Nginx 鐗圭偣

  • 楂樺苟鍙戙€侀珮鎬ц兘锛?
  • 妯″潡鍖栨灦鏋勪娇寰楀畠鐨勬墿灞曟€ч潪甯稿ソ锛?
  • 寮傛闈為樆濉炵殑浜嬩欢椹卞姩妯″瀷杩欑偣鍜?nbsp; Node.js 鐩镐技锛?
  • 鐩稿浜庡叾瀹冩湇鍔″櫒鏉ヨ瀹冨彲浠ヨ繛缁嚑涓湀鐢氳嚦鏇撮暱鑰屼笉闇€瑕侀噸鍚湇鍔″櫒浣垮緱瀹冨叿鏈夐珮鍙潬鎬э紱
  • 鐑儴缃层€佸钩婊戝崌绾э紱
  • 瀹屽叏寮€婧愶紝鐢熸€佺箒鑽o紱

Nginx 浣滅敤

Nginx 鐨勬渶閲嶈鐨勫嚑涓娇鐢ㄥ満鏅細

  1. 闈欐€佽祫婧愭湇鍔★紝閫氳繃鏈湴鏂囦欢绯荤粺鎻愪緵鏈嶅姟锛?
  2. 鍙嶅悜浠g悊鏈嶅姟锛屽欢浼稿嚭鍖呮嫭缂撳瓨銆佽礋杞藉潎琛$瓑锛?
  3. API 鏈嶅姟锛?nbsp; OpenResty 锛?

瀵逛簬鍓嶇鏉ヨ Node.js 骞朵笉闄岀敓锛?nbsp;Nginx 鍜?nbsp;Node.js 鐨勫緢澶氱悊蹇电被浼硷紝 HTTP 鏈嶅姟鍣ㄣ€佷簨浠堕┍鍔ㄣ€佸紓姝ラ潪闃诲绛夛紝涓?nbsp;Nginx 鐨勫ぇ閮ㄥ垎鍔熻兘浣跨敤 Node.js 涔熷彲浠ュ疄鐜帮紝浣?nbsp;Nginx 鍜?nbsp;Node.js 骞朵笉鍐茬獊锛岄兘鏈夎嚜宸辨搮闀跨殑棰嗗煙銆?nbsp;Nginx 鎿呴暱浜庡簳灞傛湇鍔″櫒绔祫婧愮殑澶勭悊锛堥潤鎬佽祫婧愬鐞嗚浆鍙戙€佸弽鍚戜唬鐞嗭紝璐熻浇鍧囪 绛夛級锛?nbsp;Node.js 鏇存搮闀夸笂灞傚叿浣撲笟鍔¢€昏緫鐨勫鐞嗭紝涓よ€呭彲浠ュ畬缇庣粍鍚堛€?/p>

鐢ㄤ竴寮犲浘琛ㄧず锛?/p>

Nginx 瀹夎

鏈枃婕旂ず鐨勬槸 Linux centOS 7.x 鐨勬搷浣滅郴缁熶笂瀹夎 Nginx 锛岃嚦浜庡湪鍏跺畠鎿嶄綔绯荤粺涓婅繘琛屽畨瑁呭彲浠ョ綉涓婅嚜琛屾悳绱紝閮介潪甯哥畝鍗曠殑銆?/p>

浣跨敤  yum 瀹夎 Nginx 锛?/p>

yum install nginx -y

瀹夎瀹屾垚鍚庯紝閫氳繃 rpm -ql nginx 鍛戒护鏌ョ湅 Nginx 鐨勫畨瑁呬俊鎭細

# Nginx閰嶇疆鏂囦欢
/etc/nginx/nginx.conf # nginx 涓婚厤缃枃浠?/span>
/etc/nginx/nginx.conf.default

# 鍙墽琛岀▼搴忔枃浠?/span>
/usr/bin/nginx-upgrade
/usr/sbin/nginx

# nginx搴撴枃浠?/span>
/usr/lib/systemd/system/nginx.service # 鐢ㄤ簬閰嶇疆绯荤粺瀹堟姢杩涚▼
/usr/lib64/nginx/modules # Nginx妯″潡鐩綍

# 甯姪鏂囨。
/usr/share/doc/nginx-1.16.1
/usr/share/doc/nginx-1.16.1/CHANGES
/usr/share/doc/nginx-1.16.1/README
/usr/share/doc/nginx-1.16.1/README.dynamic
/usr/share/doc/nginx-1.16.1/UPGRADE-NOTES-1.6-to-1.10

# 闈欐€佽祫婧愮洰褰?/span>
/usr/share/nginx/html/404.html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html

# 瀛樻斁Nginx鏃ュ織鏂囦欢
/var/log/nginx

涓昏鍏虫敞鐨勬枃浠跺す鏈変袱涓細

  1. /etc/nginx/conf.d/ 鏄瓙閰嶇疆椤瑰瓨鏀惧锛?nbsp; /etc/nginx/nginx.conf 涓婚厤缃枃浠朵細榛樿鎶婅繖涓枃浠跺す涓墍鏈夊瓙閰嶇疆椤归兘寮曞叆锛?
  2. /usr/share/nginx/html/ 闈欐€佹枃浠堕兘鏀惧湪杩欎釜鏂囦欢澶癸紝涔熷彲浠ユ牴鎹綘鑷繁鐨勪範鎯斁鍦ㄥ叾浠栧湴鏂癸紱

Nginx 甯哥敤鍛戒护

systemctl 绯荤粺鍛戒护锛?/p>

# 寮€鏈洪厤缃?/span>
systemctl enable nginx # 寮€鏈鸿嚜鍔ㄥ惎鍔?/span>
systemctl disable nginx # 鍏抽棴寮€鏈鸿嚜鍔ㄥ惎鍔?/span>

# 鍚姩Nginx
systemctl start nginx # 鍚姩Nginx鎴愬姛鍚庯紝鍙互鐩存帴璁块棶涓绘満IP锛屾鏃朵細灞曠ずNginx榛樿椤甸潰

# 鍋滄Nginx
systemctl stop nginx

# 閲嶅惎Nginx
systemctl restart nginx

# 閲嶆柊鍔犺浇Nginx
systemctl reload nginx

# 鏌ョ湅 Nginx 杩愯鐘舵€?/span>
systemctl status nginx

# 鏌ョ湅Nginx杩涚▼
ps -ef | grep nginx

# 鏉€姝籒ginx杩涚▼
kill -9 pid # 鏍规嵁涓婇潰鏌ョ湅鍒扮殑Nginx杩涚▼鍙凤紝鏉€姝籒ginx杩涚▼锛?9 琛ㄧず寮哄埗缁撴潫杩涚▼

Nginx 搴旂敤绋嬪簭鍛戒护锛?/p>

nginx -s reload  # 鍚戜富杩涚▼鍙戦€佷俊鍙凤紝閲嶆柊鍔犺浇閰嶇疆鏂囦欢锛岀儹閲嶅惎
nginx -s reopen  # 閲嶅惎 Nginx
nginx -s stop    # 蹇€熷叧闂?/span>
nginx -s quit    # 绛夊緟宸ヤ綔杩涚▼澶勭悊瀹屾垚鍚庡叧闂?/span>
nginx -T         # 鏌ョ湅褰撳墠 Nginx 鏈€缁堢殑閰嶇疆
nginx -t         # 妫€鏌ラ厤缃槸鍚︽湁闂

Nginx 鏍稿績閰嶇疆

閰嶇疆鏂囦欢缁撴瀯

Nginx 鐨勫吀鍨嬮厤缃ず渚嬶細

# main娈甸厤缃俊鎭?/span>
user  nginx;                        # 杩愯鐢ㄦ埛锛岄粯璁ゅ嵆鏄痭ginx锛屽彲浠ヤ笉杩涜璁剧疆
worker_processes  auto;             # Nginx 杩涚▼鏁帮紝涓€鑸缃负鍜?nbsp;CPU 鏍告暟涓€鏍?/span>
error_log  /var/log/nginx/error.log warn;   # Nginx 鐨勯敊璇棩蹇楀瓨鏀剧洰褰?/span>
pid        /var/run/nginx.pid;      # Nginx 鏈嶅姟鍚姩鏃剁殑 pid 瀛樻斁浣嶇疆

# events娈甸厤缃俊鎭?/span>
events {
    use epoll;     # 浣跨敤epoll鐨処/O妯″瀷(濡傛灉浣犱笉鐭ラ亾Nginx璇ヤ娇鐢ㄥ摢绉嶈疆璇㈡柟娉曪紝浼氳嚜鍔ㄩ€夋嫨涓€涓渶閫傚悎浣犳搷浣滅郴缁熺殑)
    worker_connections 1024;   # 姣忎釜杩涚▼鍏佽鏈€澶у苟鍙戞暟
}

# http娈甸厤缃俊鎭?/span>
# 閰嶇疆浣跨敤鏈€棰戠箒鐨勯儴鍒嗭紝浠g悊銆佺紦瀛樸€佹棩蹇楀畾涔夌瓑缁濆ぇ澶氭暟鍔熻兘鍜岀涓夋柟妯″潡鐨勯厤缃兘鍦ㄨ繖閲岃缃?/span>
http {
    # 璁剧疆鏃ュ織妯″紡
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;   # Nginx璁块棶鏃ュ織瀛樻斁浣嶇疆

    sendfile            on;   # 寮€鍚珮鏁堜紶杈撴ā寮?/span>
    tcp_nopush          on;   # 鍑忓皯缃戠粶鎶ユ枃娈电殑鏁伴噺
    tcp_nodelay         on;
    keepalive_timeout   65;   # 淇濇寔杩炴帴鐨勬椂闂达紝涔熷彨瓒呮椂鏃堕棿锛屽崟浣嶇
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;      # 鏂囦欢鎵╁睍鍚嶄笌绫诲瀷鏄犲皠琛?/span>
    default_type        application/octet-stream;   # 榛樿鏂囦欢绫诲瀷

    include /etc/nginx/conf.d/*.conf;   # 鍔犺浇瀛愰厤缃」

    # server娈甸厤缃俊鎭?/span>
    server {
     listen       80;       # 閰嶇疆鐩戝惉鐨勭鍙?/span>
     server_name  localhost;    # 閰嶇疆鐨勫煙鍚?/span>

     # location娈甸厤缃俊鎭?/span>
     location / {
      root   /usr/share/nginx/html;  # 缃戠珯鏍圭洰褰?/span>
      index  index.html index.htm;   # 榛樿棣栭〉鏂囦欢
      deny 172.168.22.11;   # 绂佹璁块棶鐨刬p鍦板潃锛屽彲浠ヤ负all
      allow 172.168.33.44锛?span class="mq-229"># 鍏佽璁块棶鐨刬p鍦板潃锛屽彲浠ヤ负all

     }

     error_page 500 502 503 504 /50x.html;  # 榛樿50x瀵瑰簲鐨勮闂〉闈?/span>
     error_page 400 404 error.html;   # 鍚屼笂
    }
}

  • main 鍏ㄥ眬閰嶇疆锛屽鍏ㄥ眬鐢熸晥锛?
  • events 閰嶇疆褰卞搷  Nginx 鏈嶅姟鍣ㄤ笌鐢ㄦ埛鐨勭綉缁滆繛鎺ワ紱
  • http 閰嶇疆浠g悊锛岀紦瀛橈紝鏃ュ織瀹氫箟绛夌粷澶у鏁板姛鑳藉拰绗笁鏂规ā鍧楃殑閰嶇疆锛?
  • server 閰嶇疆铏氭嫙涓绘満鐨勭浉鍏冲弬鏁帮紝涓€涓?nbsp; http 鍧椾腑鍙互鏈夊涓?nbsp; server 鍧楋紱
  • location 鐢ㄤ簬閰嶇疆鍖归厤鐨?nbsp; uri 锛?
  • upstream 閰嶇疆鍚庣鏈嶅姟鍣ㄥ叿浣撳湴鍧€锛岃礋杞藉潎琛¢厤缃笉鍙垨缂虹殑閮ㄥ垎锛?

鐢ㄤ竴寮犲浘娓呮櫚鐨勫睍绀哄畠鐨勫眰绾х粨鏋勶細2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?></p> 
<h2 data-tool=閰嶇疆鏂囦欢 main 娈垫牳蹇冨弬鏁?/span>

user

鎸囧畾杩愯 Nginx 鐨?nbsp;woker 瀛愯繘绋嬬殑灞炰富鍜屽睘缁勶紝鍏朵腑缁勫彲浠ヤ笉鎸囧畾銆?/p>

user USERNAME [GROUP]

user nginx lion; # 鐢ㄦ埛鏄痭ginx;缁勬槸lion

pid

鎸囧畾杩愯 Nginx master 涓昏繘绋嬬殑 pid 鏂囦欢瀛樻斁璺緞銆?/p>

pid /opt/nginx/logs/nginx.pid # master涓昏繘绋嬬殑鐨刾id瀛樻斁鍦╪ginx.pid鐨勬枃浠?/span>

worker_rlimit_nofile_number

鎸囧畾 worker 瀛愯繘绋嬪彲浠ユ墦寮€鐨勬渶澶ф枃浠跺彞鏌勬暟銆?/p>

worker_rlimit_nofile 20480; # 鍙互鐞嗚В鎴愭瘡涓獁orker瀛愯繘绋嬬殑鏈€澶ц繛鎺ユ暟閲忋€?/span>

worker_rlimit_core

鎸囧畾 worker 瀛愯繘绋嬪紓甯哥粓姝㈠悗鐨?nbsp;core 鏂囦欢锛岀敤浜庤褰曞垎鏋愰棶棰樸€?/p>

worker_rlimit_core 50M; # 瀛樻斁澶у皬闄愬埗working_directory /opt/nginx/tmp; # 瀛樻斁鐩綍澶嶅埗浠g爜

worker_processes_number

鎸囧畾 Nginx 鍚姩鐨?nbsp;worker 瀛愯繘绋嬫暟閲忋€?/p>

worker_processes 4; # 鎸囧畾鍏蜂綋瀛愯繘绋嬫暟閲弚orker_processes auto; # 涓庡綋鍓峜pu鐗╃悊鏍稿績鏁颁竴鑷村鍒朵唬鐮?/span>

worker_cpu_affinity

灏嗘瘡涓?nbsp;worker 瀛愯繘绋嬩笌鎴戜滑鐨?nbsp;cpu 鐗╃悊鏍稿績缁戝畾銆?/p>

worker_cpu_affinity 0001 0010 0100 1000; # 4涓墿鐞嗘牳蹇冿紝4涓獁orker瀛愯繘绋嬪鍒朵唬鐮?/span>
2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?> 
</figure> 
<p data-tool=灏嗘瘡涓?nbsp;worker 瀛愯繘绋嬩笌鐗瑰畾 CPU 鐗╃悊鏍稿績缁戝畾锛屼紭鍔垮湪浜庯紝閬垮厤鍚屼竴涓?nbsp;worker 瀛愯繘绋嬪湪涓嶅悓鐨?nbsp;CPU 鏍稿績涓婂垏鎹紝缂撳瓨澶辨晥锛岄檷浣庢€ц兘銆備絾鍏跺苟涓嶈兘鐪熸鐨勯伩鍏嶈繘绋嬪垏鎹€?/p>

worker_priority

鎸囧畾 worker 瀛愯繘绋嬬殑 nice 鍊硷紝浠ヨ皟鏁磋繍琛?nbsp;Nginx 鐨勪紭鍏堢骇锛岄€氬父璁惧畾涓鸿礋鍊硷紝浠ヤ紭鍏堣皟鐢?nbsp;Nginx 銆?/p>

worker_priority -10; # 120-10=110锛?10灏辨槸鏈€缁堢殑浼樺厛绾?/span>

Linux 榛樿杩涚▼鐨勪紭鍏堢骇鍊兼槸120锛屽€艰秺灏忚秺浼樺厛锛?nbsp;nice 瀹氳寖鍥翠负 -20 鍒?nbsp;+19 銆?/p>

[澶囨敞] 搴旂敤鐨勯粯璁や紭鍏堢骇鍊兼槸120鍔犱笂 nice 鍊肩瓑浜庡畠鏈€缁堢殑鍊硷紝杩欎釜鍊艰秺灏忥紝浼樺厛绾ц秺楂樸€?/p>

worker_shutdown_timeout

鎸囧畾 worker 瀛愯繘绋嬩紭闆呴€€鍑烘椂鐨勮秴鏃舵椂闂淬€?/p>

worker_shutdown_timeout 5s;

timer_resolution

worker 瀛愯繘绋嬪唴閮ㄤ娇鐢ㄧ殑璁℃椂鍣ㄧ簿搴︼紝璋冩暣鏃堕棿闂撮殧瓒婂ぇ锛岀郴缁熻皟鐢ㄨ秺灏戯紝鏈夊埄浜庢€ц兘鎻愬崌锛涘弽涔嬶紝绯荤粺璋冪敤瓒婂锛屾€ц兘涓嬮檷銆?/p>

timer_resolution 100ms;

鍦?nbsp;Linux 绯荤粺涓紝鐢ㄦ埛闇€瑕佽幏鍙栬鏃跺櫒鏃堕渶瑕佸悜鎿嶄綔绯荤粺鍐呮牳鍙戦€佽姹傦紝鏈夎姹傚氨蹇呯劧浼氭湁寮€閿€锛屽洜姝よ繖涓棿闅旇秺澶у紑閿€灏辫秺灏忋€?/p>

daemon

鎸囧畾 Nginx 鐨勮繍琛屾柟寮忥紝鍓嶅彴杩樻槸鍚庡彴锛屽墠鍙扮敤浜庤皟璇曪紝鍚庡彴鐢ㄤ簬鐢熶骇銆?/p>

daemon off; # 榛樿鏄痮n锛屽悗鍙拌繍琛屾ā寮?/span>

閰嶇疆鏂囦欢 events 娈垫牳蹇冨弬鏁?/span>

use

Nginx 浣跨敤浣曠浜嬩欢椹卞姩妯″瀷銆?/p>

use method; # 涓嶆帹鑽愰厤缃畠锛岃nginx鑷繁閫夋嫨method 鍙€夊€间负锛歴elect銆乸oll銆乲queue銆乪poll銆?dev/poll銆乪ventport澶嶅埗浠g爜

worker_connections

worker 瀛愯繘绋嬭兘澶熷鐞嗙殑鏈€澶у苟鍙戣繛鎺ユ暟銆?/p>

worker_connections 1024 # 姣忎釜瀛愯繘绋嬬殑鏈€澶ц繛鎺ユ暟涓?024澶嶅埗浠g爜

accept_mutex

鏄惁鎵撳紑璐熻浇鍧囪 浜掓枼閿併€?/p>

accept_mutex on # 榛樿鏄痮ff鍏抽棴鐨勶紝杩欓噷鎺ㄨ崘鎵撳紑澶嶅埗浠g爜

server_name 鎸囦护

鎸囧畾铏氭嫙涓绘満鍩熷悕銆?/p>

server_name name1 name2 name3# 绀轰緥锛歴erver_name www.nginx.com;澶嶅埗浠g爜

鍩熷悕鍖归厤鐨勫洓绉嶅啓娉曪細

  • 绮剧‘鍖归厤锛?nbsp; server_name www.nginx.com ;
  • 宸︿晶閫氶厤锛?nbsp; server_name *.nginx.com ;
  • 鍙充晶缁熼厤锛?nbsp; server_name www.nginx.* ;
  • 姝e垯鍖归厤锛?nbsp; server_name ~^www\.nginx\.*$ ;

鍖归厤浼樺厛绾э細绮剧‘鍖归厤 > 宸︿晶閫氶厤绗﹀尮閰?> 鍙充晶閫氶厤绗﹀尮閰?> 姝e垯琛ㄨ揪寮忓尮閰?/span>

server_name 閰嶇疆瀹炰緥锛?/p>

1銆侀厤缃湰鍦? DNS 瑙f瀽 vim /etc/hosts 锛?nbsp;macOS 绯荤粺锛?/p>

# 娣诲姞濡備笅鍐呭锛屽叾涓?nbsp;121.42.11.34 鏄樋閲屼簯鏈嶅姟鍣↖P鍦板潃
121.42.11.34 www.nginx-test.com
121.42.11.34 mail.nginx-test.com
121.42.11.34 www.nginx-test.org
121.42.11.34 doc.nginx-test.com
121.42.11.34 www.nginx-test.cn
121.42.11.34 fe.nginx-test.club

[娉ㄦ剰] 杩欓噷浣跨敤鐨勬槸铏氭嫙鍩熷悕杩涜娴嬭瘯锛屽洜姝ら渶瑕侀厤缃湰鍦?nbsp;DNS 瑙f瀽锛屽鏋滀娇鐢ㄩ樋閲屼簯涓婅喘涔扮殑鍩熷悕锛屽垯闇€瑕佸湪闃块噷浜戜笂璁剧疆濂藉煙鍚嶈В鏋愩€?/p>

2銆侀厤缃樋閲屼簯 Nginx 锛?code class="mq-404">vim /etc/nginx/nginx.conf

# 杩欓噷鍙垪涓句簡http绔腑鐨剆ever绔厤缃?/span>

# 宸﹀尮閰?/span>
server {
 listen 80;
 server_name *.nginx-test.com;
 root /usr/share/nginx/html/nginx-test/left-match/;
 location / {
  index index.html;
 }
}

# 姝e垯鍖归厤
server {
 listen 80;
 server_name ~^.*\.nginx-test\..*$;
 root /usr/share/nginx/html/nginx-test/reg-match/;
 location / {
  index index.html;
 }
}

# 鍙冲尮閰?/span>
server {
 listen 80;
 server_name www.nginx-test.*;
 root /usr/share/nginx/html/nginx-test/right-match/;
 location / {
  index index.html;
 }
}

# 瀹屽叏鍖归厤
server {
 listen 80;
 server_name www.nginx-test.com;
 root /usr/share/nginx/html/nginx-test/all-match/;
 location / {
  index index.html;
 }
}

3銆佽闂垎鏋?/p>

  • 褰撹闂?nbsp; www.nginx-test.com 鏃讹紝閮藉彲浠ヨ鍖归厤涓婏紝鍥犳閫夋嫨浼樺厛绾ф渶楂樼殑鈥滃畬鍏ㄥ尮閰嶁€濓紱
  • 褰撹闂?nbsp; mail.nginx-test.com 鏃讹紝浼氳繘琛屸€滃乏鍖归厤鈥濓紱
  • 褰撹闂?nbsp; www.nginx-test.org 鏃讹紝浼氳繘琛屸€滃彸鍖归厤鈥濓紱
  • 褰撹闂?nbsp; doc.nginx-test.com 鏃讹紝浼氳繘琛屸€滃乏鍖归厤鈥濓紱
  • 褰撹闂?nbsp; www.nginx-test.cn 鏃讹紝浼氳繘琛屸€滃彸鍖归厤鈥濓紱
  • 褰撹闂?nbsp; fe.nginx-test.club 鏃讹紝浼氳繘琛屸€滄鍒欏尮閰嶁€濓紱

root

鎸囧畾闈欐€佽祫婧愮洰褰曚綅缃紝瀹冨彲浠ュ啓鍦?nbsp;http 銆?nbsp;server 銆?nbsp;location 绛夐厤缃腑銆?/p>

root path渚嬪锛歭ocation /image { root /opt/nginx/static;}褰撶敤鎴疯闂?nbsp;www.test.com/image/1.png 鏃讹紝瀹為檯鍦ㄦ湇鍔″櫒鎵剧殑璺緞鏄?nbsp;/opt/nginx/static/image/1.png澶嶅埗浠g爜

[娉ㄦ剰] root 浼氬皢瀹氫箟璺緞涓?nbsp;URI 鍙犲姞锛?nbsp;alias 鍒欏彧鍙栧畾涔夎矾寰勩€?/p>

alias

瀹冧篃鏄寚瀹氶潤鎬佽祫婧愮洰褰曚綅缃紝瀹冨彧鑳藉啓鍦?nbsp;location 涓€?/p>

location /image { alias /opt/nginx/static/image/;}褰撶敤鎴疯闂?nbsp;www.test.com/image/1.png 鏃讹紝瀹為檯鍦ㄦ湇鍔″櫒鎵剧殑璺緞鏄?nbsp;/opt/nginx/static/image/1.png澶嶅埗浠g爜

[娉ㄦ剰] 浣跨敤 alias 鏈熬涓€瀹氳娣诲姞 / 锛屽苟涓斿畠鍙兘浣嶄簬 location 涓€?/p>

location

閰嶇疆璺緞銆?/p>

location [ = | ~ | ~* | ^~ ] uri { ...}澶嶅埗浠g爜

鍖归厤瑙勫垯锛?/p>

  • = 绮剧‘鍖归厤锛?
  • ~ 姝e垯鍖归厤锛屽尯鍒嗗ぇ灏忓啓锛?
  • ~* 姝e垯鍖归厤锛屼笉鍖哄垎澶у皬鍐欙紱
  • ^~ 鍖归厤鍒板嵆鍋滄鎼滅储锛?

鍖归厤浼樺厛绾э細 = > ^~ >  ~ > ~* > 涓嶅甫浠讳綍瀛楃銆?/p>

瀹炰緥锛?/p>

server {
  listen 80;
  server_name www.nginx-test.com;

  # 鍙湁褰撹闂?nbsp;www.nginx-test.com/match_all/ 鏃舵墠浼氬尮閰嶅埌/usr/share/nginx/html/match_all/index.html
  location = /match_all/ {
      root /usr/share/nginx/html
      index index.html
  }

  # 褰撹闂?nbsp;www.nginx-test.com/1.jpg 绛夎矾寰勬椂浼氬幓 /usr/share/nginx/images/1.jpg 鎵惧搴旂殑璧勬簮
  location ~ \.(jpeg|jpg|png|svg)$ {
   root /usr/share/nginx/images;
  }

  # 褰撹闂?nbsp;www.nginx-test.com/bbs/ 鏃朵細鍖归厤涓?nbsp;/usr/share/nginx/html/bbs/index.html
  location ^~ /bbs/ {
   root /usr/share/nginx/html;
    index index.html index.htm;
  }
}

location 涓殑鍙嶆枩绾?/h3>
location /test {
 ...
}

location /test/ {
 ...
}

  • 涓嶅甫  / 褰撹闂?nbsp; www.nginx-test.com/test 鏃讹紝  Nginx 鍏堟壘鏄惁鏈?nbsp; test 鐩綍锛屽鏋滄湁鍒欐壘  test 鐩綍涓嬬殑  index.html 锛涘鏋滄病鏈?nbsp; test 鐩綍锛?nbsp; nginx 鍒欎細鎵炬槸鍚︽湁  test 鏂囦欢銆?
  • 甯?nbsp; / 褰撹闂?nbsp; www.nginx-test.com/test 鏃讹紝  Nginx 鍏堟壘鏄惁鏈?nbsp; test 鐩綍锛屽鏋滄湁鍒欐壘  test 鐩綍涓嬬殑  index.html 锛屽鏋滄病鏈夊畠涔熶笉浼氬幓鎵炬槸鍚﹀瓨鍦?nbsp; test 鏂囦欢銆?

return

鍋滄澶勭悊璇锋眰锛岀洿鎺ヨ繑鍥炲搷搴旂爜鎴栭噸瀹氬悜鍒板叾浠?nbsp;URL 锛涙墽琛?nbsp;return 鎸囦护鍚庯紝 location 涓悗缁寚浠ゅ皢涓嶄細琚墽琛屻€?/p>

return code [text];
return code URL;
return URL;

渚嬪锛?br>location / {
 return 404; # 鐩存帴杩斿洖鐘舵€佺爜
}

location / {
 return 404 "pages not found"# 杩斿洖鐘舵€佺爜 + 涓€娈垫枃鏈?/span>
}

location / {
 return 302 /bbs ; # 杩斿洖鐘舵€佺爜 + 閲嶅畾鍚戝湴鍧€
}

location / {
 return https://www.baidu.com ; # 杩斿洖閲嶅畾鍚戝湴鍧€
}

rewrite

鏍规嵁鎸囧畾姝e垯琛ㄨ揪寮忓尮閰嶈鍒欙紝閲嶅啓 URL 銆?/p>

璇硶锛歳ewrite 姝e垯琛ㄨ揪寮?nbsp;瑕佹浛鎹㈢殑鍐呭 [flag];

涓婁笅鏂囷細server銆乴ocation銆?span class="mq-535">if

绀轰緥锛歳ewirte /images/(.*\.jpg)$ /pic/$1# $1鏄墠闈㈡嫭鍙?.*\.jpg)鐨勫弽鍚戝紩鐢?/span>

flag 鍙€夊€肩殑鍚箟锛?/p>

  • last 閲嶅啓鍚庣殑  URL 鍙戣捣鏂拌姹傦紝鍐嶆杩涘叆  server 娈碉紝閲嶈瘯  location 鐨勪腑鐨勫尮閰嶏紱
  • break 鐩存帴浣跨敤閲嶅啓鍚庣殑  URL 锛屼笉鍐嶅尮閰嶅叾瀹?nbsp; location 涓鍙ワ紱
  • redirect 杩斿洖302涓存椂閲嶅畾鍚戯紱
  • permanent 杩斿洖301姘镐箙閲嶅畾鍚戯紱
server{
  listen 80;
  server_name fe.lion.club; # 瑕佸湪鏈湴hosts鏂囦欢杩涜閰嶇疆
  root html;
  location /search {
   rewrite ^/(.*) https://www.baidu.com redirect;
  }

  location /images {
   rewrite /images/(.*) /pics/$1;
  }

  location /pics {
   rewrite /pics/(.*) /photos/$1;
  }

  location /photos {

  }
}

鎸夌収杩欎釜閰嶇疆鎴戜滑鏉ュ垎鏋愶細

  • 褰撹闂?nbsp; fe.lion.club/search 鏃讹紝浼氳嚜鍔ㄥ府鎴戜滑閲嶅畾鍚戝埌  https://www.baidu.com銆?
  • 褰撹闂?nbsp; fe.lion.club/images/1.jpg 鏃讹紝绗竴姝ラ噸鍐?nbsp; URL 涓?nbsp; fe.lion.club/pics/1.jpg 锛屾壘鍒?nbsp; pics 鐨?nbsp; location 锛岀户缁噸鍐?nbsp; URL 涓?nbsp; fe.lion.club/photos/1.jpg锛屾壘鍒?nbsp; /photos 鐨?nbsp; location 鍚庯紝鍘?nbsp; html/photos 鐩綍涓嬪鎵?nbsp; 1.jpg 闈欐€佽祫婧愩€?

if 鎸囦护

璇硶锛?span class="mq-583">if (condition) {...}

涓婁笅鏂囷細server銆乴ocation

绀轰緥锛?br>if($http_user_agent ~ Chrome){
  rewrite /(.*)/browser/$1 break;
}

condition 鍒ゆ柇鏉′欢锛?/p>

  • $variable 浠呬负鍙橀噺鏃讹紝鍊间负绌烘垨浠?寮€澶村瓧绗︿覆閮戒細琚綋鍋?nbsp; false 澶勭悊锛?
  • = 鎴?nbsp; != 鐩哥瓑鎴栦笉绛夛紱
  • ~ 姝e垯鍖归厤锛?
  • ! ~ 闈炴鍒欏尮閰嶏紱
  • ~* 姝e垯鍖归厤锛屼笉鍖哄垎澶у皬鍐欙紱
  • -f 鎴?nbsp; ! -f 妫€娴嬫枃浠跺瓨鍦ㄦ垨涓嶅瓨鍦紱
  • -d 鎴?nbsp; ! -d 妫€娴嬬洰褰曞瓨鍦ㄦ垨涓嶅瓨鍦紱
  • -e 鎴?nbsp; ! -e 妫€娴嬫枃浠躲€佺洰褰曘€佺鍙烽摼鎺ョ瓑瀛樺湪鎴栦笉瀛樺湪锛?
  • -x 鎴?nbsp; ! -x 妫€娴嬫枃浠跺彲浠ユ墽琛屾垨涓嶅彲鎵ц锛?

瀹炰緥锛?/p>

server {
  listen 8080;
  server_name localhost;
  root html;

  location / {
   if ( $uri = "/images/" ){
     rewrite (.*) /pics/ break;
    }
  }
}

褰撹闂?nbsp;localhost:8080/images/ 鏃讹紝浼氳繘鍏?nbsp;if 鍒ゆ柇閲岄潰鎵ц rewrite 鍛戒护銆?/p>

autoindex

鐢ㄦ埛璇锋眰浠?nbsp;/ 缁撳熬鏃讹紝鍒楀嚭鐩綍缁撴瀯锛屽彲浠ョ敤浜庡揩閫熸惌寤洪潤鎬佽祫婧愪笅杞界綉绔欍€?/p>

autoindex.conf 閰嶇疆淇℃伅锛?/p>

server {
  listen 80;
  server_name fe.lion-test.club;

  location /download/ {
    root /opt/source;

    autoindex on; # 鎵撳紑 autoindex锛岋紝鍙€夊弬鏁版湁 on | off
    autoindex_exact_size on; # 淇敼涓簅ff锛屼互KB銆丮B銆丟B鏄剧ず鏂囦欢澶у皬锛岄粯璁や负on锛屼互bytes鏄剧ず鍑衡絺浠剁殑纭垏饧も缉
    autoindex_format html; # 浠tml鐨勬柟寮忚繘琛屾牸寮忓寲锛屽彲閫夊弬鏁版湁 html | json | xml
    autoindex_localtime off; # 鏄剧ず鐨勨絺浠舵椂闂翠负饨備欢鐨勬湇鍔″櫒鏃堕棿銆傞粯璁や负off锛屾樉绀虹殑饨備欢鏃堕棿涓篏MT鏃堕棿
  }
}

褰撹闂?nbsp;fe.lion.com/download/ 鏃讹紝浼氭妸鏈嶅姟鍣?nbsp;/opt/source/download/ 璺緞涓嬬殑鏂囦欢灞曠ず鍑烘潵锛屽涓嬪浘鎵€绀猴細

2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?> 
</figure> 
<h2 data-tool=鍙橀噺

Nginx 鎻愪緵缁欎娇鐢ㄨ€呯殑鍙橀噺闈炲父澶氾紝浣嗘槸缁堢┒鏄竴涓畬鏁寸殑璇锋眰杩囩▼鎵€浜х敓鏁版嵁锛?nbsp;Nginx 灏嗚繖浜涙暟鎹互鍙橀噺鐨勫舰寮忔彁渚涚粰浣跨敤鑰呫€?/p>

涓嬮潰鍒椾妇浜涢」鐩腑甯哥敤鐨勫彉閲忥細

鍙橀噺鍚?/th> 鍚箟
remote_addr 瀹㈡埛绔?nbsp;IP 鍦板潃
remote_port 瀹㈡埛绔鍙?/td>
server_addr 鏈嶅姟绔?nbsp;IP 鍦板潃
server_port 鏈嶅姟绔鍙?/td>
server_protocol 鏈嶅姟绔崗璁?/td>
binary_remote_addr 浜岃繘鍒舵牸寮忕殑瀹㈡埛绔?nbsp;IP 鍦板潃
connection TCP 杩炴帴鐨勫簭鍙凤紝閫掑
connection_request TCP 杩炴帴褰撳墠鐨勮姹傛暟閲?/td>
uri 璇锋眰鐨刄RL锛屼笉鍖呭惈鍙傛暟
request_uri 璇锋眰鐨刄RL锛屽寘鍚弬鏁?/td>
scheme 鍗忚鍚嶏紝 http 鎴?nbsp;https
request_method 璇锋眰鏂规硶
request_length 鍏ㄩ儴璇锋眰鐨勯暱搴︼紝鍖呭惈璇锋眰琛屻€佽姹傚ご銆佽姹備綋
args 鍏ㄩ儴鍙傛暟瀛楃涓?/td>
arg_鍙傛暟鍚?/code> 鑾峰彇鐗瑰畾鍙傛暟鍊?/td>
is_args URL 涓槸鍚︽湁鍙傛暟锛屾湁鐨勮瘽杩斿洖 ? 锛屽惁鍒欒繑鍥炵┖
query_string 涓?nbsp;args 鐩稿悓
host 璇锋眰淇℃伅涓殑 Host 锛屽鏋滆姹備腑娌℃湁 Host 琛岋紝鍒欏湪璇锋眰澶翠腑鎵撅紝鏈€鍚庝娇鐢?nbsp;nginx 涓缃殑 server_name 銆?/td>
http_user_agent 鐢ㄦ埛娴忚鍣?/td>
http_referer 浠庡摢浜涢摼鎺ヨ繃鏉ョ殑璇锋眰
http_via 姣忕粡杩囦竴灞備唬鐞嗘湇鍔″櫒锛岄兘浼氭坊鍔犵浉搴旂殑淇℃伅
http_cookie 鑾峰彇鐢ㄦ埛 cookie
request_time 澶勭悊璇锋眰宸叉秷鑰楃殑鏃堕棿
https 鏄惁寮€鍚簡 https 锛屾槸鍒欒繑鍥?nbsp;on 锛屽惁鍒欒繑鍥炵┖
request_filename 纾佺洏鏂囦欢绯荤粺寰呰闂枃浠剁殑瀹屾暣璺緞
document_root 鐢?nbsp;URI 鍜?nbsp;root/alias 瑙勫垯鐢熸垚鐨勬枃浠跺す璺緞
limit_rate 杩斿洖鍝嶅簲鏃剁殑閫熷害涓婇檺鍊?/td>

瀹炰緥婕旂ず var.conf 锛?/p>

server{
 listen 8081;
 server_name var.lion-test.club;
 root /usr/share/nginx/html;
 location / {
  return 200 "
remote_addr: $remote_addr
remote_port: $remote_port
server_addr: $server_addr
server_port: $server_port
server_protocol: $server_protocol
binary_remote_addr: $binary_remote_addr
connection: $connection
uri: $uri
request_uri: $request_uri
scheme: $scheme
request_method: $request_method
request_length: $request_length
args: $args
arg_pid: $arg_pid
is_args: $is_args
query_string: $query_string
host: $host
http_user_agent: $http_user_agent
http_referer: $http_referer
http_via: $http_via
request_time: $request_time
https: $https
request_filename: $request_filename
document_root: $document_root
"
;
 }
}

褰撴垜浠闂?nbsp;http://var.lion-test.club:8081/test?pid=121414&cid=sadasd 鏃讹紝鐢变簬 Nginx 涓啓浜?nbsp;return 鏂规硶锛屽洜姝?nbsp;chrome 娴忚鍣ㄤ細榛樿涓烘垜浠笅杞戒竴涓枃浠讹紝涓嬮潰灞曠ず鐨勫氨鏄笅杞界殑鏂囦欢鍐呭锛?/p>

remote_addr: 27.16.220.84
remote_port: 56838
server_addr: 172.17.0.2
server_port: 8081
server_protocol: HTTP/1.1
binary_remote_addr: 鑼?br>connection: 126
uri: /test/
request_uri: /test/?pid=121414&cid=sadasd
scheme: http
request_method: GET
request_length: 518
args: pid=121414&cid=sadasd
arg_pid: 121414
is_args: ?
query_string: pid=121414&cid=sadasd
host: var.lion-test.club
http_user_agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36
http_referer:
http_via:
request_time: 0.000
https:
request_filename: /usr/share/nginx/html/test/
document_root: /usr/share/nginx/html

Nginx 鐨勯厤缃繕鏈夐潪甯稿锛屼互涓婂彧鏄綏鍒椾簡涓€浜涘父鐢ㄧ殑閰嶇疆锛屽湪瀹為檯椤圭洰涓繕鏄瀛︿細鏌ラ槄鏂囨。銆?/p>

Nginx 搴旂敤鏍稿績姒傚康

浠g悊鏄湪鏈嶅姟鍣ㄥ拰瀹㈡埛绔箣闂村亣璁剧殑涓€灞傛湇鍔″櫒锛屼唬鐞嗗皢鎺ユ敹瀹㈡埛绔殑璇锋眰骞跺皢瀹冭浆鍙戠粰鏈嶅姟鍣紝鐒跺悗灏嗘湇鍔$鐨勫搷搴旇浆鍙戠粰瀹㈡埛绔€?/p>

涓嶇鏄鍚戜唬鐞嗚繕鏄弽鍚戜唬鐞嗭紝瀹炵幇鐨勯兘鏄笂闈㈢殑鍔熻兘銆?/p>

2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?> 
</figure> 
<h2 data-tool=姝e悜浠g悊

姝e悜浠g悊锛屾剰鎬濇槸涓€涓綅浜庡鎴风鍜屽師濮嬫湇鍔″櫒(origin server)涔嬮棿鐨勬湇鍔″櫒锛屼负浜嗕粠鍘熷鏈嶅姟鍣ㄥ彇寰楀唴瀹癸紝瀹㈡埛绔悜浠g悊鍙戦€佷竴涓姹傚苟鎸囧畾鐩爣(鍘熷鏈嶅姟鍣?锛岀劧鍚庝唬鐞嗗悜鍘熷鏈嶅姟鍣ㄨ浆浜よ姹傚苟灏嗚幏寰楃殑鍐呭杩斿洖缁欏鎴风銆?/p>

姝e悜浠g悊鏄负鎴戜滑鏈嶅姟鐨勶紝鍗充负瀹㈡埛绔湇鍔$殑锛屽鎴风鍙互鏍规嵁姝e悜浠g悊璁块棶鍒板畠鏈韩鏃犳硶璁块棶鍒扮殑鏈嶅姟鍣ㄨ祫婧愩€?/p>

姝e悜浠g悊瀵规垜浠槸閫忔槑鐨勶紝瀵规湇鍔$鏄潪閫忔槑鐨勶紝鍗虫湇鍔$骞朵笉鐭ラ亾鑷繁鏀跺埌鐨勬槸鏉ヨ嚜浠g悊鐨勮闂繕鏄潵鑷湡瀹炲鎴风鐨勮闂€?/p>

鍙嶅悜浠g悊

  • 鍙嶅悜浠g悊*锛圧everse Proxy锛夋柟寮忔槸鎸囦互浠g悊鏈嶅姟鍣ㄦ潵鎺ュ彈internet涓婄殑杩炴帴璇锋眰锛岀劧鍚庡皢璇锋眰杞彂缁欏唴閮ㄧ綉缁滀笂鐨勬湇鍔″櫒锛屽苟灏嗕粠鏈嶅姟鍣ㄤ笂寰楀埌鐨勭粨鏋滆繑鍥炵粰internet涓婅姹傝繛鎺ョ殑瀹㈡埛绔紝姝ゆ椂浠g悊鏈嶅姟鍣ㄥ澶栧氨琛ㄧ幇涓轰竴涓弽鍚戜唬鐞嗘湇鍔″櫒銆?

鍙嶅悜浠g悊鏄负鏈嶅姟绔湇鍔$殑锛屽弽鍚戜唬鐞嗗彲浠ュ府鍔╂湇鍔″櫒鎺ユ敹鏉ヨ嚜瀹㈡埛绔殑璇锋眰锛屽府鍔╂湇鍔″櫒鍋氳姹傝浆鍙戯紝璐熻浇鍧囪 绛夈€?/p>

鍙嶅悜浠g悊瀵规湇鍔$鏄€忔槑鐨勶紝瀵规垜浠槸闈為€忔槑鐨勶紝鍗虫垜浠苟涓嶇煡閬撹嚜宸辫闂殑鏄唬鐞嗘湇鍔″櫒锛岃€屾湇鍔″櫒鐭ラ亾鍙嶅悜浠g悊鍦ㄤ负浠栨湇鍔°€?/p>

鍙嶅悜浠g悊鐨勪紭鍔匡細

  • 闅愯棌鐪熷疄鏈嶅姟鍣紱
  • 璐熻浇鍧囪 渚夸簬妯悜鎵╁厖鍚庣鍔ㄦ€佹湇鍔★紱
  • 鍔ㄩ潤鍒嗙锛屾彁鍗囩郴缁熷仴澹€э紱

閭d箞鈥滃姩闈欏垎绂烩€濇槸浠€涔堬紵璐熻浇鍧囪 鍙堟槸浠€涔堬紵

鍔ㄩ潤鍒嗙

鍔ㄩ潤鍒嗙鏄寚鍦?nbsp;web 鏈嶅姟鍣ㄦ灦鏋勪腑锛屽皢闈欐€侀〉闈笌鍔ㄦ€侀〉闈㈡垨鑰呴潤鎬佸唴瀹规帴鍙e拰鍔ㄦ€佸唴瀹规帴鍙e垎寮€涓嶅悓绯荤粺璁块棶鐨勬灦鏋勮璁℃柟娉曪紝杩涜€屾彁绀烘暣涓湇鍔$殑璁块棶鎬у拰鍙淮鎶ゆ€с€?/p>

2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?> 
</figure> 
<p data-tool=涓€鑸潵璇达紝閮介渶瑕佸皢鍔ㄦ€佽祫婧愬拰闈欐€佽祫婧愬垎寮€锛岀敱浜?nbsp;Nginx 鐨勯珮骞跺彂鍜岄潤鎬佽祫婧愮紦瀛樼瓑鐗规€э紝缁忓父灏嗛潤鎬佽祫婧愰儴缃插湪 Nginx 涓娿€傚鏋滆姹傜殑鏄潤鎬佽祫婧愶紝鐩存帴鍒伴潤鎬佽祫婧愮洰褰曡幏鍙栬祫婧愶紝濡傛灉鏄姩鎬佽祫婧愮殑璇锋眰锛屽垯鍒╃敤鍙嶅悜浠g悊鐨勫師鐞嗭紝鎶婅姹傝浆鍙戠粰瀵瑰簲鍚庡彴搴旂敤鍘诲鐞嗭紝浠庤€屽疄鐜板姩闈欏垎绂汇€?/p>

浣跨敤鍓嶅悗绔垎绂诲悗锛屽彲浠ュ緢澶х▼搴︽彁鍗囬潤鎬佽祫婧愮殑璁块棶閫熷害锛屽嵆浣垮姩鎬佹湇鍔′笉鍙敤锛岄潤鎬佽祫婧愮殑璁块棶涔熶笉浼氬彈鍒板奖鍝嶃€?/p>

璐熻浇鍧囪 

涓€鑸儏鍐典笅锛屽鎴风鍙戦€佸涓姹傚埌鏈嶅姟鍣紝鏈嶅姟鍣ㄥ鐞嗚姹傦紝鍏朵腑涓€閮ㄥ垎鍙兘瑕佹搷浣滀竴浜涜祫婧愭瘮濡傛暟鎹簱銆侀潤鎬佽祫婧愮瓑锛屾湇鍔″櫒澶勭悊瀹屾瘯鍚庯紝鍐嶅皢缁撴灉杩斿洖缁欏鎴风銆?/p>

杩欑妯″紡瀵逛簬鏃╂湡鐨勭郴缁熸潵璇达紝鍔熻兘瑕佹眰涓嶅鏉傦紝涓斿苟鍙戣姹傜浉瀵硅緝灏戠殑鎯呭喌涓嬭繕鑳借儨浠伙紝鎴愭湰涔熶綆銆傞殢鐫€淇℃伅鏁伴噺涓嶆柇澧為暱锛岃闂噺鍜屾暟鎹噺椋為€熷闀匡紝浠ュ強绯荤粺涓氬姟澶嶆潅搴︽寔缁鍔狅紝杩欑鍋氭硶宸叉棤娉曟弧瓒宠姹傦紝骞跺彂閲忕壒鍒ぇ鏃讹紝鏈嶅姟鍣ㄥ鏄撳穿銆?/p>

寰堟槑鏄捐繖鏄敱浜庢湇鍔″櫒鎬ц兘鐨勭摱棰堥€犳垚鐨勯棶棰橈紝闄や簡鍫嗘満鍣ㄤ箣澶栵紝鏈€閲嶈鐨勫仛娉曞氨鏄礋杞藉潎琛°€?/p>

璇锋眰鐖嗗彂寮忓闀跨殑鎯呭喌涓嬶紝鍗曚釜鏈哄櫒鎬ц兘鍐嶅己鍔蹭篃鏃犳硶婊¤冻瑕佹眰浜嗭紝杩欎釜鏃跺€欓泦缇ょ殑姒傚康浜х敓浜嗭紝鍗曚釜鏈嶅姟鍣ㄨВ鍐充笉浜嗙殑闂锛屽彲浠ヤ娇鐢ㄥ涓湇鍔″櫒锛岀劧鍚庡皢璇锋眰鍒嗗彂鍒板悇涓湇鍔″櫒涓婏紝灏嗚礋杞藉垎鍙戝埌涓嶅悓鐨勬湇鍔″櫒锛岃繖灏辨槸璐熻浇鍧囪 锛屾牳蹇冩槸銆屽垎鎽婂帇鍔涖€嶃€?nbsp;Nginx 瀹炵幇璐熻浇鍧囪 锛屼竴鑸潵璇存寚鐨勬槸灏嗚姹傝浆鍙戠粰鏈嶅姟鍣ㄩ泦缇ゃ€?/p>

涓句釜鍏蜂綋鐨勪緥瀛愶紝鏅氶珮宄颁箻鍧愬湴閾佺殑鏃跺€欙紝鍏ョ珯鍙g粡甯镐細鏈夊湴閾佸伐浣滀汉鍛樺ぇ鍠囧彮鈥滆璧?nbsp;B鍙o紝 B 鍙d汉灏戣溅绌?...鈥濓紝杩欎釜宸ヤ綔浜哄憳鐨勪綔鐢ㄥ氨鏄礋杞藉潎琛°€?img data-ratio="0.5673575129533679" src="/img?url=https://mmbiz.qpic.cn/mmbiz_png/JdLkEI9sZff0RM5qHt0MV3iaJfwWLdFzKMoic3wYD18VEQWBHRSHmEtUzkn1r68dl8yuHjhVv5s6Tg6L0E1NquuA/640?wx_fmt=png" data-type="png" data-w="772" _width="368px" class="mq-881" alt="2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?>

Nginx 瀹炵幇璐熻浇鍧囪 鐨勭瓥鐣ワ細

  • 杞绛栫暐锛氶粯璁ゆ儏鍐典笅閲囩敤鐨勭瓥鐣ワ紝灏嗘墍鏈夊鎴风璇锋眰杞鍒嗛厤缁欐湇鍔$銆傝繖绉嶇瓥鐣ユ槸鍙互姝e父宸ヤ綔鐨勶紝浣嗘槸濡傛灉鍏朵腑鏌愪竴鍙版湇鍔″櫒鍘嬪姏澶ぇ锛屽嚭鐜板欢杩燂紝浼氬奖鍝嶆墍鏈夊垎閰嶅湪杩欏彴鏈嶅姟鍣ㄤ笅鐨勭敤鎴枫€?
  • 鏈€灏忚繛鎺ユ暟绛栫暐锛氬皢璇锋眰浼樺厛鍒嗛厤缁欏帇鍔涜緝灏忕殑鏈嶅姟鍣紝瀹冨彲浠ュ钩琛℃瘡涓槦鍒楃殑闀垮害锛屽苟閬垮厤鍚戝帇鍔涘ぇ鐨勬湇鍔″櫒娣诲姞鏇村鐨勮姹傘€?
  • 鏈€蹇搷搴旀椂闂寸瓥鐣ワ細浼樺厛鍒嗛厤缁欏搷搴旀椂闂存渶鐭殑鏈嶅姟鍣ㄣ€?
  • 瀹㈡埛绔?nbsp; ip 缁戝畾绛栫暐锛氭潵鑷悓涓€涓?nbsp; ip 鐨勮姹傛案杩滃彧鍒嗛厤涓€鍙版湇鍔″櫒锛屾湁鏁堣В鍐充簡鍔ㄦ€佺綉椤靛瓨鍦ㄧ殑  session 鍏变韩闂銆?

Nginx 瀹炴垬閰嶇疆

鍦ㄩ厤缃弽鍚戜唬鐞嗗拰璐熻浇鍧囪 绛夌瓑鍔熻兘涔嬪墠锛屾湁涓や釜鏍稿績妯″潡鏄垜浠繀椤昏鎺屾彙鐨勶紝杩欎袱涓ā鍧楀簲璇ヨ鏄?nbsp;Nginx 搴旂敤閰嶇疆涓殑鏍稿績锛屽畠浠垎鍒槸锛?nbsp;upstream 銆?code class="mq-898">proxy_pass 銆?/p>

upstream

鐢ㄤ簬瀹氫箟涓婃父鏈嶅姟鍣紙鎸囩殑灏辨槸鍚庡彴鎻愪緵鐨勫簲鐢ㄦ湇鍔″櫒锛夌殑鐩稿叧淇℃伅銆?/p>

2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?> 
</figure> 
<pre data-tool=璇硶锛歶pstream name { ...}涓婁笅鏂囷細http绀轰緥锛歶pstream back_end_server{  server 192.168.100.33:8081}澶嶅埗浠g爜

鍦?nbsp;upstream 鍐呭彲浣跨敤鐨勬寚浠わ細

  • server 瀹氫箟涓婃父鏈嶅姟鍣ㄥ湴鍧€锛?
  • zone 瀹氫箟鍏变韩鍐呭瓨锛岀敤浜庤法  worker 瀛愯繘绋嬶紱
  • keepalive 瀵逛笂娓告湇鍔″惎鐢ㄩ暱杩炴帴锛?
  • keepalive_requests 涓€涓暱杩炴帴鏈€澶氳姹?nbsp; HTTP 鐨勪釜鏁帮紱
  • keepalive_timeout 绌洪棽鎯呭舰涓嬶紝涓€涓暱杩炴帴鐨勮秴鏃舵椂闀匡紱
  • hash 鍝堝笇璐熻浇鍧囪 绠楁硶锛?
  • ip_hash 渚濇嵁  IP 杩涜鍝堝笇璁$畻鐨勮礋杞藉潎琛$畻娉曪紱
  • least_conn 鏈€灏戣繛鎺ユ暟璐熻浇鍧囪 绠楁硶锛?
  • least_time 鏈€鐭搷搴旀椂闂磋礋杞藉潎琛$畻娉曪紱
  • random 闅忔満璐熻浇鍧囪 绠楁硶锛?

server

璇硶锛歴erver address [parameters]

涓婁笅鏂囷細upstream

parameters 鍙€夊€硷細

  • weight=number 鏉冮噸鍊硷紝榛樿涓?锛?
  • max_conns=number 涓婃父鏈嶅姟鍣ㄧ殑鏈€澶у苟鍙戣繛鎺ユ暟锛?
  • fail_timeout=time 鏈嶅姟鍣ㄤ笉鍙敤鐨勫垽瀹氭椂闂达紱
  • max_fails=numer 鏈嶅姟鍣ㄤ笉鍙敤鐨勬鏌ユ鏁帮紱
  • backup 澶囦唤鏈嶅姟鍣紝浠呭綋鍏朵粬鏈嶅姟鍣ㄩ兘涓嶅彲鐢ㄦ椂鎵嶄細鍚敤锛?
  • down 鏍囪鏈嶅姟鍣ㄩ暱鏈熶笉鍙敤锛岀绾跨淮鎶わ紱

keepalive

闄愬埗姣忎釜 worker 瀛愯繘绋嬩笌涓婃父鏈嶅姟鍣ㄧ┖闂查暱杩炴帴鐨勬渶澶ф暟閲忋€?/p>

keepalive connections;

涓婁笅鏂囷細upstream

绀轰緥锛歬eepalive 16;

keepalive_requests

鍗曚釜闀胯繛鎺ュ彲浠ュ鐞嗙殑鏈€澶?nbsp;HTTP 璇锋眰涓暟銆?/p>

璇硶锛歬eepalive_requests number;

榛樿鍊硷細keepalive_requests 100;

涓婁笅鏂囷細upstream

keepalive_timeout

绌洪棽闀胯繛鎺ョ殑鏈€闀夸繚鎸佹椂闂淬€?/p>

璇硶锛歬eepalive_timeout time;榛樿鍊硷細keepalive_timeout 60s;涓婁笅鏂囷細upstream澶嶅埗浠g爜

閰嶇疆瀹炰緥

upstream back_end{
 server 127.0.0.1:8081 weight=3 max_conns=1000 fail_timeout=10s max_fails=2;
  keepalive 32;
  keepalive_requests 50;
  keepalive_timeout 30s;
}

proxy_pass

鐢ㄤ簬閰嶇疆浠g悊鏈嶅姟鍣ㄣ€?/p>

璇硶锛歱roxy_pass URL;

涓婁笅鏂囷細location銆?span class="mq-981">if銆乴imit_except

绀轰緥锛?br>proxy_pass http://127.0.0.1:8081
proxy_pass http://127.0.0.1:8081/proxy

URL 鍙傛暟鍘熷垯

  1. URL 蹇呴』浠?nbsp; http 鎴?nbsp; https 寮€澶达紱
  2. URL 涓彲浠ユ惡甯﹀彉閲忥紱
  3. URL 涓槸鍚﹀甫  URI 锛屼細鐩存帴褰卞搷鍙戝線涓婃父璇锋眰鐨?nbsp; URL 锛?

鎺ヤ笅鏉ヨ鎴戜滑鏉ョ湅鐪嬩袱绉嶅父瑙佺殑 URL 鐢ㄦ硶锛?/p>

  1. proxy_pass http://192.168.100.33:8081
  2. proxy_pass http://192.168.100.33:8081/

杩欎袱绉嶇敤娉曠殑鍖哄埆灏辨槸甯?nbsp;/ 鍜屼笉甯?nbsp;/ 锛屽湪閰嶇疆浠g悊鏃跺畠浠殑鍖哄埆鍙ぇ浜嗭細

  • 涓嶅甫  / 鎰忓懗鐫€  Nginx 涓嶄細淇敼鐢ㄦ埛  URL 锛岃€屾槸鐩存帴閫忎紶缁欎笂娓哥殑搴旂敤鏈嶅姟鍣紱
  • 甯?nbsp; / 鎰忓懗鐫€  Nginx 浼氫慨鏀圭敤鎴?nbsp; URL 锛屼慨鏀规柟娉曟槸灏?nbsp; location 鍚庣殑  URL 浠庣敤鎴?nbsp; URL 涓垹闄わ紱

涓嶅甫 / 鐨勭敤娉曪細

location /bbs/{
  proxy_pass http://127.0.0.1:8080;
}

鍒嗘瀽锛?/p>

  1. 鐢ㄦ埛璇锋眰  URL 锛?nbsp; /bbs/abc/test.html
  2. 璇锋眰鍒拌揪  Nginx 鐨?nbsp; URL 锛?nbsp; /bbs/abc/test.html
  3. 璇锋眰鍒拌揪涓婃父搴旂敤鏈嶅姟鍣ㄧ殑  URL 锛?nbsp; /bbs/abc/test.html

甯?nbsp;/ 鐨勭敤娉曪細

location /bbs/{
  proxy_pass http://127.0.0.1:8080/;
}

鍒嗘瀽锛?/p>

  1. 鐢ㄦ埛璇锋眰  URL 锛?nbsp; /bbs/abc/test.html
  2. 璇锋眰鍒拌揪  Nginx 鐨?nbsp; URL 锛?nbsp; /bbs/abc/test.html
  3. 璇锋眰鍒拌揪涓婃父搴旂敤鏈嶅姟鍣ㄧ殑  URL 锛?nbsp; /abc/test.html

骞舵病鏈夋嫾鎺ヤ笂 /bbs 锛岃繖鐐瑰拰 root 涓?nbsp;alias 涔嬮棿鐨勫尯鍒槸淇濇寔涓€鑷寸殑銆?/p>

閰嶇疆鍙嶅悜浠g悊

杩欓噷涓轰簡婕旂ず鏇村姞鎺ヨ繎瀹為檯锛屼綔鑰呭噯澶囦簡涓ゅ彴浜戞湇鍔″櫒锛屽畠浠殑鍏綉 IP 鍒嗗埆鏄細 121.42.11.34 涓?nbsp;121.5.180.193 銆?/p>

鎴戜滑鎶?nbsp;121.42.11.34 鏈嶅姟鍣ㄤ綔涓轰笂娓告湇鍔″櫒锛屽仛濡備笅閰嶇疆锛?/p>

# /etc/nginx/conf.d/proxy.conf
server{
  listen 8080;
  server_name localhost;

  location /proxy/ {
    root /usr/share/nginx/html/proxy;
    index index.html;
  }
}

# /usr/share/nginx/html/proxy/index.html
<h1> 121.42.11.34 proxy html </h1>

閰嶇疆瀹屾垚鍚庨噸鍚?nbsp;Nginx 鏈嶅姟鍣?nbsp;nginx -s reload 銆?/p>

鎶?nbsp;121.5.180.193 鏈嶅姟鍣ㄤ綔涓轰唬鐞嗘湇鍔″櫒锛屽仛濡備笅閰嶇疆锛?/p>

# /etc/nginx/conf.d/proxy.conf
upstream back_end {
  server 121.42.11.34:8080 weight=2 max_conns=1000 fail_timeout=10s max_fails=3;
  keepalive 32;
  keepalive_requests 80;
  keepalive_timeout 20s;
}

server {
  listen 80;
  server_name proxy.lion.club;
  location /proxy {
   proxy_pass http://back_end/proxy;
  }
}

鏈湴鏈哄櫒瑕佽闂?nbsp;proxy.lion.club 鍩熷悕锛屽洜姝ら渶瑕侀厤缃湰鍦?nbsp;hosts 锛岄€氳繃鍛戒护锛?code class="mq-1081">vim /etc/hosts 杩涘叆閰嶇疆鏂囦欢锛屾坊鍔犲涓嬪唴瀹癸細

121.5.180.193 proxy.lion.club

2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?> 
</figure> 
<p data-tool=鍒嗘瀽锛?/p>
  1. 褰撹闂?nbsp; proxy.lion.club/proxy 鏃堕€氳繃  upstream 鐨勯厤缃壘鍒?nbsp; 121.42.11.34:8080锛?
  2. 鍥犳璁块棶鍦板潃鍙樹负  http://121.42.11.34:8080/proxy 锛?
  3. 杩炴帴鍒?nbsp; 121.42.11.34 鏈嶅姟鍣紝鎵惧埌  8080 绔彛鎻愪緵鐨?nbsp; server 锛?
  4. 閫氳繃  server 鎵惧埌  /usr/share/nginx/html/proxy/index.html 璧勬簮锛屾渶缁堝睍绀哄嚭鏉ャ€?

閰嶇疆璐熻浇鍧囪 

閰嶇疆璐熻浇鍧囪 涓昏鏄浣跨敤 upstream 鎸囦护銆?/p>

鎴戜滑鎶?nbsp;121.42.11.34 鏈嶅姟鍣ㄤ綔涓轰笂娓告湇鍔″櫒锛屽仛濡備笅閰嶇疆锛?nbsp;/etc/nginx/conf.d/balance.conf 锛夛細

server{
  listen 8020;
  location / {
   return 200 'return 8020 \n';
  }
}

server{
  listen 8030;
  location / {
   return 200 'return 8030 \n';
  }
}

server{
  listen 8040;
  location / {
   return 200 'return 8040 \n';
  }
}

閰嶇疆瀹屾垚鍚庯細

  1. nginx -t 妫€娴嬮厤缃槸鍚︽纭紱
  2. nginx -s reload 閲嶅惎  Nginx 鏈嶅姟鍣紱
  3. 鎵ц  ss -nlt 鍛戒护鏌ョ湅绔彛鏄惁琚崰鐢紝浠庤€屽垽鏂?nbsp; Nginx 鏈嶅姟鏄惁姝g‘鍚姩銆?

鎶?nbsp;121.5.180.193 鏈嶅姟鍣ㄤ綔涓轰唬鐞嗘湇鍔″櫒锛屽仛濡備笅閰嶇疆锛?nbsp;/etc/nginx/conf.d/balance.conf 锛夛細

upstream demo_server {
  server 121.42.11.34:8020;
  server 121.42.11.34:8030;
  server 121.42.11.34:8040;
}

server {
  listen 80;
  server_name balance.lion.club;

  location /balance/ {
   proxy_pass http://demo_server;
  }
}

閰嶇疆瀹屾垚鍚庨噸鍚?nbsp;Nginx 鏈嶅姟鍣ㄣ€傚苟涓斿湪闇€瑕佽闂殑瀹㈡埛绔厤缃ソ ip 鍜屽煙鍚嶇殑鏄犲皠鍏崇郴銆?/p>

# /etc/hosts

121.5.180.193 balance.lion.club

鍦ㄥ鎴风鏈哄櫒鎵ц curl http://balance.lion.club/balance/ 鍛戒护锛?/p>

2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?> 
</figure> 
<p data-tool=涓嶉毦鐪嬪嚭锛岃礋杞藉潎琛$殑閰嶇疆宸茬粡鐢熸晥浜嗭紝姣忔缁欐垜浠垎鍙戠殑涓婃父鏈嶅姟鍣ㄩ兘涓嶄竴鏍枫€傚氨鏄€氳繃绠€鍗曠殑杞绛栫暐杩涜涓婃父鏈嶅姟鍣ㄥ垎鍙戙€?/p>

鎺ヤ笅鏉ワ紝鎴戜滑鍐嶆潵浜嗚В涓?nbsp;Nginx 鐨勫叾瀹冨垎鍙戠瓥鐣ャ€?/p>

hash 绠楁硶

閫氳繃鍒跺畾鍏抽敭瀛椾綔涓?nbsp;hash key 锛屽熀浜?nbsp;hash 绠楁硶鏄犲皠鍒扮壒瀹氱殑涓婃父鏈嶅姟鍣ㄤ腑銆傚叧閿瓧鍙互鍖呭惈鏈夊彉閲忋€佸瓧绗︿覆銆?/p>

upstream demo_server {
  hash $request_uri;
  server 121.42.11.34:8020;
  server 121.42.11.34:8030;
  server 121.42.11.34:8040;
}

server {
  listen 80;
  server_name balance.lion.club;

  location /balance/ {
   proxy_pass http://demo_server;
  }
}

hash $request_uri 琛ㄧず浣跨敤 request_uri 鍙橀噺浣滀负 hash 鐨?nbsp;key 鍊硷紝鍙璁块棶鐨?nbsp;URI 淇濇寔涓嶅彉锛屽氨浼氫竴鐩村垎鍙戠粰鍚屼竴鍙版湇鍔″櫒銆?/p>

ip_hash

upstream demo_server {
  ip_hash;
  server 121.42.11.34:8020;
  server 121.42.11.34:8030;
  server 121.42.11.34:8040;
}

server {
  listen 80;
  server_name balance.lion.club;

  location /balance/ {
   proxy_pass http://demo_server;
  }
}

鏈€灏戣繛鎺ユ暟绠楁硶

鍚勪釜 worker 瀛愯繘绋嬮€氳繃璇诲彇鍏变韩鍐呭瓨鐨勬暟鎹紝鏉ヨ幏鍙栧悗绔湇鍔″櫒鐨勪俊鎭€傛潵鎸戦€変竴鍙板綋鍓嶅凡寤虹珛杩炴帴鏁版渶灏戠殑鏈嶅姟鍣ㄨ繘琛屽垎閰嶈姹傘€?/p>

璇硶锛歭east_conn;

涓婁笅鏂囷細upstream;

绀轰緥锛?/p>

upstream demo_server {
  zone test 10M; # zone鍙互璁剧疆鍏变韩鍐呭瓨绌洪棿鐨勫悕瀛楀拰澶у皬
  least_conn;
  server 121.42.11.34:8020;
  server 121.42.11.34:8030;
  server 121.42.11.34:8040;
}

server {
  listen 80;
  server_name balance.lion.club;

  location /balance/ {
   proxy_pass http://demo_server;
  }
}

鏈€鍚庝綘浼氬彂鐜帮紝璐熻浇鍧囪 鐨勯厤缃叾瀹炰竴鐐归兘涓嶅鏉傘€?/p>

閰嶇疆缂撳瓨

缂撳瓨鍙互闈炲父鏈夋晥鐨勬彁鍗囨€ц兘锛屽洜姝や笉璁烘槸瀹㈡埛绔紙娴忚鍣級锛岃繕鏄唬鐞嗘湇鍔″櫒锛?nbsp;Nginx锛夛紝涔冭嚦涓婃父鏈嶅姟鍣ㄩ兘澶氬皯浼氭秹鍙婂埌缂撳瓨銆傚彲瑙佺紦瀛樺湪姣忎釜鐜妭閮芥槸闈炲父閲嶈鐨勩€備笅闈㈣鎴戜滑鏉ュ涔?nbsp;Nginx 涓浣曡缃紦瀛樼瓥鐣ャ€?/p>

proxy_cache

瀛樺偍涓€浜涗箣鍓嶈璁块棶杩囥€佽€屼笖鍙兘灏嗚琚啀娆¤闂殑璧勬簮锛屼娇鐢ㄦ埛鍙互鐩存帴浠庝唬鐞嗘湇鍔″櫒鑾峰緱锛屼粠鑰屽噺灏戜笂娓告湇鍔″櫒鐨勫帇鍔涳紝鍔犲揩鏁翠釜璁块棶閫熷害銆?/p>

璇硶锛歱roxy_cache zone | off ; # zone 鏄叡浜唴瀛樼殑鍚嶇О

榛樿鍊硷細proxy_cache off;

涓婁笅鏂囷細http銆乻erver銆乴ocation

proxy_cache_path

璁剧疆缂撳瓨鏂囦欢鐨勫瓨鏀捐矾寰勩€?/p>

璇硶锛歱roxy_cache_path path [level=levels] ...鍙€夊弬鏁扮渷鐣ワ紝涓嬮潰浼氳缁嗗垪涓?br>
榛樿鍊硷細proxy_cache_path off

涓婁笅鏂囷細http

鍙傛暟鍚箟锛?/p>

  • path 缂撳瓨鏂囦欢鐨勫瓨鏀捐矾寰勶紱
  • level path 鐨勭洰褰曞眰绾э紱
  • keys_zone 璁剧疆鍏变韩鍐呭瓨锛?
  • inactive 鍦ㄦ寚瀹氭椂闂村唴娌℃湁琚闂紝缂撳瓨浼氳娓呯悊锛岄粯璁?0鍒嗛挓锛?

proxy_cache_key

璁剧疆缂撳瓨鏂囦欢鐨?nbsp;key 銆?/p>

璇硶锛歱roxy_cache_key

榛樿鍊硷細proxy_cache_key $scheme$proxy_host$request_uri;

涓婁笅鏂囷細http銆乻erver銆乴ocation

proxy_cache_valid

閰嶇疆浠€涔堢姸鎬佺爜鍙互琚紦瀛橈紝浠ュ強缂撳瓨鏃堕暱銆?/p>

璇硶锛歱roxy_cache_valid [code...] time;

涓婁笅鏂囷細http銆乻erver銆乴ocation

閰嶇疆绀轰緥锛歱roxy_cache_valid 200 304 2m;; # 璇存槑瀵逛簬鐘舵€佷负200鍜?04鐨勭紦瀛樻枃浠剁殑缂撳瓨鏃堕棿鏄?鍒嗛挓

proxy_no_cache

瀹氫箟鐩稿簲淇濆瓨鍒扮紦瀛樼殑鏉′欢锛屽鏋滃瓧绗︿覆鍙傛暟鐨勮嚦灏戜竴涓€间笉涓虹┖涓斾笉绛変簬鈥?0鈥濓紝鍒欏皢涓嶄繚瀛樿鍝嶅簲鍒扮紦瀛樸€?/p>

璇硶锛歱roxy_no_cache string;

涓婁笅鏂囷細http銆乻erver銆乴ocation

绀轰緥锛歱roxy_no_cache $http_pragma    $http_authorization;

proxy_cache_bypass

瀹氫箟鏉′欢锛屽湪璇ユ潯浠朵笅灏嗕笉浼氫粠缂撳瓨涓幏鍙栧搷搴斻€?/p>

璇硶锛歱roxy_cache_bypass string;

涓婁笅鏂囷細http銆乻erver銆乴ocation

绀轰緥锛歱roxy_cache_bypass $http_pragma    $http_authorization;

upstream_cache_status 鍙橀噺

瀹冨瓨鍌ㄤ簡缂撳瓨鏄惁鍛戒腑鐨勪俊鎭紝浼氳缃湪鍝嶅簲澶翠俊鎭腑锛屽湪璋冭瘯涓潪甯告湁鐢ㄣ€?/p>

MISS: 鏈懡涓紦瀛?br>HIT锛?nbsp;鍛戒腑缂撳瓨
EXPIRED: 缂撳瓨杩囨湡
STALE: 鍛戒腑浜嗛檲鏃х紦瀛?br>REVALIDDATED: Nginx楠岃瘉闄堟棫缂撳瓨渚濈劧鏈夋晥
UPDATING: 鍐呭闄堟棫锛屼絾姝e湪鏇存柊
BYPASS: X鍝嶅簲浠庡師濮嬫湇鍔″櫒鑾峰彇

閰嶇疆瀹炰緥

鎴戜滑鎶?nbsp;121.42.11.34 鏈嶅姟鍣ㄤ綔涓轰笂娓告湇鍔″櫒锛屽仛濡備笅閰嶇疆锛?nbsp;/etc/nginx/conf.d/cache.conf 锛夛細

server {
  listen 1010;
  root /usr/share/nginx/html/1010;
  location / {
   index index.html;
  }
}

server {
  listen 1020;
  root /usr/share/nginx/html/1020;
  location / {
   index index.html;
  }
}

鎶?nbsp;121.5.180.193 鏈嶅姟鍣ㄤ綔涓轰唬鐞嗘湇鍔″櫒锛屽仛濡備笅閰嶇疆锛?nbsp;/etc/nginx/conf.d/cache.conf 锛夛細

proxy_cache_path /etc/nginx/cache_temp levels=2:2 keys_zone=cache_zone:30m max_size=2g inactive=60m use_temp_path=off;

upstream cache_server{
  server 121.42.11.34:1010;
  server 121.42.11.34:1020;
}

server {
  listen 80;
  server_name cache.lion.club;
  location / {
    proxy_cache cache_zone; # 璁剧疆缂撳瓨鍐呭瓨锛屼笂闈㈤厤缃腑宸茬粡瀹氫箟濂界殑
    proxy_cache_valid 200 5m; # 缂撳瓨鐘舵€佷负200鐨勮姹傦紝缂撳瓨鏃堕暱涓?鍒嗛挓
    proxy_cache_key $request_uri# 缂撳瓨鏂囦欢鐨刱ey涓鸿姹傜殑URI
    add_header Nginx-Cache-Status $upstream_cache_status # 鎶婄紦瀛樼姸鎬佽缃负澶撮儴淇℃伅锛屽搷搴旂粰瀹㈡埛绔?/span>
    proxy_pass http://cache_server; # 浠g悊杞彂
  }
}

缂撳瓨灏辨槸杩欐牱閰嶇疆锛屾垜浠彲浠ュ湪 /etc/nginx/cache_temp 璺緞涓嬫壘鍒扮浉搴旂殑缂撳瓨鏂囦欢銆?/p>

瀵逛簬涓€浜涘疄鏃舵€ц姹傞潪甯搁珮鐨勯〉闈㈡垨鏁版嵁鏉ヨ锛屽氨涓嶅簲璇ュ幓璁剧疆缂撳瓨锛屼笅闈㈡潵鐪嬬湅濡備綍閰嶇疆涓嶇紦瀛樼殑鍐呭銆?/span>

...

server {
  listen 80;
  server_name cache.lion.club;
  # URI 涓悗缂€涓?nbsp;.txt 鎴?nbsp;.text 鐨勮缃彉閲忓€间负 "no cache"
  if ($request_uri ~ \.(txt|text)$) {
   set $cache_name "no cache"
  }

  location / {
    proxy_no_cache $cache_name# 鍒ゆ柇璇ュ彉閲忔槸鍚︽湁鍊硷紝濡傛灉鏈夊€煎垯涓嶈繘琛岀紦瀛橈紝濡傛灉娌℃湁鍊煎垯杩涜缂撳瓨
    proxy_cache cache_zone; # 璁剧疆缂撳瓨鍐呭瓨
    proxy_cache_valid 200 5m; # 缂撳瓨鐘舵€佷负200鐨勮姹傦紝缂撳瓨鏃堕暱涓?鍒嗛挓
    proxy_cache_key $request_uri# 缂撳瓨鏂囦欢鐨刱ey涓鸿姹傜殑URI
    add_header Nginx-Cache-Status $upstream_cache_status # 鎶婄紦瀛樼姸鎬佽缃负澶撮儴淇℃伅锛屽搷搴旂粰瀹㈡埛绔?/span>
    proxy_pass http://cache_server; # 浠g悊杞彂
  }
}

HTTPS

鍦ㄥ涔犲浣曢厤缃?nbsp;HTTPS 涔嬪墠锛屾垜浠厛鏉ョ畝鍗曞洖椤句笅 HTTPS 鐨勫伐浣滄祦绋嬫槸鎬庝箞鏍风殑锛熷畠鏄浣曡繘琛屽姞瀵嗕繚璇佸畨鍏ㄧ殑锛?/p>

HTTPS 宸ヤ綔娴佺▼

  1. 瀹㈡埛绔紙娴忚鍣級璁块棶  https://www.baidu.com 鐧惧害缃戠珯锛?
  2. 鐧惧害鏈嶅姟鍣ㄨ繑鍥?nbsp; HTTPS 浣跨敤鐨?nbsp; CA 璇佷功锛?
  3. 娴忚鍣ㄩ獙璇?nbsp; CA 璇佷功鏄惁涓哄悎娉曡瘉涔︼紱
  4. 楠岃瘉閫氳繃锛岃瘉涔﹀悎娉曪紝鐢熸垚涓€涓查殢鏈烘暟骞朵娇鐢ㄥ叕閽ワ紙璇佷功涓彁渚涚殑锛夎繘琛屽姞瀵嗭紱
  5. 鍙戦€佸叕閽ュ姞瀵嗗悗鐨勯殢鏈烘暟缁欑櫨搴︽湇鍔″櫒锛?
  6. 鐧惧害鏈嶅姟鍣ㄦ嬁鍒板瘑鏂囷紝閫氳繃绉侀挜杩涜瑙e瘑锛岃幏鍙栧埌闅忔満鏁帮紙鍏挜鍔犲瘑锛岀閽ヨВ瀵嗭紝鍙嶄箣涔熷彲浠ワ級锛?
  7. 鐧惧害鏈嶅姟鍣ㄦ妸瑕佸彂閫佺粰娴忚鍣ㄧ殑鍐呭锛屼娇鐢ㄩ殢鏈烘暟杩涜鍔犲瘑鍚庝紶杈撶粰娴忚鍣紱
  8. 姝ゆ椂娴忚鍣ㄥ彲浠ヤ娇鐢ㄩ殢鏈烘暟杩涜瑙e瘑锛岃幏鍙栧埌鏈嶅姟鍣ㄧ殑鐪熷疄浼犺緭鍐呭锛?

杩欏氨鏄?nbsp;HTTPS 鐨勫熀鏈繍浣滃師鐞嗭紝浣跨敤瀵圭О鍔犲瘑鍜岄潪瀵圭О鏈哄瘑閰嶅悎浣跨敤锛屼繚璇佷紶杈撳唴瀹圭殑瀹夊叏鎬с€?/p>

鍏充簬HTTPS鏇村鐭ヨ瘑锛屽彲浠ユ煡鐪嬩綔鑰呯殑鍙﹀涓€绡囨枃绔犮€婂涔?HTTP 鍗忚銆嬨€?/p>

閰嶇疆璇佷功

涓嬭浇璇佷功鐨勫帇缂╂枃浠讹紝閲岄潰鏈変釜 Nginx 鏂囦欢澶癸紝鎶?nbsp;xxx.crt 鍜?nbsp;xxx.key 鏂囦欢鎷疯礉鍒版湇鍔″櫒鐩綍锛屽啀杩涜濡備笅閰嶇疆锛?/p>

server {
  listen 443 ssl http2 default_server;   # SSL 璁块棶绔彛鍙蜂负 443
  server_name lion.club;         # 濉啓缁戝畾璇佷功鐨勫煙鍚?鎴戣繖閲屾槸闅忎究鍐欑殑)
  ssl_certificate /etc/nginx/https/lion.club_bundle.crt;   # 璇佷功鍦板潃
  ssl_certificate_key /etc/nginx/https/lion.club.key;      # 绉侀挜鍦板潃
  ssl_session_timeout 10m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 鏀寔ssl鍗忚鐗堟湰锛岄粯璁や负鍚庝笁涓紝涓绘祦鐗堟湰鏄痆TLSv1.2]

  location / {
    root         /usr/share/nginx/html;
    index        index.html index.htm;
  }
}

濡傛閰嶇疆鍚庡氨鑳芥甯歌闂?nbsp;HTTPS 鐗堢殑缃戠珯浜嗐€?/p>

閰嶇疆璺ㄥ煙 CORS

鍏堢畝鍗曞洖椤句笅璺ㄥ煙绌剁珶鏄€庝箞鍥炰簨銆?/p>

璺ㄥ煙鐨勫畾涔?/h3>

鍚屾簮绛栫暐闄愬埗浜嗕粠鍚屼竴涓簮鍔犺浇鐨勬枃妗f垨鑴氭湰濡備綍涓庢潵鑷彟涓€涓簮鐨勮祫婧愯繘琛屼氦浜掋€傝繖鏄竴涓敤浜庨殧绂绘綔鍦ㄦ伓鎰忔枃浠剁殑閲嶈瀹夊叏鏈哄埗銆傞€氬父涓嶅厑璁镐笉鍚屾簮闂寸殑璇绘搷浣溿€?/p>

鍚屾簮鐨勫畾涔?/h3>

濡傛灉涓や釜椤甸潰鐨勫崗璁紝绔彛锛堝鏋滄湁鎸囧畾锛夊拰鍩熷悕閮界浉鍚岋紝鍒欎袱涓〉闈㈠叿鏈夌浉鍚岀殑婧愩€?/p>

涓嬮潰缁欏嚭浜嗕笌 URL http://store.company.com/dir/page.html 鐨勬簮杩涜瀵规瘮鐨勭ず渚?

http://store.company.com/dir2/other.html 鍚屾簮
https://store.company.com/secure.html 涓嶅悓婧愶紝鍗忚涓嶅悓
http://store.company.com:81/dir/etc.html 涓嶅悓婧愶紝绔彛涓嶅悓
http://news.company.com/dir/other.html 涓嶅悓婧愶紝涓绘満涓嶅悓

涓嶅悓婧愪細鏈夊涓嬮檺鍒讹細

  • Web 鏁版嵁灞傞潰锛屽悓婧愮瓥鐣ラ檺鍒朵簡涓嶅悓婧愮殑绔欑偣璇诲彇褰撳墠绔欑偣鐨?nbsp; Cookie 銆?nbsp; IndexDB銆?nbsp; LocalStorage 绛夋暟鎹€?
  • DOM 灞傞潰锛屽悓婧愮瓥鐣ラ檺鍒朵簡鏉ヨ嚜涓嶅悓婧愮殑  javascript 鑴氭湰瀵瑰綋鍓?nbsp; DOM 瀵硅薄璇诲拰鍐欑殑鎿嶄綔銆?
  • 缃戠粶灞傞潰锛屽悓婧愮瓥鐣ラ檺鍒朵簡閫氳繃  XMLHttpRequest 绛夋柟寮忓皢绔欑偣鐨勬暟鎹彂閫佺粰涓嶅悓婧愮殑绔欑偣銆?

Nginx 瑙e喅璺ㄥ煙鐨勫師鐞?/h3>

渚嬪锛?/p>

  • 鍓嶇  server 鐨勫煙鍚嶄负锛?nbsp; fe.server.com
  • 鍚庣鏈嶅姟鐨勫煙鍚嶄负锛?nbsp; dev.server.com

鐜板湪鎴戝湪 fe.server.com 瀵?nbsp;dev.server.com 鍙戣捣璇锋眰涓€瀹氫細鍑虹幇璺ㄥ煙銆?/p>

鐜板湪鎴戜滑鍙渶瑕佸惎鍔ㄤ竴涓?nbsp;Nginx 鏈嶅姟鍣紝灏?nbsp;server_name 璁剧疆涓?nbsp;fe.server.com 鐒跺悗璁剧疆鐩稿簲鐨?nbsp;location 浠ユ嫤鎴墠绔渶瑕佽法鍩熺殑璇锋眰锛屾渶鍚庡皢璇锋眰浠g悊鍥?nbsp;dev.server.com 銆傚涓嬮潰鐨勯厤缃細

server { listen      80; server_name  fe.server.com; location / {  proxy_pass dev.server.com; }}澶嶅埗浠g爜

杩欐牱鍙互瀹岀編缁曡繃娴忚鍣ㄧ殑鍚屾簮绛栫暐锛?nbsp;fe.server.com 璁块棶 Nginx 鐨?nbsp;fe.server.com灞炰簬鍚屾簮璁块棶锛岃€?nbsp;Nginx 瀵规湇鍔$杞彂鐨勮姹備笉浼氳Е鍙戞祻瑙堝櫒鐨勫悓婧愮瓥鐣ャ€?/p>

閰嶇疆寮€鍚?gzip 鍘嬬缉

GZIP 鏄瀹氱殑涓夌鏍囧噯 HTTP 鍘嬬缉鏍煎紡涔嬩竴銆傜洰鍓嶇粷澶у鏁扮殑缃戠珯閮藉湪浣跨敤 GZIP 浼犺緭 HTML 銆?code class="mq-1381">CSS 銆?nbsp;JavaScript 绛夎祫婧愭枃浠躲€?/p>

瀵逛簬鏂囨湰鏂囦欢锛?nbsp;GZiP 鐨勬晥鏋滈潪甯告槑鏄撅紝寮€鍚悗浼犺緭鎵€闇€娴侀噺澶х害浼氶檷鑷?nbsp;1/4~1/3 銆?/p>

骞朵笉鏄瘡涓祻瑙堝櫒閮芥敮鎸?nbsp;gzip 鐨勶紝濡備綍鐭ラ亾瀹㈡埛绔槸鍚︽敮鎸?nbsp;gzip 鍛紝璇锋眰澶翠腑鐨?nbsp;Accept-Encoding 鏉ユ爣璇嗗鍘嬬缉鐨勬敮鎸併€?img data-ratio="0.3834808259587021" src="/img?url=https://mmbiz.qpic.cn/mmbiz_png/JdLkEI9sZff0RM5qHt0MV3iaJfwWLdFzKYmqqVeouGz4gL6MwkZZfo9WQGcapvK9D8iaQ19QxJOhW6GlHSEY0mdA/640?wx_fmt=png" data-type="png" data-w="339" _width="339px" class="mq-1390" alt="2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?>鍚敤 gzip 鍚屾椂闇€瑕佸鎴风鍜屾湇鍔$鐨勬敮鎸侊紝濡傛灉瀹㈡埛绔敮鎸?nbsp;gzip 鐨勮В鏋愶紝閭d箞鍙鏈嶅姟绔兘澶熻繑鍥?nbsp;gzip 鐨勬枃浠跺氨鍙互鍚敤 gzip 浜?鎴戜滑鍙互閫氳繃 Nginx 鐨勯厤缃潵璁╂湇鍔$鏀寔 gzip 銆備笅闈㈢殑 respone 涓?nbsp;content-encoding:gzip 锛屾寚鏈嶅姟绔紑鍚簡 gzip鐨勫帇缂╂柟寮忋€?img data-ratio="0.5748031496062992" src="/img?url=https://mmbiz.qpic.cn/mmbiz_png/JdLkEI9sZff0RM5qHt0MV3iaJfwWLdFzKkt4Kqto9Ur5dK7YEedVVNmZsib0mE0NIkB4AfWiaWNZCNopHI923MO2g/640?wx_fmt=png" data-type="png" data-w="381" _width="368px" class="mq-1400" alt="2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?>鍦?nbsp;/etc/nginx/conf.d/ 鏂囦欢澶逛腑鏂板缓閰嶇疆鏂囦欢 gzip.conf 锛?/p>

# # 榛樿off锛屾槸鍚﹀紑鍚痝zip
gzip on;
# 瑕侀噰鐢?nbsp;gzip 鍘嬬缉鐨?nbsp;MIME 鏂囦欢绫诲瀷锛屽叾涓?nbsp;text/html 琚郴缁熷己鍒跺惎鐢紱
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# ---- 浠ヤ笂涓や釜鍙傛暟寮€鍚氨鍙互鏀寔Gzip鍘嬬缉浜?nbsp;---- #

# 榛樿 off锛岃妯″潡鍚敤鍚庯紝Nginx 棣栧厛妫€鏌ユ槸鍚﹀瓨鍦ㄨ姹傞潤鎬佹枃浠剁殑 gz 缁撳熬鐨勬枃浠讹紝濡傛灉鏈夊垯鐩存帴杩斿洖璇?nbsp;.gz 鏂囦欢鍐呭锛?/span>
gzip_static on;

# 榛樿 off锛宯ginx鍋氫负鍙嶅悜浠g悊鏃跺惎鐢紝鐢ㄤ簬璁剧疆鍚敤鎴栫鐢ㄤ粠浠g悊鏈嶅姟鍣ㄤ笂鏀跺埌鐩稿簲鍐呭 gzip 鍘嬬缉锛?/span>
gzip_proxied any;

# 鐢ㄤ簬鍦ㄥ搷搴旀秷鎭ご涓坊鍔?nbsp;Vary锛欰ccept-Encoding锛屼娇浠g悊鏈嶅姟鍣ㄦ牴鎹姹傚ご涓殑 Accept-Encoding 璇嗗埆鏄惁鍚敤 gzip 鍘嬬缉锛?/span>
gzip_vary on;

# gzip 鍘嬬缉姣旓紝鍘嬬缉绾у埆鏄?nbsp;1-9锛? 鍘嬬缉绾у埆鏈€浣庯紝9 鏈€楂橈紝绾у埆瓒婇珮鍘嬬缉鐜囪秺澶э紝鍘嬬缉鏃堕棿瓒婇暱锛屽缓璁?nbsp;4-6锛?/span>
gzip_comp_level 6;

# 鑾峰彇澶氬皯鍐呭瓨鐢ㄤ簬缂撳瓨鍘嬬缉缁撴灉锛?6 8k 琛ㄧず浠?nbsp;8k*16 涓哄崟浣嶈幏寰楋紱
gzip_buffers 16 8k;

# 鍏佽鍘嬬缉鐨勯〉闈㈡渶灏忓瓧鑺傛暟锛岄〉闈㈠瓧鑺傛暟浠巋eader澶翠腑鐨?nbsp;Content-Length 涓繘琛岃幏鍙栥€傞粯璁ゅ€兼槸 0锛屼笉绠¢〉闈㈠澶ч兘鍘嬬缉銆傚缓璁缃垚澶т簬 1k 鐨勫瓧鑺傛暟锛屽皬浜?nbsp;1k 鍙兘浼氳秺鍘嬭秺澶э紱
# gzip_min_length 1k;

# 榛樿 1.1锛屽惎鐢?nbsp;gzip 鎵€闇€鐨?nbsp;HTTP 鏈€浣庣増鏈紱
gzip_http_version 1.1;

鍏跺疄涔熷彲浠ラ€氳繃鍓嶇鏋勫缓宸ュ叿渚嬪 webpack 銆?code class="mq-1419">rollup 绛夊湪鎵撶敓浜у寘鏃跺氨鍋氬ソ Gzip 鍘嬬缉锛岀劧鍚庢斁鍒?nbsp;Nginx 鏈嶅姟鍣ㄤ腑锛岃繖鏍峰彲浠ュ噺灏戞湇鍔″櫒鐨勫紑閿€锛屽姞蹇闂€熷害銆?/p>

鍏充簬 Nginx 鐨勫疄闄呭簲鐢ㄥ氨瀛︿範鍒拌繖閲岋紝鐩镐俊閫氳繃鎺屾彙浜?nbsp;Nginx 鏍稿績閰嶇疆浠ュ強瀹炴垬閰嶇疆锛屼箣鍚庡啀閬囧埌浠€涔堥渶姹傦紝鎴戜滑涔熻兘杞绘澗搴斿銆傛帴涓嬫潵锛岃鎴戜滑鍐嶆繁鍏ヤ竴鐐瑰涔犱笅 Nginx 鐨勬灦鏋勩€?/p>

Nginx 鏋舵瀯

杩涚▼缁撴瀯

澶氳繘绋嬬粨鏋?nbsp;Nginx 鐨勮繘绋嬫ā鍨嬪浘锛?/p>

2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?> 
</figure> 
<p data-tool=澶氳繘绋嬩腑鐨?nbsp;Nginx 杩涚▼鏋舵瀯濡備笅鍥炬墍绀猴紝浼氭湁涓€涓埗杩涚▼锛?nbsp;Master Process 锛夛紝瀹冧細鏈夊緢澶氬瓙杩涚▼锛?nbsp;Child Processes 锛夈€?/p>
  • Master Process

    鐢ㄦ潵绠$悊瀛愯繘绋嬬殑锛屽叾鏈韩骞朵笉鐪熸澶勭悊鐢ㄦ埛璇锋眰銆?/p>

    • 鏌愪釜瀛愯繘绋?nbsp; down 鎺夌殑璇濓紝瀹冧細鍚?nbsp; Master 杩涚▼鍙戦€佷竴鏉℃秷鎭紝琛ㄦ槑鑷繁涓嶅彲鐢ㄤ簡锛屾鏃?nbsp; Master 杩涚▼浼氬幓鏂拌捣涓€涓瓙杩涚▼銆?
    • 鏌愪釜閰嶇疆鏂囦欢琚慨鏀逛簡  Master 杩涚▼浼氬幓閫氱煡  work 杩涚▼鑾峰彇鏂扮殑閰嶇疆淇℃伅锛岃繖涔熷氨鏄垜浠墍璇寸殑鐑儴缃层€?
  • 瀛愯繘绋嬮棿鏄€氳繃鍏变韩鍐呭瓨鐨勬柟寮忚繘琛岄€氫俊鐨勩€?/p>

閰嶇疆鏂囦欢閲嶈浇鍘熺悊

reload 閲嶈浇閰嶇疆鏂囦欢鐨勬祦绋嬶細

  1. 鍚?nbsp; master 杩涚▼鍙戦€?nbsp; HUP 淇″彿锛?nbsp; reload 鍛戒护锛夛紱
  2. master 杩涚▼妫€鏌ラ厤缃娉曟槸鍚︽纭紱
  3. master 杩涚▼鎵撳紑鐩戝惉绔彛锛?
  4. master 杩涚▼浣跨敤鏂扮殑閰嶇疆鏂囦欢鍚姩鏂扮殑  worker 瀛愯繘绋嬶紱
  5. master 杩涚▼鍚戣€佺殑  worker 瀛愯繘绋嬪彂閫?nbsp; QUIT 淇″彿锛?
  6. 鑰佺殑  worker 杩涚▼鍏抽棴鐩戝惉鍙ユ焺锛屽鐞嗗畬褰撳墠杩炴帴鍚庡叧闂繘绋嬶紱
  7. 鏁翠釜杩囩▼  Nginx 濮嬬粓澶勪簬骞崇ǔ杩愯涓紝瀹炵幇浜嗗钩婊戝崌绾э紝鐢ㄦ埛鏃犳劅鐭ワ紱

Nginx 妯″潡鍖栫鐞嗘満鍒?/span>

Nginx 鐨勫唴閮ㄧ粨鏋勬槸鐢辨牳蹇冮儴鍒嗗拰涓€绯诲垪鐨勫姛鑳芥ā鍧楁墍缁勬垚銆傝繖鏍峰垝鍒嗘槸涓轰簡浣垮緱姣忎釜妯″潡鐨勫姛鑳界浉瀵圭畝鍗曪紝渚夸簬寮€鍙戯紝鍚屾椂涔熶究浜庡绯荤粺杩涜鍔熻兘鎵╁睍銆?code class="mq-1488">Nginx 鐨勬ā鍧楁槸浜掔浉鐙珛鐨?浣庤€﹀悎楂樺唴鑱氥€?/p>

鎬荤粨

鐩镐俊閫氳繃鏈枃鐨勫涔狅紝浣犲簲璇ヤ細瀵?nbsp;Nginx 鏈変竴涓洿鍔犲叏闈㈢殑璁よ瘑銆?/p>

閮界湅鍒拌繖閲屼簡锛屽氨鐐逛釜馃憤 馃憤 馃憤 鍚с€?/p>



鐐逛釜鍦ㄧ湅锛屼綘鏈€濂界湅

以上是关于2.3W瀛楋紝杩欏彲鑳芥槸鎶奛ginx璁插緱鏈€鍏ㄩ潰鐨勪竴绡囨枃绔犱簡锛屽缓璁敹钘忓鐢?/h1>

的主要内容,如果未能解决你的问题,请参考以下文章

鍒ゆ柇涓€缁勬暟瀛楋紝鏄惁杩炵画

python 鐖彇涔屼簯鎵€鏈夊巶鍟嗗悕瀛楋紝url锛屾紡娲炴€绘暟 骞跺瓨鍏ユ暟鎹簱