{"id":1428,"date":"2024-08-27T14:50:21","date_gmt":"2024-08-27T06:50:21","guid":{"rendered":"https:\/\/blog.nonot.cn\/?p=1428"},"modified":"2024-08-27T14:50:21","modified_gmt":"2024-08-27T06:50:21","slug":"nginx-nginx%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86-%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1-%e7%bc%93%e5%ad%98","status":"publish","type":"post","link":"https:\/\/blog.nonot.cn\/index.php\/2024\/08\/27\/nginx-nginx%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86-%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1-%e7%bc%93%e5%ad%98\/","title":{"rendered":"nginx | nginx\u53cd\u5411\u4ee3\u7406\/\u8d1f\u8f7d\u5747\u8861\/\u7f13\u5b58"},"content":{"rendered":"<div>nginx | nginx\u53cd\u5411\u4ee3\u7406\/\u8d1f\u8f7d\u5747\u8861\/\u7f13\u5b58<\/div>\n<div><\/div>\n<div>\u00a0\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86Nginx\u7684\u53cd\u5411\u4ee3\u7406\u539f\u7406\u3001\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u7ed3\u6784\uff0c\u6db5\u76d6\u4e86\u70ed\u5907\u3001\u8f6e\u8be2\u3001\u52a0\u6743\u8f6e\u8be2\u3001ip_hash\u7b49\u591a\u79cd\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\uff0c\u4ee5\u53ca\u7f13\u5b58\u673a\u5236\u7684\u914d\u7f6e\u3001\u6e05\u9664\u65b9\u6cd5\u548c\u907f\u514d\u7f13\u5b58\u7279\u5b9a\u8d44\u6e90\u7684\u6280\u5de7\u3002<\/div>\n<div>\u6458\u8981\u7531CSDN\u901a\u8fc7\u667a\u80fd\u6280\u672f\u751f\u6210<\/div>\n<div>\u6587\u7ae0\u76ee\u5f55<\/div>\n<div>\u4e00\u3001Nginx \u53cd\u5411\u4ee3\u7406<\/div>\n<div>1.1 nginx \u6587\u4ef6\u7ed3\u6784<\/div>\n<div>1.2 \u9ed8\u8ba4\u7684nginx\u914d\u7f6e\u6587\u4ef6<\/div>\n<div>1.3 \u5b9e\u8df5\u4e2d\u7684 nginx.conf<\/div>\n<div>\u4e8c\u3001Nginx \u8d1f\u8f7d\u5747\u8861<\/div>\n<div>2.1 \u70ed\u5907\u8d1f\u8f7d\u5747\u8861<\/div>\n<div>2.2 \u8f6e\u8be2\u8d1f\u8d23\u5747\u8861<\/div>\n<div>2.3 \u52a0\u6743\u8f6e\u8be2\u8d1f\u8f7d\u89c4\u5219<\/div>\n<div>2.4 ip_hash \u8d1f\u8f7d\u5747\u8861<\/div>\n<div>2.5 \u5bf9\u7279\u5b9a\u8d44\u6e90\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861<\/div>\n<div>2.6 \u5bf9\u4e0d\u540c\u57df\u540d\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861<\/div>\n<div>2.7 \u5b9e\u73b0\u5e26\u6709URL\u91cd\u5199\u7684\u8d1f\u8f7d\u5747\u8861<\/div>\n<div>2.8 \u56db\u5c42\u8d1f\u8f7d\u5747\u8861<\/div>\n<div>\u4e09\u3001Nginx \u7f13\u5b58<\/div>\n<div>3.1 nginx \u7684\u7f13\u5b58\u673a\u5236<\/div>\n<div>3.2 \u7f13\u5b58\u5b9e\u4f8b<\/div>\n<div>3.3 Nginx\u7f13\u5b58\u7684\u6e05\u9664<\/div>\n<div>3.4 Nginx\u8bbe\u7f6e\u8d44\u6e90\u4e0d\u7f13\u5b58<\/div>\n<div>\u56db\u3001\u53c2\u8003\u8d44\u6599<\/div>\n<div>\u4e00\u3001Nginx \u53cd\u5411\u4ee3\u7406<\/div>\n<div>\u6b63\u5411\u4ee3\u7406\u4ee3\u7406\u7684\u5bf9\u8c61\u662f\u5ba2\u6237\u7aef\uff0c\u53cd\u5411\u4ee3\u7406\u4ee3\u7406\u7684\u662f\u670d\u52a1\u7aef<\/div>\n<div><\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1458\" title=\"294cd94fa7212b7e4cd106408263928a-1-1-1-1-1-1-1-1-1-1-1-1\" src=\"https:\/\/blog.nonot.cn\/wp-content\/uploads\/replace\/6484e91d7354fe367bed292872fcdbd4.png\" alt=\"294cd94fa7212b7e4cd106408263928a-1-1-1-1-1-1-1-1-1-1-1-1\" width=\"796\" height=\"170\" \/><\/div>\n<div>\u5728nginx\u5b89\u88c5\u5305\u4e0b\uff0c\u6709 conf\/nginx.conf \u6587\u4ef6\uff0c\u8fd9\u662fnginx\u670d\u52a1\u5668\u7684\u57fa\u7840\u914d\u7f6e\uff0c\u9ed8\u8ba4\u7684\u914d\u7f6e\u4e5f\u5b58\u653e\u5728\u6b64\u3002<\/div>\n<div><\/div>\n<div>1.1 nginx \u6587\u4ef6\u7ed3\u6784<\/div>\n<div>\n<p># 1.\u5168\u5c40\u5757,\u914d\u7f6e\u5f71\u54cdnginx\u5168\u5c40\u7684\u6307\u4ee4\u3002<br \/>\n# \u4e00\u822c\u6709\u8fd0\u884cnginx\u670d\u52a1\u5668\u7684\u7528\u6237\u7ec4\uff0cnginx\u8fdb\u7a0bpid\u5b58\u653e\u8def\u5f84\uff0c\u65e5\u5fd7\u5b58\u653e\u8def\u5f84\uff0c\u914d\u7f6e\u6587\u4ef6\u5f15\u5165\uff0c\u5141\u8bb8\u751f\u6210worker process\u6570\u7b49\u3002<br \/>\n&#8230; #\u5168\u5c40\u5757<\/p>\n<p># 2.\u914d\u7f6e\u5f71\u54cdnginx\u670d\u52a1\u5668\u6216\u4e0e\u7528\u6237\u7684\u7f51\u7edc\u8fde\u63a5\u3002<br \/>\n# \u6709\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u6700\u5927\u8fde\u63a5\u6570\uff0c\u9009\u53d6\u54ea\u79cd\u4e8b\u4ef6\u9a71\u52a8\u6a21\u578b\u5904\u7406\u8fde\u63a5\u8bf7\u6c42\uff0c\u662f\u5426\u5141\u8bb8\u540c\u65f6\u63a5\u53d7\u591a\u4e2a\u7f51\u8def\u8fde\u63a5\uff0c\u5f00\u542f\u591a\u4e2a\u7f51\u7edc\u8fde\u63a5\u5e8f\u5217\u5316\u7b49\u3002<\/p>\n<p>events { #events\u5757<br \/>\n&#8230;<br \/>\n}<\/p>\n<p># 3.\u53ef\u4ee5\u5d4c\u5957\u591a\u4e2aserver\uff0c\u914d\u7f6e\u4ee3\u7406\uff0c\u7f13\u5b58\uff0c\u65e5\u5fd7\u5b9a\u4e49\u7b49\u7edd\u5927\u591a\u6570\u529f\u80fd\u548c\u7b2c\u4e09\u65b9\u6a21\u5757\u7684\u914d\u7f6e\u3002<br \/>\n# \u5982\u6587\u4ef6\u5f15\u5165\uff0cmime-type\u5b9a\u4e49\uff0c\u65e5\u5fd7\u81ea\u5b9a\u4e49\uff0c\u662f\u5426\u4f7f\u7528sendfile\u4f20\u8f93\u6587\u4ef6\uff0c\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u8fde\u63a5\u8bf7\u6c42\u6570\u7b49\u3002<br \/>\nhttp #http\u5757<br \/>\n{<br \/>\n&#8230; #http\u5168\u5c40\u5757<\/p>\n<p># 4.\u914d\u7f6e\u865a\u62df\u4e3b\u673a\u7684\u76f8\u5173\u53c2\u6570\uff0c\u4e00\u4e2ahttp\u4e2d\u53ef\u4ee5\u6709\u591a\u4e2aserver\u3002<br \/>\nserver #server\u5757<br \/>\n{<br \/>\n&#8230; #server\u5168\u5c40\u5757<\/p>\n<p># 5.\u914d\u7f6e\u8bf7\u6c42\u7684\u8def\u7531\uff0c\u4ee5\u53ca\u5404\u79cd\u9875\u9762\u7684\u5904\u7406\u60c5\u51b5\u3002<br \/>\nlocation [PATTERN] #location\u5757<br \/>\n{<br \/>\n&#8230;<br \/>\n}<br \/>\nlocation [PATTERN]<br \/>\n{<br \/>\n&#8230;<br \/>\n}<br \/>\n}<br \/>\nserver<br \/>\n{<br \/>\n&#8230;<br \/>\n}<br \/>\n&#8230; #http\u5168\u5c40\u5757<br \/>\n}<\/p>\n<\/div>\n<div>1.2 \u9ed8\u8ba4\u7684nginx\u914d\u7f6e\u6587\u4ef6<\/div>\n<div>\n<p>#user nobody;<br \/>\nworker_processes 1;<\/p>\n<p>#error_log logs\/error.log;<br \/>\n#error_log logs\/error.log notice;<br \/>\n#error_log logs\/error.log info;<\/p>\n<p>#pid logs\/nginx.pid;<\/p>\n<p>events {<br \/>\nworker_connections 1024;<br \/>\n}<\/p>\n<p>http {<br \/>\ninclude mime.types;<br \/>\ndefault_type application\/octet-stream;<\/p>\n<p>#log_format main &#8216;$remote_addr &#8211; $remote_user [$time_local] &#8220;$request&#8221; &#8216;<br \/>\n# &#8216;$status $body_bytes_sent &#8220;$http_referer&#8221; &#8216;<br \/>\n# &#8216;&#8221;$http_user_agent&#8221; &#8220;$http_x_forwarded_for&#8221;&#8216;;<\/p>\n<p>#access_log logs\/access.log main;<\/p>\n<p>sendfile on;<br \/>\n#tcp_nopush on;<\/p>\n<p>#keepalive_timeout 0;<br \/>\nkeepalive_timeout 65;<\/p>\n<p>#gzip on;<\/p>\n<p>server {<br \/>\nlisten 80;<br \/>\nserver_name localhost;<\/p>\n<p>#charset koi8-r;<\/p>\n<p>#access_log logs\/host.access.log main;<\/p>\n<p>location \/ {<br \/>\nroot html;<br \/>\nindex index.html index.htm;<br \/>\n}<\/p>\n<p>#error_page 404 \/404.html;<\/p>\n<p># redirect server error pages to the static page \/50x.html<br \/>\n#<br \/>\nerror_page 500 502 503 504 \/50x.html;<br \/>\nlocation = \/50x.html {<br \/>\nroot html;<br \/>\n}<\/p>\n<p># proxy the PHP scripts to Apache listening on 127.0.0.1:80<br \/>\n#<br \/>\n#location ~ .php$ {<br \/>\n# proxy_pass http:\/\/127.0.0.1;<br \/>\n#}<\/p>\n<p># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000<br \/>\n#<br \/>\n#location ~ .php$ {<br \/>\n# root html;<br \/>\n# fastcgi_pass 127.0.0.1:9000;<br \/>\n# fastcgi_index index.php;<br \/>\n# fastcgi_param SCRIPT_FILENAME \/scripts$fastcgi_script_name;<br \/>\n# include fastcgi_params;<br \/>\n#}<\/p>\n<p># deny access to .htaccess files, if Apache&#8217;s document root<br \/>\n# concurs with nginx&#8217;s one<br \/>\n#<br \/>\n#location ~ \/.ht {<br \/>\n# deny all;<br \/>\n#}<br \/>\n}<\/p>\n<p># another virtual host using mix of IP-, name-, and port-based configuration<br \/>\n#<br \/>\n#server {<br \/>\n# listen 8000;<br \/>\n# listen somename:8080;<br \/>\n# server_name somename alias another.alias;<\/p>\n<p># location \/ {<br \/>\n# root html;<br \/>\n# index index.html index.htm;<br \/>\n# }<br \/>\n#}<\/p>\n<p># HTTPS server<br \/>\n#<br \/>\n#server {<br \/>\n# listen 443 ssl;<br \/>\n# server_name localhost;<\/p>\n<p># ssl_certificate cert.pem;<br \/>\n# ssl_certificate_key cert.key;<\/p>\n<p># ssl_session_cache shared:SSL:1m;<br \/>\n# ssl_session_timeout 5m;<\/p>\n<p># ssl_ciphers HIGH:!aNULL:!MD5;<br \/>\n# ssl_prefer_server_ciphers on;<\/p>\n<p># location \/ {<br \/>\n# root html;<br \/>\n# index index.html index.htm;<br \/>\n# }<br \/>\n#}<\/p>\n<p>}<\/p>\n<\/div>\n<div>1.3 \u5b9e\u8df5\u4e2d\u7684 nginx.conf<\/div>\n<div>\n<p>########### \u6bcf\u4e2a\u6307\u4ee4\u5fc5\u987b\u6709\u5206\u53f7\u7ed3\u675f\u3002#################<br \/>\n#user administrator administrators; #\u914d\u7f6e\u7528\u6237\u6216\u8005\u7ec4\uff0c\u9ed8\u8ba4\u4e3anobody nobody\u3002<br \/>\n#worker_processes 2; #\u5141\u8bb8\u751f\u6210\u7684\u8fdb\u7a0b\u6570\uff0c\u9ed8\u8ba4\u4e3a1<br \/>\n#pid \/nginx\/pid\/nginx.pid; #\u6307\u5b9anginx\u8fdb\u7a0b\u8fd0\u884c\u6587\u4ef6\u5b58\u653e\u5730\u5740<br \/>\nerror_log log\/error.log debug; #\u5236\u5b9a\u65e5\u5fd7\u8def\u5f84\uff0c\u7ea7\u522b\u3002\u8fd9\u4e2a\u8bbe\u7f6e\u53ef\u4ee5\u653e\u5165\u5168\u5c40\u5757\uff0chttp\u5757\uff0cserver\u5757\uff0c\u7ea7\u522b\u4ee5\u6b64\u4e3a\uff1adebug|info|notice|warn|error|crit|alert|emerg<br \/>\nevents {<br \/>\naccept_mutex on; #\u8bbe\u7f6e\u7f51\u8def\u8fde\u63a5\u5e8f\u5217\u5316\uff0c\u9632\u6b62\u60ca\u7fa4\u73b0\u8c61\u53d1\u751f\uff0c\u9ed8\u8ba4\u4e3aon<br \/>\nmulti_accept on; #\u8bbe\u7f6e\u4e00\u4e2a\u8fdb\u7a0b\u662f\u5426\u540c\u65f6\u63a5\u53d7\u591a\u4e2a\u7f51\u7edc\u8fde\u63a5\uff0c\u9ed8\u8ba4\u4e3aoff<br \/>\n#use epoll; #\u4e8b\u4ef6\u9a71\u52a8\u6a21\u578b\uff0cselect|poll|kqueue|epoll|resig|\/dev\/poll|eventport<br \/>\nworker_connections 1024; #\u6700\u5927\u8fde\u63a5\u6570\uff0c\u9ed8\u8ba4\u4e3a512<br \/>\n}<br \/>\nhttp {<br \/>\ninclude mime.types; #\u6587\u4ef6\u6269\u5c55\u540d\u4e0e\u6587\u4ef6\u7c7b\u578b\u6620\u5c04\u8868<br \/>\ndefault_type application\/octet-stream; #\u9ed8\u8ba4\u6587\u4ef6\u7c7b\u578b\uff0c\u9ed8\u8ba4\u4e3atext\/plain<br \/>\n#access_log off; #\u53d6\u6d88\u670d\u52a1\u65e5\u5fd7<br \/>\nlog_format myFormat &#8216;$remote_addr\u2013$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for&#8217;; #\u81ea\u5b9a\u4e49\u683c\u5f0f<br \/>\naccess_log log\/access.log myFormat; #combined\u4e3a\u65e5\u5fd7\u683c\u5f0f\u7684\u9ed8\u8ba4\u503c<br \/>\nsendfile on; #\u5141\u8bb8sendfile\u65b9\u5f0f\u4f20\u8f93\u6587\u4ef6\uff0c\u9ed8\u8ba4\u4e3aoff\uff0c\u53ef\u4ee5\u5728http\u5757\uff0cserver\u5757\uff0clocation\u5757\u3002<br \/>\nsendfile_max_chunk 100k; #\u6bcf\u4e2a\u8fdb\u7a0b\u6bcf\u6b21\u8c03\u7528\u4f20\u8f93\u6570\u91cf\u4e0d\u80fd\u5927\u4e8e\u8bbe\u5b9a\u7684\u503c\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u5373\u4e0d\u8bbe\u4e0a\u9650\u3002<br \/>\nkeepalive_timeout 65; #\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff0c\u9ed8\u8ba4\u4e3a75s\uff0c\u53ef\u4ee5\u5728http\uff0cserver\uff0clocation\u5757\u3002<\/p>\n<p>upstream mysvr {<br \/>\nserver 127.0.0.1:7878;<br \/>\nserver 192.168.10.121:3333 backup; #\u70ed\u5907<br \/>\n}<br \/>\nerror_page 404 https:\/\/www.baidu.com; #\u9519\u8bef\u9875<br \/>\nserver {<br \/>\nkeepalive_requests 120; #\u5355\u8fde\u63a5\u8bf7\u6c42\u4e0a\u9650\u6b21\u6570\u3002<br \/>\nlisten 4545; #\u76d1\u542c\u7aef\u53e3<br \/>\nserver_name 127.0.0.1; #\u76d1\u542c\u5730\u5740<br \/>\nlocation ~*^.+$ { #\u8bf7\u6c42\u7684url\u8fc7\u6ee4\uff0c\u6b63\u5219\u5339\u914d\uff0c~\u4e3a\u533a\u5206\u5927\u5c0f\u5199\uff0c~*\u4e3a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002<br \/>\n#root path; #\u6839\u76ee\u5f55<br \/>\n#index vv.txt; #\u8bbe\u7f6e\u9ed8\u8ba4\u9875<br \/>\nproxy_pass http:\/\/mysvr; #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868<br \/>\ndeny 127.0.0.1; #\u62d2\u7edd\u7684ip<br \/>\nallow 172.18.5.54; #\u5141\u8bb8\u7684ip<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<\/div>\n<div>\u60ca\u7fa4\u73b0\u8c61\uff1a\u4e00\u4e2a\u7f51\u8def\u8fde\u63a5\u5230\u6765\uff0c\u591a\u4e2a\u7761\u7720\u7684\u8fdb\u7a0b\u88ab\u540c\u65f6\u53eb\u9192\uff0c\u4f46\u53ea\u6709\u4e00\u4e2a\u8fdb\u7a0b\u80fd\u83b7\u5f97\u94fe\u63a5\uff0c\u8fd9\u6837\u4f1a\u5f71\u54cd\u7cfb\u7edf\u6027\u80fd\u3002<\/div>\n<div><\/div>\n<div>\u51e0\u4e2a\u5e38\u89c1\u914d\u7f6e\u9879\uff1a<\/div>\n<div><\/div>\n<div>1.$remote_addr \u4e0e $http_x_forwarded_for \u7528\u4ee5\u8bb0\u5f55\u5ba2\u6237\u7aef\u7684ip\u5730\u5740\uff1b<\/div>\n<div>2.$remote_user \uff1a\u7528\u6765\u8bb0\u5f55\u5ba2\u6237\u7aef\u7528\u6237\u540d\u79f0\uff1b<\/div>\n<div>3.$time_local \uff1a \u7528\u6765\u8bb0\u5f55\u8bbf\u95ee\u65f6\u95f4\u4e0e\u65f6\u533a\uff1b<\/div>\n<div>4.$request \uff1a \u7528\u6765\u8bb0\u5f55\u8bf7\u6c42\u7684url\u4e0ehttp\u534f\u8bae\uff1b<\/div>\n<div>5.$status \uff1a \u7528\u6765\u8bb0\u5f55\u8bf7\u6c42\u72b6\u6001\uff1b\u6210\u529f\u662f200\uff1b<\/div>\n<div>6.$body_bytes_s ent \uff1a\u8bb0\u5f55\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u6587\u4ef6\u4e3b\u4f53\u5185\u5bb9\u5927\u5c0f\uff1b<\/div>\n<div>7.$http_referer \uff1a\u7528\u6765\u8bb0\u5f55\u4ece\u90a3\u4e2a\u9875\u9762\u94fe\u63a5\u8bbf\u95ee\u8fc7\u6765\u7684\uff1b<\/div>\n<div>8.$http_user_agent \uff1a\u8bb0\u5f55\u5ba2\u6237\u7aef\u6d4f\u89c8\u5668\u7684\u76f8\u5173\u4fe1\u606f\uff1b<\/div>\n<div>\u4e8c\u3001Nginx \u8d1f\u8f7d\u5747\u8861<\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1459\" title=\"07f5f443dd402b123adf7b93247ea3cd-1-1-1-1-1-1-1-1-1-1\" src=\"https:\/\/blog.nonot.cn\/wp-content\/uploads\/replace\/42f8e0f0856fc462c8a84185c0c4d04e.png\" alt=\"07f5f443dd402b123adf7b93247ea3cd-1-1-1-1-1-1-1-1-1-1\" width=\"785\" height=\"189\" \/><\/div>\n<div>2.1 \u70ed\u5907\u8d1f\u8f7d\u5747\u8861<\/div>\n<div>\u70ed\u5907\uff1a\u5982\u679c\u4f60\u67092\u53f0\u670d\u52a1\u5668\uff0c\u5f53\u4e00\u53f0\u670d\u52a1\u5668\u53d1\u751f\u4e8b\u6545\u65f6\uff0c\u624d\u542f\u7528\u7b2c\u4e8c\u53f0\u670d\u52a1\u5668\u7ed9\u63d0\u4f9b\u670d\u52a1\u3002\u670d\u52a1\u5668\u5904\u7406\u8bf7\u6c42\u7684\u987a\u5e8f\uff1aAAAAAA\u7a81\u7136A\u6302\u5566\uff0cBBBBBBBBBBBBBB\u2026<\/div>\n<div><\/div>\n<div>\n<p>upstream mysvr {<br \/>\nserver 127.0.0.1:7878;<br \/>\nserver 192.168.10.121:3333 backup; #\u70ed\u5907<br \/>\n}<\/p>\n<p>server {<br \/>\nlisten 8081; #\u76d1\u542c\u7aef\u53e3<br \/>\nserver_name 127.0.0.1; #\u76d1\u542c\u5730\u5740<br \/>\nlocation \/{<br \/>\nproxy_pass http:\/\/mysvr; #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868<br \/>\n}<br \/>\n}<\/p>\n<\/div>\n<div>2.2 \u8f6e\u8be2\u8d1f\u8d23\u5747\u8861<\/div>\n<div>\u8f6e\u8be2\uff1anginx\u9ed8\u8ba4\u5c31\u662f\u8f6e\u8be2\u5176\u6743\u91cd\u90fd\u9ed8\u8ba4\u4e3a1\uff0c\u670d\u52a1\u5668\u5904\u7406\u8bf7\u6c42\u7684\u987a\u5e8f\uff1aABABABABAB\u2026<\/div>\n<div><\/div>\n<div>\n<p>upstream mysvr {<br \/>\nserver 127.0.0.1:7878;<br \/>\nserver 192.168.10.121:3333;<br \/>\n}<\/p>\n<p>server {<br \/>\nlisten 8081; #\u76d1\u542c\u7aef\u53e3<br \/>\nserver_name 127.0.0.1; #\u76d1\u542c\u5730\u5740<br \/>\nlocation \/{<br \/>\nproxy_pass http:\/\/mysvr; #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868<br \/>\n}<br \/>\n}<\/p>\n<\/div>\n<div>2.3 \u52a0\u6743\u8f6e\u8be2\u8d1f\u8f7d\u89c4\u5219<\/div>\n<div>\u52a0\u6743\u8f6e\u8be2\uff1a\u8ddf\u636e\u914d\u7f6e\u7684\u6743\u91cd\u7684\u5927\u5c0f\u800c\u5206\u53d1\u7ed9\u4e0d\u540c\u670d\u52a1\u5668\u4e0d\u540c\u6570\u91cf\u7684\u8bf7\u6c42\u3002\u5982\u679c\u4e0d\u8bbe\u7f6e\uff0c\u5219\u9ed8\u8ba4\u4e3a1\u3002\u4e0b\u9762\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u987a\u5e8f\u4e3a\uff1aABBABBABBABBABB\u2026<\/div>\n<div><\/div>\n<div>upstream mysvr {<br \/>\nserver 127.0.0.1:7878 weight=1;<br \/>\nserver 192.168.10.121:3333 weight=2;<br \/>\n}<br \/>\nserver {<br \/>\nlisten 8081; #\u76d1\u542c\u7aef\u53e3<br \/>\nserver_name 127.0.0.1; #\u76d1\u542c\u5730\u5740<br \/>\nlocation \/{<br \/>\nproxy_pass http:\/\/mysvr; #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868<br \/>\n}<br \/>\n}<\/div>\n<div>2.4 ip_hash \u8d1f\u8f7d\u5747\u8861<\/div>\n<div>ip_hash:nginx\u4f1a\u8ba9\u76f8\u540c\u7684\u5ba2\u6237\u7aefip\u8bf7\u6c42\u76f8\u540c\u7684\u670d\u52a1\u5668\u3002<\/div>\n<div><\/div>\n<div>upstream mysvr {<br \/>\nserver 127.0.0.1:7878;<br \/>\nserver 192.168.10.121:3333;<br \/>\nip_hash;<br \/>\n}<br \/>\nserver {<br \/>\nlisten 8081; #\u76d1\u542c\u7aef\u53e3<br \/>\nserver_name 127.0.0.1; #\u76d1\u542c\u5730\u5740<br \/>\nlocation \/{<br \/>\nproxy_pass http:\/\/mysvr; #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868<br \/>\n}<br \/>\n}<\/div>\n<div>2.5 \u5bf9\u7279\u5b9a\u8d44\u6e90\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861<\/div>\n<div>\u901a\u8fc7\u591a\u4e2aupstream\u5206\u6210\u591a\u4e2a\u670d\u52a1\u5668\u7ec4\uff0c\u5c06\u4e0d\u540c\u7684\u8bf7\u6c42\u5206\u6d41\u5230\u4e0d\u540c\u7684<\/div>\n<div><\/div>\n<div>\n<p>upstream videomysvr {<br \/>\nserver 127.0.0.1:7878 weight=1;<br \/>\nserver 192.168.10.121:3333 weight=2;<br \/>\n}<\/p>\n<p>upstream filemysvr {<br \/>\nserver 192.3.2.1:7878 weight=1;<br \/>\nserver 192.3.2.2:3333 weight=2;<br \/>\n}<br \/>\nserver {<br \/>\nlisten 8081; #\u76d1\u542c\u7aef\u53e3<br \/>\nserver_name 127.0.0.1; #\u76d1\u542c\u5730\u5740<br \/>\nlocation \/video\/ {<br \/>\nproxy_pass http:\/\/videomysvr; #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868<br \/>\n}<br \/>\nlocation \/file\/ {<br \/>\nproxy_pass http:\/\/filemysvr; #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868<br \/>\n}<br \/>\n}<\/p>\n<\/div>\n<div>2.6 \u5bf9\u4e0d\u540c\u57df\u540d\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861<\/div>\n<div>\n<p>upstream videomysvr {<br \/>\nserver 127.0.0.1:7878 weight=1;<br \/>\nserver 192.168.10.121:3333 weight=2;<br \/>\n}<\/p>\n<p>upstream filemysvr {<br \/>\nserver 192.3.2.1:7878 weight=1;<br \/>\nserver 192.3.2.2:3333 weight=2;<br \/>\n}<br \/>\nserver {<br \/>\nlisten 8081; #\u76d1\u542c\u7aef\u53e3<br \/>\nserver_name www.ustc.edu.cn; #\u76d1\u542c\u5730\u5740<br \/>\nlocation \/video\/ {<br \/>\nproxy_pass http:\/\/videomysvr; #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868<br \/>\n}<br \/>\n}<br \/>\nserver {<br \/>\nlisten 8082; #\u76d1\u542c\u7aef\u53e3<br \/>\nserver_name www.ustc.sse.edu.cn; #\u76d1\u542c\u5730\u5740<br \/>\nlocation \/file\/ {<br \/>\nproxy_pass http:\/\/filemysvr; #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868<br \/>\n}<br \/>\n}<\/p>\n<\/div>\n<div>2.7 \u5b9e\u73b0\u5e26\u6709URL\u91cd\u5199\u7684\u8d1f\u8f7d\u5747\u8861<\/div>\n<div>\n<div>upstream backend{<\/div>\n<div>server 192.168.200.146:9001;<\/div>\n<div>server 192.168.200.146:9002;<\/div>\n<div>server 192.168.200.146:9003;<\/div>\n<div>}<\/div>\n<div>server {<\/div>\n<div>listen80;<\/div>\n<div>server_name localhost;<\/div>\n<div>location \/file\/ {<\/div>\n<div>rewrite ^(\/file\/.*) \/server\/$1 last;<\/div>\n<div>}<\/div>\n<div>location \/ {<\/div>\n<div>proxy_pass http:\/\/backend;<\/div>\n<div>}<\/div>\n<div>}<\/div>\n<\/div>\n<div>2.8 \u56db\u5c42\u8d1f\u8f7d\u5747\u8861<\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1460\" title=\"1ee51f6a64e847efeb7f48dca4d0026c-1-1-1\" src=\"https:\/\/blog.nonot.cn\/wp-content\/uploads\/replace\/17dadc7cdd714a9ce546f4e647dfbf4d.png\" alt=\"1ee51f6a64e847efeb7f48dca4d0026c-1-1-1\" width=\"770\" height=\"284\" \/><\/div>\n<div>\u9996\u5148\u5b89\u88c5\u597dredis\u548ctomcat<\/div>\n<div><\/div>\n<div>stream { # \u4e00\u7ea7\u62ec\u53f7<br \/>\nupstream redisbackend {<br \/>\nserver 192.168.200.146:6379;<br \/>\nserver 192.168.200.146:6378;<br \/>\n}<br \/>\nupstream tomcatbackend {<br \/>\nserver 192.168.200.146:8080;<br \/>\n}<br \/>\nserver {<br \/>\nlisten 81;<br \/>\nproxy_pass redisbackend;<br \/>\n}<br \/>\nserver {<br \/>\nlisten 82;<br \/>\nproxy_pass tomcatbackend;<br \/>\n}<br \/>\n}<\/div>\n<div>\u4e09\u3001Nginx \u7f13\u5b58<\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1461\" title=\"2715dfee9c5bbbe2a2b6cfe9c8d41487-1-1\" src=\"https:\/\/blog.nonot.cn\/wp-content\/uploads\/replace\/9897ed7afce887dab00a9a3671e36a84.png\" alt=\"2715dfee9c5bbbe2a2b6cfe9c8d41487-1-1\" width=\"771\" height=\"232\" \/><\/div>\n<div>nginx \u7f13\u5b58\u7684\u597d\u5904<\/div>\n<div><\/div>\n<div>\u51cf\u8f7b\u670d\u52a1\u5668\u8d1f\u8f7d<\/div>\n<div>\u63d0\u4f9b\u7f51\u9875\u54cd\u5e94\u6548\u7387<\/div>\n<div>\u964d\u4f4e\u7f51\u7edc\u963b\u585e\uff0c\u589e\u5f3a\u7f51\u7edc\u53ef\u6269\u5c55\u6027<\/div>\n<div>3.1 nginx \u7684\u7f13\u5b58\u673a\u5236<\/div>\n<div>\u914d\u7f6e\u5757 \u540d\u79f0 \u540d\u79f0<\/div>\n<div>http proxy_cache_path \u6307\u5b9a\u7f13\u51b2\u533a\u7684\u8def\u5f84<\/div>\n<div>levels \u7f13\u5b58\u76ee\u5f55\u7ea7\u6700\u9ad8\u4e09\u5c42\uff0c\u6bcf\u5c421-2\u4e2a\u5b57\u7b26\u8868\u793a\uff0c\u6bd4\u5982\uff1a1:1:2 \u4e09\u5c42<\/div>\n<div>keys_zone \u7f13\u5b58\u5757\u540d\u79f0\u53ca\u5185\u5b58\u5757\u5927\u5c0f\uff0c\u6bd4\u5982\uff1acache_item:500m\u8868\u793a\u58f0\u660e\u4e00\u4e2a\u540d\u4e3acache_item\u5927\u5c0f\u4e3a500m\uff0c\u8d85\u51fa\u5927\u5c0f\u540e\u6700\u65e9\u7684\u88ab\u6e05\u9664<\/div>\n<div>max_size \u7f13\u5b58\u533a\u786c\u76d8\u7684\u6700\u5927\u503c\uff0c\u8d85\u51fa\u95f2\u7f6e\u6570\u636e\u5c06\u88ab\u6e05\u9664<\/div>\n<div>inactive \u6700\u957f\u95f2\u7f6e\u65f6\u95f4\uff0c\u6bd4\u5982\uff1a10d \uff0c\u8868\u793a\u4e00\u4e2a\u6570\u636e\u88ab\u95f2\u7f6e10\u5929\u5219\u5c06\u88ab\u6e05\u9664<\/div>\n<div>location proxy_cache \u6307\u5b9a\u7f13\u51b2\u533a\uff0c\u5bf9\u5e94keys_zone\u4e2d\u7684\u8bbe\u5b9a\u7684\u503c<\/div>\n<div>proxy_cache_key \u901a\u8fc7\u53c2\u6570\u62fc\u88c5\u53c2\u6570key\u5982\uff1ah o s t hosthosturii s a r g s is_argsisargsargs \u5219\u4f1a\u5df2\u5168\u90e8md5\u503c\u4f5c\u4e3akey<\/div>\n<div>proxy_cache_valid \u5bf9\u4e0d\u540c\u7684\u72b6\u6001\u7801\u8bbe\u7f6e\u7f13\u5b58\u6709\u6548\u671f<\/div>\n<div>http\u6a21\u5757\uff1a<\/div>\n<div><\/div>\n<div>proxy_cache_path\uff1a\u8be5\u6307\u5b9a\u7528\u4e8e\u8bbe\u7f6e\u7f13\u5b58\u6587\u4ef6\u7684\u5b58\u653e\u8def\u5f84<\/div>\n<div>levels: \u6307\u5b9a\u8be5\u7f13\u5b58\u7a7a\u95f4\u5bf9\u5e94\u7684\u76ee\u5f55\uff0c\u6700\u591a\u53ef\u4ee5\u8bbe\u7f6e3\u5c42\uff0c\u6bcf\u5c42\u53d6\u503c\u4e3a1|2\u5982 : levels=1:2 \u7f13\u5b58\u7a7a\u95f4\u6709\u4e24\u5c42\u76ee\u5f55\uff0c\u7b2c\u4e00\u6b21\u662f1\u4e2a\u5b57\u6bcd\uff0c\u7b2c\u4e8c\u6b21\u662f2\u4e2a\u5b57\u6bcd;levels=2:2:2 \u6700\u7ec8\u7684\u5b58\u50a8\u8def\u5f84\u4e3a \/usr\/local\/proxy_cache\/7d\/10\/e2<\/div>\n<div>keys_zone\uff1a\u7528\u6765\u4e3a\u8fd9\u4e2a\u7f13\u5b58\u533a\u8bbe\u7f6e\u540d\u79f0\u548c\u6307\u5b9a\u5927\u5c0f\uff0c\u5982\uff1akeys_zone=ffideal:200m \u7f13\u5b58\u533a\u7684\u540d\u79f0\u662fffideal\uff0c\u5927\u5c0f\u4e3a200M\uff0c1M\u5927\u6982\u80fd\u5b58\u50a88000\u4e2akeys<\/div>\n<div>inactive\uff1a\u6307\u5b9a\u7f13\u5b58\u7684\u6570\u636e\u591a\u6b21\u65f6\u95f4\u672a\u88ab\u8bbf\u95ee\u5c31\u5c06\u88ab\u5220\u9664\uff0c\u5982\uff1ainactive=1d \uff0c\u7f13\u5b58\u6570\u636e\u57281\u5929\u5185\u6ca1\u6709\u88ab\u8bbf\u95ee\u5c31\u4f1a\u88ab\u5220\u9664<\/div>\n<div>max_size\uff1a\u8bbe\u7f6e\u6700\u5927\u7f13\u5b58\u7a7a\u95f4\uff0c\u5982\u679c\u7f13\u5b58\u7a7a\u95f4\u5b58\u6ee1\uff0c\u9ed8\u8ba4\u4f1a\u8986\u76d6\u7f13\u5b58\u65f6\u95f4\u6700\u957f\u7684\u8d44\u6e90\uff0c\u5982:max_size=20g<\/div>\n<div>\n<p>http{<br \/>\n# proxy_cache_path path [levels=number]<br \/>\n# keys_zone=zone_name:zone_size [inactive=time][max_size=size];<br \/>\nproxy_cache_path \/usr\/local\/proxy_cache levels=1:2:1 keys_zone=ffideal:200m inactive=1d max_size=20g<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div>location\uff1a<\/div>\n<div><\/div>\n<div>proxy_cache<\/div>\n<div>\u8be5\u6307\u4ee4\u7528\u6765\u5f00\u542f\u6216\u5173\u95ed\u4ee3\u7406\u7f13\u5b58\uff0c\u5982\u679c\u662f\u5f00\u542f\u5219\u81ea\u5b9a\u4f7f\u7528\u54ea\u4e2a\u7f13\u5b58\u533a\u6765\u8fdb\u884c\u7f13\u5b58\u3002<\/div>\n<div><\/div>\n<div>\u8bed\u6cd5 proxy_cache zone_name|off;<\/div>\n<div>\u9ed8\u8ba4\u503c proxy_cache off;<\/div>\n<div>\u4f4d\u7f6e http\u3001server\u3001location<\/div>\n<div>zone_name\uff1a\u6307\u5b9a\u4f7f\u7528\u7f13\u5b58\u533a\u7684\u540d\u79f0<\/div>\n<div><\/div>\n<div>proxy_cache_key<\/div>\n<div>\u8be5\u6307\u4ee4\u7528\u6765\u8bbe\u7f6eweb\u7f13\u5b58\u7684key\u503c\uff0cNginx\u4f1a\u6839\u636ekey\u503cMD5\u54c8\u5e0c\u5b58\u7f13\u5b58\u3002<\/div>\n<div><\/div>\n<div>\u8bed\u6cd5 proxy_cache_key key;<\/div>\n<div>\u9ed8\u8ba4\u503c proxy_cache_key $scheme$proxy_host$request_uri;<\/div>\n<div>\u4f4d\u7f6e http\u3001server\u3001location<\/div>\n<div>proxy_cache_valid<\/div>\n<div>\u8be5\u6307\u4ee4\u7528\u6765\u5bf9\u4e0d\u540c\u8fd4\u56de\u72b6\u6001\u7801\u7684URL\u8bbe\u7f6e\u4e0d\u540c\u7684\u7f13\u5b58\u65f6\u95f4<\/div>\n<div><\/div>\n<div>\u8bed\u6cd5 proxy_cache_valid [code \u2026] time;<\/div>\n<div>\u9ed8\u8ba4\u503c \u2014<\/div>\n<div>\u4f4d\u7f6e http\u3001server\u3001location<\/div>\n<div>\u5982\uff1a<\/div>\n<div>proxy_cache_valid 200 302 10m;<br \/>\nproxy_cache_valid 404 1m;<br \/>\n\u4e3a200\u548c302\u7684\u54cd\u5e94URL\u8bbe\u7f6e10\u5206\u949f\u7f13\u5b58\uff0c\u4e3a404\u7684\u54cd\u5e94URL\u8bbe\u7f6e1\u5206\u949f\u7f13\u5b58<br \/>\nproxy_cache_valid any 1m;<br \/>\n\u5bf9\u6240\u6709\u54cd\u5e94\u72b6\u6001\u7801\u7684URL\u90fd\u8bbe\u7f6e1\u5206\u949f\u7f13\u5b58<\/div>\n<div><\/div>\n<div>proxy_cache_min_uses<\/div>\n<div>\u8be5\u6307\u4ee4\u7528\u6765\u8bbe\u7f6e\u8d44\u6e90\u88ab\u8bbf\u95ee\u591a\u5c11\u6b21\u540e\u88ab\u7f13\u5b58<\/div>\n<div><\/div>\n<div>\u8bed\u6cd5 proxy_cache_min_uses number;<\/div>\n<div>\u9ed8\u8ba4\u503c proxy_cache_min_uses 1;<\/div>\n<div>\u4f4d\u7f6e http\u3001server\u3001location<\/div>\n<div>proxy_cache_methods<\/div>\n<div>\u8be5\u6307\u4ee4\u7528\u6237\u8bbe\u7f6e\u7f13\u5b58\u54ea\u4e9bHTTP\u65b9\u6cd5<\/div>\n<div><\/div>\n<div>\u8bed\u6cd5 proxy_cache_methods GET|HEAD|POST;<\/div>\n<div>\u9ed8\u8ba4\u503c proxy_cache_methods GET HEAD;<\/div>\n<div>\u4f4d\u7f6e http\u3001server\u3001location<\/div>\n<div>\u9ed8\u8ba4\u7f13\u5b58HTTP\u7684GET\u548cHEAD\u65b9\u6cd5\uff0c\u4e0d\u7f13\u5b58POST\u65b9\u6cd5\u3002<\/div>\n<div><\/div>\n<div>3.2 \u7f13\u5b58\u5b9e\u4f8b<\/div>\n<div>Nginx\u7684\u73af\u5883\u51c6\u5907<\/div>\n<div><\/div>\n<div>\uff081\uff09\u5b8c\u6210Nginx\u53cd\u5411\u4ee3\u7406\u914d\u7f6e<\/div>\n<div><\/div>\n<div>http{<\/div>\n<div>upstream backend{<\/div>\n<div>server 192.168.200.146:8080;<\/div>\n<div>}<\/div>\n<div>server {<\/div>\n<div>listen\u00a0 \u00a0 \u00a0 \u00a08080;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 server_name\u00a0 localhost;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 location \/ {<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 proxy_pass http:\/\/backend\/js\/;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 }<\/div>\n<div>}<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>\uff082\uff09\u5b8c\u6210Nginx\u7f13\u5b58\u914d\u7f6e<\/div>\n<div><\/div>\n<div>4.\u6dfb\u52a0\u7f13\u5b58\u914d\u7f6e<\/div>\n<div><\/div>\n<div>http{<\/div>\n<div>proxy_cache_path \/usr\/local\/proxy_cache levels=2:1 keys_zone=itcast:200m inactive=1d max_size=20g;<\/div>\n<div>upstream backend{<\/div>\n<div>server 192.168.200.146:8080;<\/div>\n<div>}<\/div>\n<div>server {<\/div>\n<div>listen\u00a0 \u00a0 \u00a0 \u00a08080;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 server_name\u00a0 localhost;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 location \/ {<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 proxy_cache itcast;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 proxy_cache_key itheima;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 proxy_cache_min_uses 5;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 proxy_cache_valid 200 5d;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 proxy_cache_valid 404 30s;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 proxy_cache_valid any 1m;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 add_header nginx-cache &#8220;$upstream_cache_status&#8221;;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 proxy_pass http:\/\/backend\/js\/;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 }<\/div>\n<div>}<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>3.3 Nginx\u7f13\u5b58\u7684\u6e05\u9664<\/div>\n<div>\u65b9\u5f0f\u4e00:\u5220\u9664\u5bf9\u5e94\u7684\u7f13\u5b58\u76ee\u5f55<\/div>\n<div><\/div>\n<div>rm -rf \/usr\/local\/proxy_cache\/&#8230;&#8230;<\/div>\n<div><\/div>\n<div>\u65b9\u5f0f\u4e8c:\u4f7f\u7528\u7b2c\u4e09\u65b9\u6269\u5c55\u6a21\u5757<\/div>\n<div><\/div>\n<div>ngx_cache_purge<\/div>\n<div><\/div>\n<div>\uff081\uff09\u4e0b\u8f7dngx_cache_purge\u6a21\u5757\u5bf9\u5e94\u7684\u8d44\u6e90\u5305\uff0c\u5e76\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u4e0a\u3002<\/div>\n<div><\/div>\n<div>ngx_cache_purge-2.3.tar.gz<\/div>\n<div><\/div>\n<div>\uff082\uff09\u5bf9\u8d44\u6e90\u6587\u4ef6\u8fdb\u884c\u89e3\u538b\u7f29<\/div>\n<div><\/div>\n<div>tar -zxf ngx_cache_purge-2.3.tar.gz<\/div>\n<div><\/div>\n<div>\uff083\uff09\u4fee\u6539\u6587\u4ef6\u5939\u540d\u79f0\uff0c\u65b9\u4fbf\u540e\u671f\u914d\u7f6e<\/div>\n<div><\/div>\n<div>mv ngx_cache_purge-2.3 purge<\/div>\n<div><\/div>\n<div>\uff084\uff09\u67e5\u8be2Nginx\u7684\u914d\u7f6e\u53c2\u6570<\/div>\n<div><\/div>\n<div>nginx -V<\/div>\n<div><\/div>\n<div>\uff085\uff09\u8fdb\u5165Nginx\u7684\u5b89\u88c5\u76ee\u5f55\uff0c\u4f7f\u7528.\/configure\u8fdb\u884c\u53c2\u6570\u914d\u7f6e<\/div>\n<div><\/div>\n<div>.\/configure &#8211;add-module=\/root\/nginx\/module\/purge<\/div>\n<div><\/div>\n<div>\uff086\uff09\u4f7f\u7528make\u8fdb\u884c\u7f16\u8bd1<\/div>\n<div><\/div>\n<div>make<\/div>\n<div><\/div>\n<div>\uff087\uff09\u5c06nginx\u5b89\u88c5\u76ee\u5f55\u7684nginx\u4e8c\u7ea7\u5236\u53ef\u6267\u884c\u6587\u4ef6\u5907\u4efd<\/div>\n<div><\/div>\n<div>mv \/usr\/local\/nginx\/sbin\/nginx \/usr\/local\/nginx\/sbin\/nginxold<\/div>\n<div><\/div>\n<div>\uff088\uff09\u5c06\u7f16\u8bd1\u540e\u7684objs\u4e2d\u7684nginx\u62f7\u8d1d\u5230nginx\u7684sbin\u76ee\u5f55\u4e0b<\/div>\n<div><\/div>\n<div>cp objs\/nginx \/usr\/local\/nginx\/sbin<\/div>\n<div><\/div>\n<div>\uff089\uff09\u4f7f\u7528make\u8fdb\u884c\u5347\u7ea7<\/div>\n<div><\/div>\n<div>make upgrade<\/div>\n<div><\/div>\n<div>\uff0810\uff09\u5728nginx\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fdb\u884c\u5982\u4e0b\u914d\u7f6e<\/div>\n<div><\/div>\n<div>server{<\/div>\n<div>location ~\/purge(\/.*) {<\/div>\n<div>proxy_cache_purge itcast itheima;<\/div>\n<div>}<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>3.4 Nginx\u8bbe\u7f6e\u8d44\u6e90\u4e0d\u7f13\u5b58<\/div>\n<div>\u524d\u9762\u54b1\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86Nginx\u4f5c\u4e3aweb\u7f13\u5b58\u670d\u52a1\u5668\u7684\u4f7f\u7528\u3002\u4f46\u662f\u6211\u4eec\u5f97\u601d\u8003\u4e00\u4e2a\u95ee\u9898\u5c31\u662f\u4e0d\u662f\u6240\u6709\u7684\u6570\u636e\u90fd\u9002\u5408\u8fdb\u884c\u7f13\u5b58\u3002\u6bd4\u5982\u8bf4\u5bf9\u4e8e\u4e00\u4e9b\u7ecf\u5e38\u53d1\u751f\u53d8\u5316\u7684\u6570\u636e\u3002\u5982\u679c\u8fdb\u884c\u7f13\u5b58\u7684\u8bdd\uff0c\u5c31\u5f88\u5bb9\u6613\u51fa\u73b0\u7528\u6237\u8bbf\u95ee\u5230\u7684\u6570\u636e\u4e0d\u662f\u670d\u52a1\u5668\u771f\u5b9e\u7684\u6570\u636e\u3002\u6240\u4ee5\u5bf9\u4e8e\u8fd9\u4e9b\u8d44\u6e90\u6211\u4eec\u5728\u7f13\u5b58\u7684\u8fc7\u7a0b\u4e2d\u5c31\u9700\u8981\u8fdb\u884c\u8fc7\u6ee4\uff0c\u4e0d\u8fdb\u884c\u7f13\u5b58\u3002<\/div>\n<div><\/div>\n<div>Nginx\u4e5f\u63d0\u4f9b\u4e86\u8fd9\u5757\u7684\u529f\u80fd\u8bbe\u7f6e\uff0c\u9700\u8981\u4f7f\u7528\u5230\u5982\u4e0b\u4e24\u4e2a\u6307\u4ee4<\/div>\n<div><\/div>\n<div>proxy_no_cache<\/div>\n<div><\/div>\n<div>\u8be5\u6307\u4ee4\u662f\u7528\u6765\u5b9a\u4e49\u4e0d\u5c06\u6570\u636e\u8fdb\u884c\u7f13\u5b58\u7684\u6761\u4ef6\u3002<\/div>\n<div><\/div>\n<div>\u8bed\u6cd5 proxy_no_cache string \u2026;<\/div>\n<div>\u9ed8\u8ba4\u503c \u2014<\/div>\n<div>\u4f4d\u7f6e http\u3001server\u3001location<\/div>\n<div>\u914d\u7f6e\u5b9e\u4f8b<\/div>\n<div><\/div>\n<div>proxy_no_cache $cookie_nocache $arg_nocache $arg_comment;<\/div>\n<div><\/div>\n<div>proxy_cache_bypass<\/div>\n<div><\/div>\n<div>\u8be5\u6307\u4ee4\u662f\u7528\u6765\u8bbe\u7f6e\u4e0d\u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e\u7684\u6761\u4ef6\u3002<\/div>\n<div><\/div>\n<div>\u8bed\u6cd5 proxy_cache_bypass string \u2026;<\/div>\n<div>\u9ed8\u8ba4\u503c \u2014<\/div>\n<div>\u4f4d\u7f6e http\u3001server\u3001location<\/div>\n<div>\u914d\u7f6e\u5b9e\u4f8b<\/div>\n<div><\/div>\n<div>proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;<\/div>\n<div><\/div>\n<div>\u4e0a\u8ff0\u4e24\u4e2a\u6307\u4ee4\u90fd\u6709\u4e00\u4e2a\u6307\u5b9a\u7684\u6761\u4ef6\uff0c\u8fd9\u4e2a\u6761\u4ef6\u53ef\u4ee5\u662f\u591a\u4e2a\uff0c\u5e76\u4e14\u591a\u4e2a\u6761\u4ef6\u4e2d\u81f3\u5c11\u6709\u4e00\u4e2a\u4e0d\u4e3a\u7a7a\u4e14\u4e0d\u7b49\u4e8e&#8221;0&#8243;,\u5219\u6761\u4ef6\u6ee1\u8db3\u6210\u7acb\u3002\u4e0a\u9762\u7ed9\u7684\u914d\u7f6e\u5b9e\u4f8b\u662f\u4ece\u5b98\u65b9\u7f51\u7ad9\u83b7\u53d6\u7684\uff0c\u91cc\u9762\u4f7f\u7528\u5230\u4e86\u4e09\u4e2a\u53d8\u91cf\uff0c\u5206\u522b\u662f$cookie_nocache\u3001$arg_nocache\u3001$arg_comment<\/div>\n<div><\/div>\n<div>$cookie_nocache\u3001$arg_nocache\u3001$arg_comment<\/div>\n<div><\/div>\n<div>\u8fd9\u4e09\u4e2a\u53c2\u6570\u5206\u522b\u4ee3\u8868\u7684\u542b\u4e49\u662f:<\/div>\n<div><\/div>\n<div>$cookie_nocache<\/div>\n<div>\u6307\u7684\u662f\u5f53\u524d\u8bf7\u6c42\u7684cookie\u4e2d\u952e\u7684\u540d\u79f0\u4e3anocache\u5bf9\u5e94\u7684\u503c<\/div>\n<div>$arg_nocache\u548c$arg_comment<\/div>\n<div>\u6307\u7684\u662f\u5f53\u524d\u8bf7\u6c42\u7684\u53c2\u6570\u4e2d\u5c5e\u6027\u540d\u4e3anocache\u548ccomment\u5bf9\u5e94\u7684\u5c5e\u6027\u503c<\/div>\n<div><\/div>\n<div>\u6848\u4f8b\u6f14\u793a\u4e0b:<\/div>\n<div><\/div>\n<div>log_format params $cookie_nocache | $arg_nocache | $arg_comment\uff1b<\/div>\n<div>server{<\/div>\n<div>listen8081;<\/div>\n<div>server_name localhost;<\/div>\n<div>location \/{<\/div>\n<div>access_log logs\/access_params.log params;<\/div>\n<div>add_header Set-Cookie &#8216;nocache=999&#8217;;<\/div>\n<div>root html;<\/div>\n<div>index index.html;<\/div>\n<div>}<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>\u6848\u4f8b\u5b9e\u73b0<\/div>\n<div><\/div>\n<div>\u8bbe\u7f6e\u4e0d\u7f13\u5b58\u8d44\u6e90\u7684\u914d\u7f6e\u65b9\u6848<\/div>\n<div><\/div>\n<div>server{<\/div>\n<div>listen8080;<\/div>\n<div>server_name localhost;<\/div>\n<div>location \/ {<\/div>\n<div>if ($request_uri ~ \/.*.js$){<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0set $nocache 1;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 }<\/div>\n<div>proxy_no_cache $nocache $cookie_nocache $arg_nocache $arg_comment;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 proxy_cache_bypass $nocache $cookie_nocache $arg_nocache $arg_comment;<\/div>\n<div>}<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>\u56db\u3001\u53c2\u8003\u8d44\u6599<\/div>\n<div>https:\/\/www.runoob.com\/w3cnote\/nginx-setup-intro.html<\/div>\n<div><\/div>\n<div>https:\/\/www.runoob.com\/w3cnote\/nginx-proxy-balancing.html<\/div>\n<div>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/div>\n<div><\/div>\n<div>\u00a0\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3a\u535a\u4e3b\u539f\u521b\u6587\u7ae0\uff0c\u9075\u5faa CC 4.0 BY-SA \u7248\u6743\u534f\u8bae\uff0c\u8f6c\u8f7d\u8bf7\u9644\u4e0a\u539f\u6587\u51fa\u5904\u94fe\u63a5\u548c\u672c\u58f0\u660e\u3002<\/div>\n<div>\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/blog.csdn.net\/xt199711\/article\/details\/137258815<\/div>\n","protected":false},"excerpt":{"rendered":"<p>nginx | nginx\u53cd\u5411\u4ee3\u7406\/\u8d1f\u8f7d\u5747\u8861\/\u7f13\u5b58 \u00a0\u672c\u6587\u8be6&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1428","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/1428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1428"}],"version-history":[{"count":1,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/1428\/revisions"}],"predecessor-version":[{"id":1466,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/1428\/revisions\/1466"}],"wp:attachment":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}