{"id":577,"date":"2024-05-07T18:41:13","date_gmt":"2024-05-07T10:41:13","guid":{"rendered":"http:\/\/www.madbull.site\/?p=577"},"modified":"2024-12-04T10:15:11","modified_gmt":"2024-12-04T02:15:11","slug":"nginx%e5%9f%ba%e6%9c%ac%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.madbull.site\/?p=577","title":{"rendered":"nginx\u914d\u7f6e\u5e38\u7528\u53c2\u6570"},"content":{"rendered":"\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"has-large-font-size\"><strong>\u5185\u7f6e\u53d8\u91cf<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$remote_addr\uff1a\u5ba2\u6237\u7aef\u7684IP\u5730\u5740\u3002\n$remote_port\uff1a\u5ba2\u6237\u7aef\u7684\u7aef\u53e3\u3002\n$server_addr\uff1a\u670d\u52a1\u5668\u5730\u5740\uff0c\u5728\u5b8c\u6210\u4e00\u6b21\u7cfb\u7edf\u8c03\u7528\u540e\u53ef\u4ee5\u786e\u5b9a\u8fd9\u4e2a\u503c\u3002\n$server_port\uff1a\u8bf7\u6c42\u5230\u8fbe\u670d\u52a1\u5668\u7684\u7aef\u53e3\u53f7\u3002\n$server_protocol\uff1a\u8bf7\u6c42\u4f7f\u7528\u7684\u534f\u8bae\uff0c\u901a\u5e38\u662fHTTP\/1.0\u6216HTTP\/1.1\u3002\n$http_host\uff1a\u8bf7\u6c42\u4e2d\u7684Host\u5934\u5b57\u6bb5\uff0c\u5982\u679c\u8bf7\u6c42\u4e2d\u6ca1\u6709Host\u5934\u5b57\u6bb5\uff0c\u5219\u7b49\u4e8e$server_name\u3002\n$request_uri\uff1a\u5305\u542b\u8bf7\u6c42\u53c2\u6570\u7684\u539f\u59cbURI\uff0c\u4e0d\u5305\u542b\u4e3b\u673a\u540d\uff0c\u5982\uff1a\"\/foo\/bar.php?arg=baz\"\u3002\n$document_uri\uff1a\u4e0e$uri\u76f8\u540c\u3002\n$request_filename\uff1a\u5f53\u524d\u8bf7\u6c42\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u7531root\u6216alias\u6307\u4ee4\u4e0eURI\u8bf7\u6c42\u751f\u6210\u3002\n$args\uff1a\u8fd9\u4e2a\u53d8\u91cf\u7b49\u4e8e\u8bf7\u6c42\u884c\u4e2d\u7684\u53c2\u6570\uff0c\u540c$query_string\u3002\n$query_string\uff1a\u8fd9\u4e2a\u53d8\u91cf\u4e0e$args\u76f8\u540c\u3002<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20);height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"has-large-font-size\"><strong>\u4ee3\u7406\u76f8\u5173\u53d8\u91cf<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>proxy_pass\uff1a\n    \u6307\u5b9a\u4ee3\u7406\u670d\u52a1\u5668\u7684\u5730\u5740\u548c\u7aef\u53e3\uff0c\u4ee5\u53ca\u53ef\u9009\u7684URI\u3002Nginx\u4f1a\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u8fd9\u4e2a\u5730\u5740\u3002\n    \u793a\u4f8b\uff1aproxy_pass http:\/\/backend_server;\nproxy_set_header\uff1a\n    \u5141\u8bb8\u4f60\u91cd\u65b0\u5b9a\u4e49\u6216\u6dfb\u52a0\u53d1\u9001\u5230\u4ee3\u7406\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u5934\u3002\n    \u5e38\u89c1\u7684\u7528\u6cd5\u5305\u62ec\u8bbe\u7f6eHost\u3001X-Real-IP\u3001X-Forwarded-For\u7b49\u5934\u3002\n    \u793a\u4f8b\uff1a\n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\nproxy_hide_header\uff1a\n    \u6307\u5b9a\u54ea\u4e9b\u5934\u4e0d\u5e94\u8be5\u88ab\u53d1\u9001\u5230\u5ba2\u6237\u7aef\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cNginx\u4e0d\u4f1a\u8f6c\u53d1\u67d0\u4e9b\u5934\uff0c\u5982Date\u3001Server\u7b49\uff0c\u4f46\u4f60\u53ef\u4ee5\u4f7f\u7528\u6b64\u6307\u4ee4\u6dfb\u52a0\u5176\u4ed6\u5934\u3002\n    \u793a\u4f8b\uff1aproxy_hide_header X-Powered-By;\nproxy_connect_timeout\uff1a\n    \u8bbe\u7f6e\u4e0e\u4ee3\u7406\u670d\u52a1\u5668\u7684\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\u3002\n    \u793a\u4f8b\uff1aproxy_connect_timeout 60s;\nproxy_send_timeout\uff1a\n    \u8bbe\u7f6e\u5411\u4ee3\u7406\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42\u7684\u8d85\u65f6\u65f6\u95f4\u3002\n    \u793a\u4f8b\uff1aproxy_send_timeout 60s;\nproxy_read_timeout\uff1a\n    \u8bbe\u7f6e\u4ece\u4ee3\u7406\u670d\u52a1\u5668\u8bfb\u53d6\u54cd\u5e94\u7684\u8d85\u65f6\u65f6\u95f4\u3002\n    \u793a\u4f8b\uff1aproxy_read_timeout 60s;\nproxy_buffering\uff1a\n    \u542f\u7528\u6216\u7981\u7528\u4ece\u4ee3\u7406\u670d\u52a1\u5668\u8bfb\u53d6\u54cd\u5e94\u7684\u7f13\u51b2\u3002\n    \u793a\u4f8b\uff1aproxy_buffering on; \u6216 proxy_buffering off;\nproxy_buffer_size\uff1a\n    \u8bbe\u7f6e\u5355\u4e2a\u7f13\u51b2\u533a\u7684\u5927\u5c0f\u3002\n    \u793a\u4f8b\uff1aproxy_buffer_size 4k;\nproxy_buffers\uff1a\n    \u8bbe\u7f6e\u54cd\u5e94\u7f13\u51b2\u533a\u7684\u6570\u91cf\u548c\u5927\u5c0f\u3002\n    \u793a\u4f8b\uff1aproxy_buffers 8 32k;\uff088\u4e2a\u7f13\u51b2\u533a\uff0c\u6bcf\u4e2a\u7f13\u51b2\u533a32k\u5927\u5c0f\uff09\nproxy_busy_buffers_size\uff1a\n    \u5728\u54cd\u5e94\u88ab\u53d1\u9001\u5230\u5ba2\u6237\u7aef\u4e4b\u524d\uff0cNginx\u4f1a\u5c3d\u91cf\u5c06\u5c3d\u53ef\u80fd\u591a\u7684\u6570\u636e\u4ece\u4ee3\u7406\u670d\u52a1\u5668\u8bfb\u53d6\u5230\u7f13\u51b2\u533a\u4e2d\u3002\u8fd9\u4e2a\u6307\u4ee4\u8bbe\u7f6e\u4e86\u5728\u9ad8\u6d41\u91cf\u671f\u95f4\u53ef\u4ee5\u7528\u4e8e\u4e34\u65f6\u5b58\u50a8\u5c1a\u672a\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u7684\u6570\u636e\u7684\u7f13\u51b2\u533a\u5927\u5c0f\u3002\n    \u793a\u4f8b\uff1aproxy_busy_buffers_size 64k;\nproxy_temp_path\uff1a\n    \u8bbe\u7f6e\u7528\u4e8e\u5b58\u50a8\u4e34\u65f6\u6587\u4ef6\u7684\u8def\u5f84\u3002\u5f53Nginx\u9700\u8981\u5c06\u5927\u91cf\u6570\u636e\u4ece\u4ee3\u7406\u670d\u52a1\u5668\u8bfb\u53d6\u5230\u672c\u5730\u6587\u4ef6\u65f6\uff0c\u5b83\u4f1a\u4f7f\u7528\u8fd9\u4e2a\u8def\u5f84\u3002\n    \u793a\u4f8b\uff1aproxy_temp_path \/var\/cache\/nginx\/proxy_temp;\nproxy_max_temp_file_size\uff1a\n    \u8bbe\u7f6eNginx\u53ef\u4ee5\u5199\u5165\u4e34\u65f6\u6587\u4ef6\u7684\u6700\u5927\u6570\u636e\u91cf\u3002\u5f53\u8bf7\u6c42\u4f53\u7684\u5927\u5c0f\u8d85\u8fc7\u6b64\u9650\u5236\u65f6\uff0cNginx\u4f1a\u8fd4\u56de\u4e00\u4e2a\u9519\u8bef\u3002\n    \u793a\u4f8b\uff1aproxy_max_temp_file_size 1024m;\nproxy_method\uff1a\n    \u66f4\u6539\u53d1\u9001\u5230\u4ee3\u7406\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u5c06GET\u8bf7\u6c42\u66f4\u6539\u4e3aPOST\u8bf7\u6c42\u3002\n    \u793a\u4f8b\uff1aproxy_method POST;\nproxy_http_version\uff1a\n    \u8bbe\u7f6e\u4e0e\u4ee3\u7406\u670d\u52a1\u5668\u901a\u4fe1\u7684HTTP\u534f\u8bae\u7248\u672c\u3002\n    \u793a\u4f8b\uff1aproxy_http_version 1.1;\nproxy_ignore_headers\uff1a\n    \u5b9a\u4e49\u54ea\u4e9b\u54cd\u5e94\u5934\u5e94\u8be5\u88abNginx\u5ffd\u7565\uff0c\u800c\u4e0d\u662f\u5e94\u7528\u5230\u5ba2\u6237\u7aef\u8fde\u63a5\u3002\n    \u793a\u4f8b\uff1aproxy_ignore_headers X-Accel-Redirect X-Accel-Expires;<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20);height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"has-large-font-size\"><strong>location\u914d\u7f6e\u683c\u5f0f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>location &#91;=|~|~*|^~|@] \/uri\/ {  \n\n    # \u914d\u7f6e\u6307\u4ee4...  \n\n}\n\n=\uff1a\u7cbe\u786e\u5339\u914d\u3002\u5982\u679c\u8bf7\u6c42\u7684 URI \u5b8c\u5168\u5339\u914d\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\uff0c\u5219\u4f7f\u7528\u8be5 location \u5757\u3002\n~\uff1a\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d\u3002\u5982\u679c\u8bf7\u6c42\u7684 URI \u4e0e\u6307\u5b9a\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\uff0c\u5219\u4f7f\u7528\u8be5 location \u5757\u3002\n~*\uff1a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d\u3002\n^~\uff1a\u5982\u679c\u8bf7\u6c42\u7684 URI \u4ee5\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u5f00\u59cb\uff0c\u5219\u4f7f\u7528\u8be5 location \u5757\uff0c\u5e76\u4e14\u4e0d\u518d\u8fdb\u884c\u6b63\u5219\u5339\u914d\u3002\n@\uff1a\u547d\u540d\u4f4d\u7f6e\uff0c\u901a\u5e38\u7528\u4e8e\u5185\u90e8\u91cd\u5b9a\u5411\u5230\u67d0\u4e2a location\uff0c\u6216\u8005\u7528\u4e8e try_files \u6307\u4ee4\u4e2d\u3002<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20);height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>nginx\u57fa\u672c\u914d\u7f6e\uff0c\u5185\u7f6e\u53d8\u91cf\uff0c\u4ee3\u7406\uff0clocation<\/p>\n","protected":false},"author":1,"featured_media":450,"comment_status":"open","ping_status":"open","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[135,131],"tags":[187,184,186,188,185],"class_list":["post-577","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-131","tag-location","tag-nginx","tag-186","tag-188","tag-185"],"_links":{"self":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=577"}],"version-history":[{"count":3,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/577\/revisions"}],"predecessor-version":[{"id":1840,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/577\/revisions\/1840"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/media\/450"}],"wp:attachment":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}