{"id":18037,"date":"2024-11-18T13:56:33","date_gmt":"2024-11-18T05:56:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18037\/"},"modified":"2024-11-18T13:56:33","modified_gmt":"2024-11-18T05:56:33","slug":"nginx%e9%98%b2%e7%81%ab%e5%a2%99%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18037\/","title":{"rendered":"nginx\u9632\u706b\u5899\u600e\u4e48\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  \u672c\u6307\u5357\u4ecb\u7ecd\u4e86\u5982\u4f55\u8bbe\u7f6e nginx \u9632\u706b\u5899\uff0c\u6b65\u9aa4\u5982\u4e0b\uff1a\u542f\u7528 firewall \u6a21\u5757\u5b9a\u4e49\u9632\u706b\u5899\u7b56\u7565\uff08\u4f8b\u5982\uff0c\u5141\u8bb8\u7279\u5b9a ip \u5730\u5740\u8bbf\u95ee\uff0c\u7981\u6b62\u7279\u5b9a\u7aef\u53e3\u8bbf\u95ee\uff09\u5e94\u7528\u9632\u706b\u5899\u7b56\u7565\u91cd\u65b0\u52a0\u8f7d nginx \u914d\u7f6e\u6d4b\u8bd5\u9632\u706b\u5899\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/27\/2024052719452923699.jpg\" class=\"aligncenter\" title=\"nginx\u9632\u706b\u5899\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" alt=\"nginx\u9632\u706b\u5899\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e Nginx \u9632\u706b\u5899<\/strong><\/p>\n<p>Nginx \u662f\u4e00\u4e2a\u6d41\u884c\u7684 Web \u670d\u52a1\u5668\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5f3a\u5927\u7684\u9632\u706b\u5899\u529f\u80fd\uff0c\u53ef\u4ee5\u4fdd\u62a4\u4f60\u7684\u670d\u52a1\u5668\u514d\u53d7\u672a\u7ecf\u6388\u6743\u7684\u8bbf\u95ee\u548c\u653b\u51fb\u3002\u4ee5\u4e0b\u662f\u8bbe\u7f6e Nginx \u9632\u706b\u5899\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u542f\u7528 Firewall \u6a21\u5757<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u542f\u7528 Firewall \u6a21\u5757\u3002\u4e3a\u6b64\uff0c\u8bf7\u5728 http \u5757\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>load_module firewall_module modules\/mod_firewall.so;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5b9a\u4e49\u9632\u706b\u5899\u7b56\u7565<\/strong><\/p>\n<p>Nginx \u7684\u9632\u706b\u5899\u6a21\u5757\u5141\u8bb8\u4f60\u5b9a\u4e49\u4e00\u7ec4\u89c4\u5219\u6765\u63a7\u5236\u5bf9\u670d\u52a1\u5668\u7684\u8bbf\u95ee\u3002\u8fd9\u4e9b\u89c4\u5219\u53ef\u4ee5\u57fa\u4e8e IP \u5730\u5740\u3001\u7aef\u53e3\u53f7\u6216\u5176\u4ed6\u6761\u4ef6\u3002\u8981\u5b9a\u4e49\u9632\u706b\u5899\u7b56\u7565\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>firewall {\n    # \u89c4\u5219\u5217\u8868\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\u9632\u706b\u5899\u89c4\u5219\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u5141\u8bb8\u6765\u81ea\u7279\u5b9a IP \u5730\u5740\u7684\u8bbf\u95ee\uff1a<\/strong><\/li>\n<\/ul>\n<pre>allow 192.168.0.1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li><strong>\u5141\u8bb8\u7279\u5b9a\u7aef\u53e3\u7684\u8bbf\u95ee\uff1a<\/strong><\/li>\n<\/ul>\n<pre>allow 80;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li><strong>\u7981\u6b62\u6765\u81ea\u7279\u5b9a IP \u5730\u5740\u7684\u8bbf\u95ee\uff1a<\/strong><\/li>\n<\/ul>\n<pre>deny 192.168.0.2;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li><strong>\u7981\u6b62\u7279\u5b9a\u7aef\u53e3\u7684\u8bbf\u95ee\uff1a<\/strong><\/li>\n<\/ul>\n<pre>deny 443;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u5e94\u7528\u9632\u706b\u5899\u7b56\u7565<\/strong><\/p>\n<p>\u5b9a\u4e49\u9632\u706b\u5899\u7b56\u7565\u540e\uff0c\u4f60\u5fc5\u987b\u5c06\u5176\u5e94\u7528\u5230\u670d\u52a1\u5668\u3002\u4e3a\u6b64\uff0c\u8bf7\u5728 http \u5757\u4e2d\u4f7f\u7528\u4ee5\u4e0b\u6307\u4ee4\uff1a<\/p>\n<pre>firewall on;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u91cd\u65b0\u52a0\u8f7d Nginx \u914d\u7f6e<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u91cd\u65b0\u52a0\u8f7d Nginx \u914d\u7f6e\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre>nginx -s reload<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u6d4b\u8bd5\u9632\u706b\u5899<\/strong><\/p>\n<p>\u8981\u6d4b\u8bd5\u9632\u706b\u5899\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\uff0c\u8bf7\u5c1d\u8bd5\u4ece\u5141\u8bb8\u7684 IP \u5730\u5740\u548c\u7aef\u53e3\u8bbf\u95ee\u670d\u52a1\u5668\u3002\u4f60\u5e94\u8be5\u80fd\u591f\u6210\u529f\u8bbf\u95ee\u670d\u52a1\u5668\u3002\u7136\u540e\uff0c\u5c1d\u8bd5\u4ece\u88ab\u7981\u6b62\u7684 IP \u5730\u5740\u6216\u7aef\u53e3\u8bbf\u95ee\u670d\u52a1\u5668\u3002\u4f60\u5e94\u8be5\u65e0\u6cd5\u8bbf\u95ee\u670d\u52a1\u5668\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u9632\u706b\u5899\u600e\u4e48\u8bbe\u7f6e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6307\u5357\u4ecb\u7ecd\u4e86\u5982\u4f55\u8bbe\u7f6e nginx \u9632\u706b\u5899\uff0c\u6b65\u9aa4\u5982\u4e0b\uff1a\u542f\u7528 firewall \u6a21\u5757\u5b9a\u4e49\u9632\u706b\u5899\u7b56\u7565\uff08\u4f8b\u5982\uff0c\u5141\u8bb8\u7279\u5b9a ip \u5730\u5740\u8bbf\u95ee\uff0c\u7981\u6b62\u7279\u5b9a\u7aef\u53e3\u8bbf\u95ee\uff09\u5e94\u7528\u9632\u706b\u5899\u7b56\u7565\u91cd\u65b0\u52a0\u8f7d nginx \u914d\u7f6e\u6d4b\u8bd5\u9632\u706b\u5899\u662f\u5426\u6b63\u5e38\u5de5\u4f5c \u5982\u4f55\u8bbe\u7f6e Nginx \u9632\u706b\u5899 Nginx \u662f\u4e00\u4e2a\u6d41\u884c\u7684 Web \u670d\u52a1\u5668\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5f3a\u5927\u7684\u9632\u706b\u5899\u529f\u80fd\uff0c\u53ef\u4ee5\u4fdd\u62a4\u4f60\u7684\u670d\u52a1\u5668\u514d\u53d7\u672a\u7ecf\u6388\u6743\u7684\u8bbf\u95ee\u548c\u653b\u51fb\u3002\u4ee5\u4e0b\u662f\u8bbe\u7f6e Nginx \u9632\u706b\u5899\u7684\u6b65\u9aa4\uff1a 1. \u542f\u7528 Firewall \u6a21\u5757 \u9996\u5148\uff0c\u4f60\u9700\u8981\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u542f\u7528 Firewall \u6a21\u5757\u3002\u4e3a\u6b64\uff0c\u8bf7\u5728 http \u5757\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a load_module firewall_module modules\/mod_firewall.so; \u767b\u5f55\u540e\u590d\u5236 2. \u5b9a\u4e49\u9632\u706b\u5899\u7b56\u7565 Nginx \u7684\u9632\u706b\u5899\u6a21\u5757\u5141\u8bb8\u4f60\u5b9a\u4e49\u4e00\u7ec4\u89c4\u5219\u6765\u63a7\u5236\u5bf9\u670d\u52a1\u5668\u7684\u8bbf\u95ee\u3002\u8fd9\u4e9b\u89c4\u5219\u53ef\u4ee5\u57fa\u4e8e IP \u5730\u5740\u3001\u7aef\u53e3\u53f7\u6216\u5176\u4ed6\u6761\u4ef6\u3002\u8981\u5b9a\u4e49\u9632\u706b\u5899\u7b56\u7565\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a firewall { # \u89c4\u5219\u5217\u8868 } \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\u9632\u706b\u5899\u89c4\u5219\uff1a \u5141\u8bb8\u6765\u81ea\u7279\u5b9a IP \u5730\u5740\u7684\u8bbf\u95ee\uff1a allow 192.168.0.1; \u767b\u5f55\u540e\u590d\u5236 \u5141\u8bb8\u7279\u5b9a\u7aef\u53e3\u7684\u8bbf\u95ee\uff1a allow 80; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18037","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18037","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=18037"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18037\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}