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 鐨勬渶閲嶈鐨勫嚑涓娇鐢ㄥ満鏅細
-
闈欐€佽祫婧愭湇鍔★紝閫氳繃鏈湴鏂囦欢绯荤粺鎻愪緵鏈嶅姟锛?
-
鍙嶅悜浠g悊鏈嶅姟锛屽欢浼稿嚭鍖呮嫭缂撳瓨銆佽礋杞藉潎琛$瓑锛?
-
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
涓昏鍏虫敞鐨勬枃浠跺す鏈変袱涓細
-
/etc/nginx/conf.d/
鏄瓙閰嶇疆椤瑰瓨鏀惧锛?nbsp;
/etc/nginx/nginx.conf
涓婚厤缃枃浠朵細榛樿鎶婅繖涓枃浠跺す涓墍鏈夊瓙閰嶇疆椤归兘寮曞叆锛?
-
/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
閰嶇疆鍚庣鏈嶅姟鍣ㄥ叿浣撳湴鍧€锛岃礋杞藉潎琛¢厤缃笉鍙垨缂虹殑閮ㄥ垎锛?
鐢ㄤ竴寮犲浘娓呮櫚鐨勫睍绀哄畠鐨勫眰绾х粨鏋勶細閰嶇疆鏂囦欢 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>
绀轰緥锛歳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/
璺緞涓嬬殑鏂囦欢灞曠ず鍑烘潵锛屽涓嬪浘鎵€绀猴細
鍙橀噺
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>
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 鐨勬渶閲嶈鐨勫嚑涓娇鐢ㄥ満鏅細
-
闈欐€佽祫婧愭湇鍔★紝閫氳繃鏈湴鏂囦欢绯荤粺鎻愪緵鏈嶅姟锛? -
鍙嶅悜浠g悊鏈嶅姟锛屽欢浼稿嚭鍖呮嫭缂撳瓨銆佽礋杞藉潎琛$瓑锛? -
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
涓昏鍏虫敞鐨勬枃浠跺す鏈変袱涓細
-
/etc/nginx/conf.d/
鏄瓙閰嶇疆椤瑰瓨鏀惧锛?nbsp;/etc/nginx/nginx.conf
涓婚厤缃枃浠朵細榛樿鎶婅繖涓枃浠跺す涓墍鏈夊瓙閰嶇疆椤归兘寮曞叆锛? -
/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
閰嶇疆鍚庣鏈嶅姟鍣ㄥ叿浣撳湴鍧€锛岃礋杞藉潎琛¢厤缃笉鍙垨缂虹殑閮ㄥ垎锛?
鐢ㄤ竴寮犲浘娓呮櫚鐨勫睍绀哄畠鐨勫眰绾х粨鏋勶細閰嶇疆鏂囦欢 main 娈垫牳蹇冨弬鏁?/span>
鎸囧畾杩愯 鎸囧畾杩愯 鎸囧畾 鎸囧畾 鎸囧畾 灏嗘瘡涓?nbsp; 鎸夌収杩欎釜閰嶇疆鎴戜滑鏉ュ垎鏋愶細user
Nginx
鐨?nbsp;woker
瀛愯繘绋嬬殑灞炰富鍜屽睘缁勶紝鍏朵腑缁勫彲浠ヤ笉鎸囧畾銆?/p>
user USERNAME [GROUP]
user nginx lion; # 鐢ㄦ埛鏄痭ginx;缁勬槸lionpid
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
worker
瀛愯繘绋嬩笌鎴戜滑鐨?nbsp;cpu
鐗╃悊鏍稿績缁戝畾銆?/p>
worker_cpu_affinity 0001 0010 0100 1000; # 4涓墿鐞嗘牳蹇冿紝4涓獁orker瀛愯繘绋嬪鍒朵唬鐮?/span>
绀轰緥锛歳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 {
}
}
fe.lion.club/search
鏃讹紝浼氳嚜鍔ㄥ府鎴戜滑閲嶅畾鍚戝埌
https://www.baidu.com
銆?
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 鎸囦护
(condition) {...}璇硶锛?span class="mq-583">if
涓婁笅鏂囷細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/
璺緞涓嬬殑鏂囦欢灞曠ず鍑烘潵锛屽涓嬪浘鎵€绀猴細
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>