{"id":26967,"date":"2024-11-24T18:37:09","date_gmt":"2024-11-24T10:37:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=26967"},"modified":"2024-11-24T18:37:09","modified_gmt":"2024-11-24T10:37:09","slug":"nginx%e4%b8%ad%e6%a0%b9%e6%8d%ae%e8%b7%af%e5%be%84%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26967\/","title":{"rendered":"Nginx\u4e2d\u6839\u636e\u8def\u5f84\u53cd\u5411\u4ee3\u7406"},"content":{"rendered":"<p>\u4eca\u5929\u5728\u914d\u7f6enginx\u7684\u65f6\uff0c\u78b0\u5230\u7684\u4e00\u4e2a\u95ee\u9898\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5148\u6765\u770b\u4e0b\u9762\u7684\u6b63\u786e\u914d\u7f6e<\/p>\n<pre>upstream backend_122{\r\n    server 192.168.80.122 weight=5 max_fails=3 fail_timeout=30s;\r\n}\r\nupstream backend_122_02{\r\n    server 192.168.80.122:15672;\r\n}       \r\n\r\n\r\nserver{\r\n    listen          80;\r\n        server_name                     122.100.com;\r\n        \r\n        access_log  \/var\/log\/nginx\/122.100.com.access.log main;\r\n        error_log   \/var\/log\/nginx\/122.100.com.error.log; \r\n        \r\n        location ^~ \/rabbit<strong>\/<\/strong> {  #\u8fd9\u91cc\u4e5f\u6700\u597d\u5e26\u4e0a\/\r\n                <strong>proxy_pass http:\/\/backend_122_02\/;<\/strong>\r\n                proxy_redirect off;\r\n                proxy_set_header Host $host;\r\n                proxy_set_header X-Real-IP $remote_addr;\r\n                proxy_set_header X-Forwarded-For $remote_addr;\r\n                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n                proxy_set_header Remote_addr $remote_addr;\r\n        }       \r\n        \r\n        location \/ {\r\n                proxy_pass http:\/\/backend_122;\r\n                proxy_redirect off;\r\n                proxy_set_header Host $host;\r\n                proxy_set_header X-Real-IP $remote_addr;\r\n                proxy_set_header X-Forwarded-For $remote_addr;\r\n                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n                proxy_set_header Remote_addr $remote_addr; \r\n        }\r\n}<\/pre>\n<p>\u6ce8\u610f\u4e0a\u97622\u5904\u6807\u8bc6\u51fa\u6765\u7684\u4ee3\u7801\u7684\u533a\u522b\uff0c\u4e00\u4e2a\u6700\u672b\u5c3e\u52a0\u4e86 \/ \uff0c\u4e00\u4e2a\u6ca1\u6709 \/\u00a0\u00a0 \uff0c\u8fd92\u4e2a\u65f6\u6709\u533a\u522b\u7684<\/p>\n<p>\u4e3e\u4f8b\u5b50\u8bf4\u660e\u5427\uff1a<\/p>\n<pre>location ^~ \/static_js\/ \r\n{\r\n    proxy_cache js_cache; \r\n    proxy_set_header Host js.test.com; \r\n    proxy_pass http:\/\/js.test.com\/; \r\n}\r\n\uff03\u5982\u4e0a\u9762\u7684\u914d\u7f6e\uff0c\u5982\u679c\u8bf7\u6c42\u7684url\u662fhttp:\/\/servername\/static_js\/test.html\r\n\uff03\u4f1a\u88ab\u4ee3\u7406\u6210<strong>http:\/\/js.test.com\/test.html<\/strong><\/pre>\n<pre>location ^~ \/static_js\/ \r\n{\r\n    proxy_cache js_cache; \r\n    proxy_set_header Host js.test.com; \r\n    proxy_pass http:\/\/js.test.com; \r\n}\r\n\uff03\u5219\u4f1a\u88ab\u4ee3\u7406\u5230http:\/\/js.test.com\/static_js\/test.html<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u5728\u914d\u7f6enginx\u7684\u65f6\uff0c\u78b0\u5230\u7684\u4e00\u4e2a\u95ee\u9898\u3002 &nbsp; \u5148\u6765\u770b\u4e0b\u9762\u7684\u6b63\u786e\u914d\u7f6e upstream backend_122{ server 192.168.80.122 weight=5 max_fails=3 fail_timeout=30s; } upstream backend_122_02{ server 192.168.80.122:15672; } server{ listen 80; server_name 122.100.com; access_log \/var\/log\/nginx\/122.100.com.access.log main; error_log \/var\/log\/nginx\/122.100.com.error.log; location ^~ \/rabbit\/ { #\u8fd9\u91cc\u4e5f\u6700\u597d\u5e26\u4e0a\/ proxy_pass http:\/\/backend_122_02\/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Remote_addr $remote_addr; } location \/ { proxy_pass [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-26967","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=26967"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26967\/revisions"}],"predecessor-version":[{"id":26973,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26967\/revisions\/26973"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}