{"id":886,"date":"2022-07-07T17:27:30","date_gmt":"2022-07-07T09:27:30","guid":{"rendered":"http:\/\/www.rchen.top\/?p=886"},"modified":"2022-07-07T17:38:47","modified_gmt":"2022-07-07T09:38:47","slug":"886","status":"publish","type":"post","link":"https:\/\/www.rchen.top\/?p=886","title":{"rendered":"nginx\u7b80\u4ecb"},"content":{"rendered":"<p>Nginx \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684 HTTP \u548c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u7279\u70b9\u662f\u5360\u7528\u5185\u5b58\u5c11\uff0c\u5e76\u53d1\u80fd\u529b\u5f3a\uff0c\u4e8b\u5b9e\u4e0a Nginx \u7684\u5e76\u53d1\u80fd\u529b\u786e\u5b9e\u5728\u540c\u7c7b\u578b\u7684\u7f51\u9875\u670d\u52a1\u5668\u4e2d\u8868\u73b0\u8f83\u597d\u3002Nginx \u4e13\u4e3a\u6027\u80fd\u4f18\u5316\u800c\u5f00\u53d1\uff0c\u6027\u80fd\u662f\u5176\u6700\u91cd\u8981\u7684\u8981\u6c42\uff0c\u5341\u5206\u6ce8\u91cd\u6548\u7387\uff0c\u6709\u62a5\u544a Nginx \u80fd\u652f\u6301\u9ad8\u8fbe 50000 \u4e2a\u5e76\u53d1\u8fde\u63a5\u6570\u3002<\/p>\n<p><b>\u6b63\u5411\u4ee3\u7406\uff1a<\/b><\/p>\n<p>\u5c40\u57df\u7f51\u4e2d\u7684\u7535\u8111\u7528\u6237\u60f3\u8981\u76f4\u63a5\u8bbf\u95ee\u7f51\u7edc\u662f\u4e0d\u53ef\u884c\u7684\uff0c\u53ea\u80fd\u901a\u8fc7\u4ee3\u7406\u670d\u52a1\u5668\u6765\u8bbf\u95ee\uff0c\u8fd9\u79cd\u4ee3\u7406\u670d\u52a1\u5c31\u88ab\u79f0\u4e3a\u6b63\u5411\u4ee3\u7406\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"489\" height=\"341\" class=\"alignnone wp-image-887 size-full\" src=\"http:\/\/www.rchen.top\/wp-content\/uploads\/2022\/07\/Pasted-18.png\"><\/p>\n<p><b>\u914d\u7f6e\u793a\u4f8b<\/b><\/p>\n<p>server {<\/p>\n<p>resolver 114.114.114.114;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #\u6307\u5b9aDNS\u670d\u52a1\u5668IP\u5730\u5740<\/p>\n<p>listen 80;<\/p>\n<p>location \/ {<\/p>\n<p>proxy_pass <a href=\"http:\/\/$host$request_uri\">http:\/\/$host$request_uri<\/a>;&nbsp;&nbsp;&nbsp;&nbsp; #\u8bbe\u5b9a\u4ee3\u7406\u670d\u52a1\u5668\u7684\u534f\u8bae\u548c\u5730\u5740<\/p>\n<p>proxy_set_header HOST $host;<\/p>\n<p>proxy_buffers 256 4k;<\/p>\n<p>proxy_max_temp_file_size 0k;<\/p>\n<p>proxy_connect_timeout 30;<\/p>\n<p>proxy_send_timeout 60;<\/p>\n<p>proxy_read_timeout 60;<\/p>\n<p>proxy_next_upstream error timeout invalid_header http_502;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>server {<\/p>\n<p>resolver 114.114.114.114;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #\u6307\u5b9aDNS\u670d\u52a1\u5668IP\u5730\u5740<\/p>\n<p>listen 443;<\/p>\n<p>location \/ {<\/p>\n<p>proxy_pass <a href=\"https:\/\/$host$request_uri\">https:\/\/$host$request_uri<\/a>;&nbsp;&nbsp;&nbsp; #\u8bbe\u5b9a\u4ee3\u7406\u670d\u52a1\u5668\u7684\u534f\u8bae\u548c\u5730\u5740<\/p>\n<p>proxy_buffers 256 4k;<\/p>\n<p>proxy_max_temp_file_size 0k;<\/p>\n<p>proxy_connect_timeout 30;<\/p>\n<p>proxy_send_timeout 60;<\/p>\n<p>proxy_read_timeout 60;<\/p>\n<p>proxy_next_upstream error timeout invalid_header http_502;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>~<\/p>\n<p>~<\/p>\n<p><b>\u6d4b\u8bd5\u529f\u80fd\uff1a<\/b><\/p>\n<p>[root@jumpserver ~]# curl&nbsp; -I &#8211;proxy 10.100.7.30:80 <a href=\"http:\/\/www.baidu.com\">www.baidu.com<\/a><\/p>\n<p>HTTP\/1.1 200 OK<\/p>\n<p>Server: nginx\/1.12.2<\/p>\n<p>Date: Thu, 05 Dec 2019 07:37:55 GMT<\/p>\n<p>Content-Type: text\/html<\/p>\n<p>Content-Length: 3700<\/p>\n<p>Last-Modified: Tue, 06 Mar 2018 09:26:21 GMT<\/p>\n<p>Connection: keep-alive<\/p>\n<p>ETag: &#8220;5a9e5ebd-e74&#8221;<\/p>\n<p>Accept-Ranges: bytes<\/p>\n<p><b>\u53cd\u5411\u4ee3\u7406\uff1a<\/b><\/p>\n<p>\u5ba2\u6237\u7aef\u65e0\u6cd5\u611f\u77e5\u4ee3\u7406\uff0c\u56e0\u4e3a\u5ba2\u6237\u7aef\u8bbf\u95ee\u7f51\u7edc\u4e0d\u9700\u8981\u914d\u7f6e\uff0c\u53ea\u8981\u628a\u8bf7\u6c42\u53d1\u9001\u5230\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u7531\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u53bb\u9009\u62e9\u76ee\u6807\u670d\u52a1\u5668\u83b7\u53d6\u6570\u636e\uff0c\u7136\u540e\u518d\u8fd4\u56de\u5230\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u6b64\u65f6\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u548c\u76ee\u6807\u670d\u52a1\u5668\u5bf9\u5916\u5c31\u662f\u4e00\u4e2a\u670d\u52a1\u5668\uff0c\u66b4\u9732\u7684\u662f\u4ee3\u7406\u670d\u52a1\u5668\u5730\u5740\uff0c\u9690\u85cf\u4e86\u771f\u5b9e\u670d\u52a1\u5668 IP \u5730\u5740\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"365\" class=\"alignnone wp-image-888 size-full\" src=\"http:\/\/www.rchen.top\/wp-content\/uploads\/2022\/07\/Pasted-19.png\"><\/p>\n<p><b>\u6b65\u9aa4<\/b><b>1<\/b><b>\u3001<\/b><b>\u5728nginx.conf\u914d\u7f6e\u5185\u5f15\u7528conf.d\u6587\u4ef6\u5939\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6<\/b><\/p>\n<p>cat \/etc\/nginx\/nginx.conf<\/p>\n<p>include \/etc\/nginx\/conf.d\/*.conf;<\/p>\n<p><b>\u6b65\u9aa4<\/b><b>2<\/b><b>\u3001\u5728\/etc\/nginx\/conf.d\/*.conf \u5185\u65b0\u589e\u4ee3\u7406\u8f6c\u53d1<\/b><\/p>\n<p>cat \/etc\/nginx\/conf.d\/tools.etransfar.com.conf<\/p>\n<p>upstream mytomcat{<\/p>\n<p>server 10.100.7.31:80 weight=1;<\/p>\n<p>server 10.100.7.32:80 weight=1;<\/p>\n<p>}<\/p>\n<p>server {<\/p>\n<p>listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 80 default_server;<\/p>\n<p>server_name test.xxx.com;<\/p>\n<p>if ($host ~* test.xxx.com) {<\/p>\n<p>rewrite ^(.*)$ <a href=\"https:\/\/$host$1\">https:\/\/$host$1<\/a> permanent;&nbsp;&nbsp;&nbsp;&nbsp; #\u5f3a\u5236\u8df3\u8f6chttps<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>server {<\/p>\n<p>listen 443;<\/p>\n<p>server_name test.xxx.com;<\/p>\n<p>ssl on;<\/p>\n<p>ssl_certificate \/etc\/nginx\/ssl\/xxx.com.cer;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # \u516c\u94a5\u6587\u4ef6(Globalsign \u9881\u53d1\u7684\u8bc1\u4e66)<\/p>\n<p>ssl_certificate_key \/etc\/nginx\/ssl\/xxx.com.key;&nbsp;&nbsp;&nbsp;&nbsp; # \u79c1\u94a5\u6587\u4ef6<\/p>\n<p>location \/ {<\/p>\n<p>proxy_pass <a href=\"http:\/\/mytomcat\">http:\/\/mytomcat<\/a>;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684 HTTP \u548c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u7279\u70b9\u662f\u5360\u7528\u5185\u5b58\u5c11\uff0c\u5e76\u53d1\u80fd\u529b\u5f3a\uff0c\u4e8b\u5b9e\u4e0a Nginx \u7684\u5e76 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":889,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[95],"tags":[145],"class_list":["post-886","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-95","tag-nginx"],"_links":{"self":[{"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/posts\/886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=886"}],"version-history":[{"count":2,"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/posts\/886\/revisions"}],"predecessor-version":[{"id":891,"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/posts\/886\/revisions\/891"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/media\/889"}],"wp:attachment":[{"href":"https:\/\/www.rchen.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}