{"id":5663,"date":"2024-09-06T14:01:01","date_gmt":"2024-09-06T06:01:01","guid":{"rendered":""},"modified":"2024-09-06T14:01:01","modified_gmt":"2024-09-06T06:01:01","slug":"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a","status":"publish","type":"post","link":"https:\/\/mushiming.com\/5663.html","title":{"rendered":"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a<\/p>\n

NGINX \u6587\u4ef6\u914d\u7f6e<\/h3>\n

\u5728.conf\u6587\u4ef6\u5e95\u90e8\u6dfb\u52a0\u5982\u4e0b\u914d\u7f6e\uff1a<\/strong><\/p>\n

upstream transes { \n   <\/span> server 121.37.156.200:<\/span>8080; server 121.37.156.200:<\/span>8088; server 121.37.156.200:<\/span>8087; }<\/span> server { \n   <\/span> listen 80; server_name www.transes.com; location \/ { \n   <\/span> proxy_pass http:<\/span>\/\/transes; }<\/span> }<\/span> <\/code><\/pre>\n

\u8d1f\u8f7d\u5747\u8861\u2014\u2014\u8f6e\u8be2<\/h3>\n

\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a<\/p>\n

\u8d1f\u8f7d\u5747\u8861\u2014\u2014\u52a0\u6743\u8f6e\u8be2<\/h3>\n

\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a
weight=1 \u5373\u6743\u91cd \uff0c\u503c\u8d8a\u5927\uff0c\u8bbf\u95ee\u6bd4\u4f8b\u8d8a\u591a<\/strong><\/p>\n

upstream transes2 { server 121.37.156.200:8080 weight=1; server 121.37.156.200:8088 weight=2; server 121.37.156.200:8087 weight=5; } server { listen 80; server_name www.transes2.com; location \/ { proxy_pass http:\/\/transes2; } } <\/code><\/pre>\n

upstream \u6307\u4ee4\u53c2\u6570<\/h3>\n

\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a
max_conns<\/strong><\/p>\n

\n

\u9650\u5236\u4e00\u53f0\u670d\u52a1\u5668\u7684\u6700\u5927\u8fde\u63a5\u6570\uff0c\u9ed8\u8ba40<\/p>\n<\/blockquote>\n

slow_start<\/strong><\/p>\n

\n

\u7f13\u6162\u7684\u542f\u52a8\uff0c\u8be5\u53c2\u6570\u5fc5\u987b\u8981\u6709\u6743\u91cd\u53c2\u6570(weight)\uff0c\u5fc5\u987b\u7528\u5728\u96c6\u7fa4\u5185\u4e14\u670d\u52a1\u5668\u6570\u91cf\u5927\u4e8e1\uff0c\u8be5\u53c2\u6570\u4ec5\u5728\u5546\u4e1a\u7248\u672c\u4e2d\u53ef\u7528<\/p>\n<\/blockquote>\n

down<\/strong><\/p>\n

\n

\u6807\u8bc6\u670d\u52a1\u5668\u72b6\u6001\uff0c\u7981\u7528\u72b6\u6001\uff0c\u52a0\u4e0a\u8be5\u53c2\u6570\u540e\u8868\u793a\u5f53\u524d\u670d\u52a1\u5668\u4e0d\u53ef\u7528<\/p>\n<\/blockquote>\n

backup<\/strong><\/p>\n

\n

\u5907\u4efd\uff0c\u8868\u793a\u5907\u7528\u673a\uff0c\u53ea\u6709\u5176\u4ed6\u670d\u52a1\u5668\u5b95\u673a\u4e4b\u540e\u624d\u4f1a\u542f\u7528\u5f53\u524d\u670d\u52a1\u5668<\/p>\n<\/blockquote>\n

max_fails<\/strong><\/p>\n

\n

\u6700\u5927\u5931\u8d25\u6b21\u6570\uff0c\u5931\u8d25\u6b21\u6570\u8fbe\u5230\u4e4b\u540enginx\u4f1a\u81ea\u52a8\u5c06\u8be5\u670d\u52a1\u5668\u8bbe\u7f6e\u4e3a\u5b95\u673a\u72b6\u6001<\/p>\n<\/blockquote>\n

fail_timeout<\/strong><\/p>\n

\n

\u914d\u7f6e\u5931\u8d25\u65f6\u95f4(\u598215s)\uff0c\u5982\u679c\u8fde\u7eed\u4e24\u6b21\u8bf7\u6c42\u67d0\u4e2a\u670d\u52a1\u4e3a\u5931\u8d25\u72b6\u6001\u4f1a\u81ea\u52a8\u7b49\u5f8515s\uff0c\u5e76\u4e1415s\u5185\u4e0d\u4f1a\u518d\u6709\u65b0\u7684\u8bf7\u6c42\u8bbf\u95ee\u8be5\u670d\u52a1<\/p>\n<\/blockquote>\n

keepalive\u63d0\u9ad8\u541e\u5410\u91cf<\/h3>\n

keepalived<\/strong> `<\/p>\n

\n

\u8bbe\u7f6e\u957f\u8fde\u63a5\u5904\u7406\u7684\u6570\u91cf<\/p>\n<\/blockquote>\n

`
proxy_http_version<\/strong><\/p>\n

\n

\u8bbe\u7f6e\u957f\u8fde\u63a5http\u7248\u672c\u4e3a1.1<\/p>\n<\/blockquote>\n

proxy_set_header<\/strong><\/p>\n

\n

\u6e05\u9664connection header \u4fe1\u606f<\/p>\n<\/blockquote>\n

\u8d1f\u8f7d\u5747\u8861\u2014\u2014ip_hash<\/h3>\n
\n

ip_hash \u53ef\u4ee5\u4fdd\u8bc1\u7528\u6237\u8bbf\u95ee\u53ef\u4ee5\u8bf7\u6c42\u5230\u4e0a\u6e38\u670d\u52a1\u4e2d\u7684\u56fa\u5b9a\u7684\u670d\u52a1\u5668\uff0c\u524d\u63d0\u662f\u7528\u6237ip\u6ca1\u6709\u53d1\u751f\u66f4\u6539\u3002 \u4f7f\u7528ip_hash\u7684\u6ce8\u610f\u70b9\uff1a
\u4e0d\u80fd\u628a\u540e\u53f0\u670d\u52a1\u5668\u76f4\u63a5\u79fb\u9664\uff0c\u53ea\u80fd\u6807\u8bb0down.<\/p>\n<\/blockquote>\n

\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a
\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a
\u6dfb\u52a0ip_hash\u7b97\u6cd5\u89c4\u5219\u7684\u8d1f\u8f7d\u5747\u8861 \u53ea\u9700\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0ip_hash\u5373\u53ef\uff1b<\/p>\n

upstream transes2 { ip_hash; server 121.37.156.200:8080; server 121.37.156.200:8088; keepalive 32; } <\/code><\/pre>\n

\u8d1f\u8f7d\u5747\u8861\u2014\u2014url_hash<\/h3>\n

\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a
\u6dfb\u52a0url_hash\u7b97\u6cd5\u89c4\u5219\u7684\u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\u65b9\u6cd5<\/p>\n

upstream transes2 { hash $request_uri; server 121.37.156.200:8080; server 121.37.156.200:8088; keepalive 32; } <\/code><\/pre>\n

\u8d1f\u8f7d\u5747\u8861\u2014\u2014least_coon<\/h3>\n

\u6839\u636e\u6700\u5c11\u8fde\u63a5\u6570\u8fdb\u884c\u8bf7\u6c42\uff0c\u6bcf\u6b21\u90fd\u8bf7\u6c42\u6700\u5c0f\u94fe\u63a5\u6570\u7684\u670d\u52a1<\/p>\n

upstream transes2 { hash $request_uri; least_coon\uff1b server 121.37.156.200:8080; server 121.37.156.200:8088; keepalive 32; } <\/code><\/pre>\n

Nginx \u2014\u2014\u7f13\u5b58<\/strong><\/p>\n

\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a
expires \u6307\u4ee4<\/strong>
\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a<\/p>\n

expires [time]<\/strong><\/p>\n

\n

\u8bbe\u7f6e\u6d4f\u89c8\u5668\u7f13\u5b58\u8fc7\u671f\u65f6\u95f4<\/p>\n<\/blockquote>\n

expires @[time]<\/strong><\/p>\n

\n

\u6307\u5b9a\u6d4f\u89c8\u5668\u7f13\u5b58\u8fc7\u671f\u7684\u5177\u4f53\u65f6\u95f4<\/p>\n<\/blockquote>\n

expires -[time]<\/strong><\/p>\n

\n

\u7f13\u5b58\u63d0\u524d\u5931\u6548\u65f6\u95f4<\/p>\n<\/blockquote>\n

expires epoch<\/strong><\/p>\n

\n

\u4e0d\u8bbe\u7f6ecache\u7f13\u5b58<\/p>\n<\/blockquote>\n

expires off<\/strong><\/p>\n

\n

\u9ed8\u8ba4\u5173\u95ed\u7f13\u5b58<\/p>\n<\/blockquote>\n

expires max<\/strong><\/p>\n

\n

\u8bbe\u7f6e\u7f13\u5b58\u6c38\u4e0d\u8fc7\u671f<\/p>\n<\/blockquote>\n

server {  \n        listen       90;\n        server_name  localhost;\n         \n        location \/ {\n            root   \/usr\/local\/tomact-frontend\/webapps\/foodie-shop;\n            index  index.html; \n        }\n\n\n        location \/static {\n           # root   \/home;\n           alias    \/home\/imooc;\n         # expires 10s;\n         # expires @22h30m;  \n         # expires -1h;    \n         # expires epoch; \n         # expires off; \n           expires max;\n        }\n    \n        location \/imooc {\n           root   \/home;\n        }\n        error_page   500 502 503 504  \/50x.html;\n        location = \/50x.html {\n            root   html;\n        }\n\n    }\n<\/code><\/pre>\n

Nginx \u2014\u2014\u53cd\u5411\u4ee3\u7406\u7f13\u5b58<\/strong><\/p>\n

 # proxy_cache_path \u8bbe\u7f6e\u7f13\u5b58\u76ee\u5f55 # keys_zone \u8bbe\u7f6e\u5171\u4eab\u5185\u5b58\u4ee5\u53ca\u5360\u7528\u7a7a\u95f4\u5927\u5c0f # max_size \u8bbe\u7f6e\u7f13\u5b58\u5927\u5c0f # inactive \u8d85\u8fc7\u6b64\u65f6\u95f4\u5219\u88ab\u6e05\u7406 # use_temp_path \u4e34\u65f6\u76ee\u5f55\uff0c\u4f7f\u7528\u540e\u4f1a\u5f71\u54cdnginx\u6027\u80fd proxy_cache_path \/usr\/local\/nginx\/upstream_cache keys_zone=mycache:5m max_size=1g inactive=1m use_temp_path=off; server { listen 80; server_name 121.37.156.200; location \/ { proxy_pass http:\/\/transes2; # \u542f\u7528\u7f13\u5b58\uff0c\u548ckeys_zone\u4e00\u81f4 proxy_cache mycache; # \u9488\u5bf9200\u548c304\u72b6\u6001\u7801\u7f13\u5b58\u65f6\u95f4\u4e3a8\u5c0f\u65f6 proxy_cache_valid 200 304 8h; proxy_http_version 1.1; proxy_set_header Connection \"\"; } } <\/code><\/pre>\n

\u52a8\u9759\u5206\u79bb\u7684\u7279\u70b9<\/h3>\n

\"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0a<\/p>\n","protected":false},"excerpt":{"rendered":"nginx\u642d\u5efatomcat\u96c6\u7fa4_\u5982\u4f55\u5c06\u9879\u76ee\u90e8\u7f72\u5230tomcat\u670d\u52a1\u5668\u4e0aNGINX\u6587\u4ef6\u914d\u7f6e\u5728.conf\u6587\u4ef6\u5e95\u90e8\u6dfb\u52a0\u5982\u4e0b\u914d\u7f6e\uff1aupstreamtranses{server121...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5663"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=5663"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5663\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=5663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=5663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=5663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}