{"id":63,"date":"2026-07-29T09:00:00","date_gmt":"2026-07-29T01:00:00","guid":{"rendered":"https:\/\/fsdata.site\/?p=63"},"modified":"2026-07-24T00:36:53","modified_gmt":"2026-07-23T16:36:53","slug":"nginx-%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86%e9%85%8d%e7%bd%ae%e8%af%a6%e8%a7%a3%ef%bc%88%e9%99%84-5-%e7%a7%8d%e5%b8%b8%e8%a7%81%e5%9c%ba%e6%99%af%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fsdata.site\/?p=63","title":{"rendered":"Nginx \u53cd\u5411\u4ee3\u7406\u914d\u7f6e\u8be6\u89e3\uff08\u9644 5 \u79cd\u5e38\u89c1\u573a\u666f\uff09"},"content":{"rendered":"<h2>\u4e00\u3001\u53cd\u5411\u4ee3\u7406\u662f\u4ec0\u4e48<\/h2>\n<p>\u53cd\u5411\u4ee3\u7406\u4f4d\u4e8e\u5ba2\u6237\u7aef\u548c\u540e\u7aef\u670d\u52a1\u4e4b\u95f4\uff0c\u5bf9\u5916\u66b4\u9732\u7edf\u4e00\u5165\u53e3\uff0c\u628a\u8bf7\u6c42\u8f6c\u53d1\u5230\u5185\u7f51\u7684\u591a\u53f0\u670d\u52a1\u5668\u3002\u5b83\u89e3\u51b3\u7684\u662f<strong>\u7edf\u4e00\u5165\u53e3\u3001\u8d1f\u8f7d\u5747\u8861\u3001HTTPS \u7ec8\u7ed3\u3001\u9690\u85cf\u540e\u7aef<\/strong>\u7b49\u95ee\u9898\u3002<\/p>\n<h2>\u4e8c\u3001\u6700\u5e38\u7528\u914d\u7f6e\uff1a\u4ee3\u7406\u5230\u540e\u7aef\u670d\u52a1<\/h2>\n<pre><code>server {\n    listen 80;\n    server_name api.example.com;\n    location \/ {\n        proxy_pass http:\/\/127.0.0.1:8080;\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;\n        proxy_set_header X-Forwarded-Proto $scheme;\n    }\n}\n<\/code><\/pre>\n<h2>\u4e09\u3001\u4e94\u79cd\u5e38\u89c1\u573a\u666f<\/h2>\n<h3>1. \u591a\u670d\u52a1\u6309\u8def\u5f84\u5206\u6d41<\/h3>\n<pre><code>location \/api\/   { proxy_pass http:\/\/127.0.0.1:8080; }\nlocation \/admin\/ { proxy_pass http:\/\/127.0.0.1:9000; }\n<\/code><\/pre>\n<h3>2. \u8d1f\u8f7d\u5747\u8861<\/h3>\n<pre><code>upstream backend {\n    server 10.0.0.1:8080 weight=3;\n    server 10.0.0.2:8080 weight=1;\n}\nlocation \/ { proxy_pass http:\/\/backend; }\n<\/code><\/pre>\n<h3>3. HTTPS \u7ec8\u7ed3 + HTTP \u8f6c\u53d1<\/h3>\n<p>Nginx \u505a SSL \u7ec8\u6b62\uff0c\u540e\u7aef\u53ea\u8dd1 HTTP\uff0c\u964d\u4f4e\u540e\u7aef\u52a0\u89e3\u5bc6\u5f00\u9500\u3002<\/p>\n<h3>4. WebSocket \u652f\u6301<\/h3>\n<pre><code>location \/ws\/ {\n    proxy_pass http:\/\/127.0.0.1:8080;\n    proxy_http_version 1.1;\n    proxy_set_header Upgrade $http_upgrade;\n    proxy_set_header Connection \"upgrade\";\n}\n<\/code><\/pre>\n<h3>5. \u9759\u6001\u8d44\u6e90 + \u52a8\u6001\u5206\u79bb<\/h3>\n<pre><code>location \/static\/ { root \/var\/www; expires 30d; }\nlocation \/ { proxy_pass http:\/\/127.0.0.1:8080; }\n<\/code><\/pre>\n<h2>\u56db\u3001\u5b9e\u6218\uff1a\u7ed9\u5fae\u4fe1 API \u505a\u4ee3\u7406<\/h2>\n<p>\u628a\u8bf7\u6c42\u7edf\u4e00\u4ece\u56fa\u5b9a\u670d\u52a1\u5668 IP \u51fa\u7f51\uff0c\u907f\u514d\u5bb6\u5ead\u5bbd\u5e26 IP \u53d8\u52a8\u5bfc\u81f4\u767d\u540d\u5355\u5931\u6548\uff1a<\/p>\n<pre><code>location \/wxproxy\/ {\n    proxy_pass https:\/\/api.weixin.qq.com;\n    proxy_set_header Host api.weixin.qq.com;\n    proxy_ssl_server_name on;\n}\n<\/code><\/pre>\n<h2>\u4e94\u3001\u6392\u9519\u6e05\u5355<\/h2>\n<ul>\n<li>502\uff1a\u540e\u7aef\u6ca1\u8d77\u6216\u7aef\u53e3\u9519\uff0c\u5148 curl \u540e\u7aef\u5730\u5740\u9a8c\u8bc1\u3002<\/li>\n<li>413\uff1a<code>client_max_body_size 20m;<\/code> \u8c03\u5927\u3002<\/li>\n<li>\u8d85\u65f6\uff1a\u52a0 <code>proxy_read_timeout 60s;<\/code>\u3002<\/li>\n<\/ul>\n<h2>\u7ed3\u8bed<\/h2>\n<p>\u53cd\u5411\u4ee3\u7406\u662f\u8fd0\u7ef4\u57fa\u672c\u529f\uff0c\u914d\u719f\u8fd9\u4e94\u79cd\u573a\u666f\uff0c\u65e5\u5e38 90% \u7684\u9700\u6c42\u90fd\u80fd\u8986\u76d6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bb2\u900f Nginx \u53cd\u5411\u4ee3\u7406\uff1a\u57fa\u7840\u4ee3\u7406\u3001\u8def\u5f84\u5206\u6d41\u3001\u8d1f\u8f7d\u5747\u8861\u3001WebSocket\u3001HTTPS \u7ec8\u7ed3\uff0c\u9644\u5fae\u4fe1 API \u4ee3\u7406\u5b9e\u6218\u3002<\/p>\n","protected":false},"author":2,"featured_media":171,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-63","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=63"}],"version-history":[{"count":1,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":150,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/63\/revisions\/150"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/media\/171"}],"wp:attachment":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}