{"id":43192,"date":"2024-10-04T20:41:41","date_gmt":"2024-10-04T12:41:41","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43192\/"},"modified":"2024-10-04T20:41:41","modified_gmt":"2024-10-04T12:41:41","slug":"centos-7-%e4%b8%8a%e5%af%a6%e7%8f%be-nginxtomcat-%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43192\/","title":{"rendered":"CentOS 7 \u4e0a\u5be6\u73fe Nginx+Tomcat \u8ca0\u8f09\u5747\u8861"},"content":{"rendered":"<h1 id=\"centos-7-%e4%b8%8a%e5%af%a6%e7%8f%be-nginxtomcat-%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1-VNGgSAnnPy\">CentOS 7 \u4e0a\u5be6\u73fe Nginx+Tomcat \u8ca0\u8f09\u5747\u8861<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u7684\u53ef\u7528\u6027\u548c\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002\u70ba\u4e86\u78ba\u4fdd\u9ad8\u6548\u7684\u6d41\u91cf\u7ba1\u7406\u548c\u5feb\u901f\u7684\u97ff\u61c9\u6642\u9593\uff0c\u8a31\u591a\u4f01\u696d\u9078\u64c7\u4f7f\u7528\u8ca0\u8f09\u5747\u8861\u6280\u8853\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5be6\u73fe Nginx \u8207 Tomcat \u7684\u8ca0\u8f09\u5747\u8861\u914d\u7f6e\uff0c\u5e6b\u52a9\u60a8\u63d0\u5347\u61c9\u7528\u7684\u7a69\u5b9a\u6027\u548c\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1%ef%bc%9f-VNGgSAnnPy\">\u4ec0\u9ebc\u662f\u8ca0\u8f09\u5747\u8861\uff1f<\/h2>\n<p>\u8ca0\u8f09\u5747\u8861\u662f\u4e00\u7a2e\u5206\u914d\u7db2\u7d61\u6d41\u91cf\u7684\u6280\u8853\uff0c\u65e8\u5728\u78ba\u4fdd\u591a\u500b\u4f3a\u670d\u5668\u4e4b\u9593\u7684\u8ca0\u8f09\u5747\u52fb\u5206\u914d\u3002\u9019\u4e0d\u50c5\u80fd\u63d0\u9ad8\u61c9\u7528\u7684\u53ef\u7528\u6027\uff0c\u9084\u80fd\u6e1b\u5c11\u55ae\u4e00\u4f3a\u670d\u5668\u7684\u58d3\u529b\uff0c\u5f9e\u800c\u63d0\u5347\u6574\u9ad4\u6027\u80fd\u3002Nginx \u4f5c\u70ba\u4e00\u500b\u9ad8\u6548\u7684\u53cd\u5411\u4ee3\u7406\u4f3a\u670d\u5668\uff0c\u5e38\u88ab\u7528\u4f86\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\uff0c\u800c Tomcat \u5247\u662f Java \u61c9\u7528\u7684\u6d41\u884c\u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-VNGgSAnnPy\">\u74b0\u5883\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u60a8\u7684 CentOS 7 \u7cfb\u7d71\u5df2\u5b89\u88dd Nginx \u548c Tomcat\u3002\u4ee5\u4e0b\u662f\u5b89\u88dd\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"%e5%ae%89%e8%a3%9d-nginx-VNGgSAnnPy\">\u5b89\u88dd Nginx<\/h3>\n<pre><code>sudo yum install epel-release\nsudo yum install nginx\nsudo systemctl start nginx\nsudo systemctl enable nginx<\/code><\/pre>\n<h3 id=\"%e5%ae%89%e8%a3%9d-tomcat-VNGgSAnnPy\">\u5b89\u88dd Tomcat<\/h3>\n<p>\u60a8\u53ef\u4ee5\u5f9e Apache Tomcat \u7684\u5b98\u65b9\u7db2\u7ad9\u4e0b\u8f09\u6700\u65b0\u7248\u672c\uff0c\u7136\u5f8c\u89e3\u58d3\u4e26\u914d\u7f6e\uff1a<\/p>\n<pre><code>wget https:\/\/downloads.apache.org\/tomcat\/tomcat-9\/v9.0.62\/bin\/apache-tomcat-9.0.62.tar.gz\ntar -xvzf apache-tomcat-9.0.62.tar.gz\nsudo mv apache-tomcat-9.0.62 \/opt\/tomcat\ncd \/opt\/tomcat\/bin\nsudo .\/startup.sh<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-nginx-%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1-VNGgSAnnPy\">\u914d\u7f6e Nginx \u8ca0\u8f09\u5747\u8861<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u914d\u7f6e Nginx \u4ee5\u5be6\u73fe\u5c0d Tomcat \u7684\u8ca0\u8f09\u5747\u8861\u3002\u7de8\u8f2f Nginx \u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/nginx\/nginx.conf<\/code><\/pre>\n<p>\u5728 http \u5340\u57df\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>http {\n    upstream tomcat {\n        server 127.0.0.1:8080;  # Tomcat \u4f3a\u670d\u5668 1\n        server 127.0.0.1:8081;  # Tomcat \u4f3a\u670d\u5668 2\n    }\n\n    server {\n        listen 80;\n\n        location \/ {\n            proxy_pass http:\/\/tomcat;\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<p>\u5728\u9019\u88e1\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba `tomcat` \u7684\u4e0a\u6e38\u4f3a\u670d\u5668\u7d44\uff0c\u4e26\u5c07\u6d41\u91cf\u8f49\u767c\u5230\u5169\u500b Tomcat \u5be6\u4f8b\uff08\u5047\u8a2d\u5b83\u5011\u5206\u5225\u904b\u884c\u5728 8080 \u548c 8081 \u7aef\u53e3\uff09\u3002<\/p>\n<h2 id=\"%e5%95%9f%e5%8b%95-nginx-VNGgSAnnPy\">\u555f\u52d5 Nginx<\/h2>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u6aa2\u67e5 Nginx \u914d\u7f6e\u662f\u5426\u6b63\u78ba\uff0c\u7136\u5f8c\u91cd\u555f Nginx\uff1a<\/p>\n<pre><code>sudo nginx -t\nsudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1-VNGgSAnnPy\">\u6e2c\u8a66\u8ca0\u8f09\u5747\u8861<\/h2>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u700f\u89bd\u5668\u6216\u547d\u4ee4\u884c\u5de5\u5177\uff08\u5982 curl\uff09\u4f86\u6e2c\u8a66\u8ca0\u8f09\u5747\u8861\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\u3002\u8a2a\u554f\u60a8\u7684\u4f3a\u670d\u5668 IP \u5730\u5740\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u770b\u5230 Tomcat \u61c9\u7528\u7684\u97ff\u61c9\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-VNGgSAnnPy\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u5df2\u6210\u529f\u5728 CentOS 7 \u4e0a\u914d\u7f6e\u4e86 Nginx \u8207 Tomcat \u7684\u8ca0\u8f09\u5747\u8861\u3002\u9019\u7a2e\u914d\u7f6e\u4e0d\u50c5\u80fd\u63d0\u9ad8\u61c9\u7528\u7684\u53ef\u7528\u6027\uff0c\u9084\u80fd\u6709\u6548\u5206\u6563\u6d41\u91cf\uff0c\u63d0\u5347\u6027\u80fd\u3002\u5982\u679c\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to implement Nginx and Tomcat load balancing on CentOS 7 for improved performance and reliability in your web applications.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43192","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=43192"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43192\/revisions"}],"predecessor-version":[{"id":43193,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43192\/revisions\/43193"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}