{"id":424,"date":"2024-12-09T20:52:54","date_gmt":"2024-12-09T12:52:54","guid":{"rendered":"https:\/\/znl.pub\/?p=424"},"modified":"2025-03-10T10:57:19","modified_gmt":"2025-03-10T02:57:19","slug":"nginx-ssl%e8%af%81%e4%b9%a6%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/znl.pub\/?p=424","title":{"rendered":"Nginx \u4e2d return 444 \u7684\u4f5c\u7528\u4e0e\u6700\u4f73\u5b9e\u8df5\uff1a\u5982\u4f55\u5b89\u5168\u62e6\u622a\u975e\u6cd5\u8bf7\u6c42"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>\u5f15\u8a00<\/strong><\/h3>\n\n\n\n<p>\u5728\u7ba1\u7406 Web \u670d\u52a1\u5668\u65f6\uff0c\u6211\u4eec\u5e38\u5e38\u9700\u8981\u5904\u7406\u4e00\u4e9b\u975e\u6cd5\u8bf7\u6c42\uff0c\u6bd4\u5982\u672a\u6388\u6743\u7684\u57df\u540d\u8bbf\u95ee\u3001\u6076\u610f\u626b\u63cf\u6216 DDoS \u653b\u51fb\u3002Nginx \u63d0\u4f9b\u4e86\u4e00\u79cd\u9ad8\u6548\u4e14\u9690\u853d\u7684\u673a\u5236\u6765\u5e94\u5bf9\u8fd9\u7c7b\u95ee\u9898\u2014\u2014<code>return 444<\/code>\u3002 \u672c\u6587\u5c06\u6df1\u5165\u89e3\u6790\u8fd9\u4e00\u914d\u7f6e\u7684\u539f\u7406\u3001\u5e94\u7528\u573a\u666f\uff0c\u5e76\u6f14\u793a\u5982\u4f55\u901a\u8fc7 <code>default_server<\/code> \u548c <code>server_name _<\/code> \u5b9e\u73b0\u5b89\u5168\u62e6\u622a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4ec0\u4e48\u662f <code>return 444<\/code>\uff1f<\/strong><\/h3>\n\n\n\n<p><code>444<\/code> \u662f Nginx \u5b9a\u4e49\u7684\u975e\u6807\u51c6 HTTP \u72b6\u6001\u7801\u3002\u5b83\u7684\u884c\u4e3a\u975e\u5e38\u7b80\u5355\u7c97\u66b4\uff1a<strong>\u76f4\u63a5\u5173\u95ed\u4e0e\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\uff0c\u4e0d\u8fd4\u56de\u4efb\u4f55\u54cd\u5e94<\/strong>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5ba2\u6237\u7aef\u8868\u73b0<\/strong>\uff1a\u6d4f\u89c8\u5668\u6216\u5ba2\u6237\u7aef\u5de5\u5177\uff08\u5982 <code>curl<\/code>\uff09\u4f1a\u611f\u77e5\u5230\u8fde\u63a5\u88ab\u4e2d\u65ad\uff08\u4f8b\u5982 <code>curl: (52) Empty reply from server<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u670d\u52a1\u5668\u65e5\u5fd7<\/strong>\uff1aNginx \u4f1a\u8bb0\u5f55\u72b6\u6001\u7801 <code>444<\/code>\uff0c\u4fbf\u4e8e\u7ba1\u7406\u5458\u5206\u6790\u975e\u6cd5\u8bf7\u6c42\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6838\u5fc3\u914d\u7f6e\u89e3\u6790<\/strong><\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5178\u578b\u7684\u62e6\u622a\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>server {\n    listen 443 ssl default_server;\n    server_name _;\n    ssl_certificate \/etc\/nginx\/ssl\/znl.pub_bundle.pem;\n    ssl_certificate_key \/etc\/nginx\/ssl\/znl.pub.key;\n\n    return 444;\n}<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. <code>default_server<\/code> \u7684\u4f5c\u7528<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f18\u5148\u7ea7\u903b\u8f91<\/strong>\uff1a\u5f53\u5ba2\u6237\u7aef\u8bf7\u6c42\u7684\u4e3b\u673a\u540d\uff08<code>Host<\/code> \u5934\uff09\u672a\u5339\u914d\u4efb\u4f55 <code>server<\/code> \u5757\u7684 <code>server_name<\/code> \u65f6\uff0cNginx \u4f1a\u4f7f\u7528\u6807\u8bb0\u4e3a <code>default_server<\/code> \u7684\u5757\u5904\u7406\u8bf7\u6c42\u3002<\/li>\n\n\n\n<li><strong>\u552f\u4e00\u6027<\/strong>\uff1a\u6bcf\u4e2a\u7aef\u53e3\uff08\u5982 443\uff09\u53ea\u80fd\u6709\u4e00\u4e2a <code>default_server<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. <code>server_name _<\/code> \u7684\u7528\u9014<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u914d\u7b26\u8bed\u4e49<\/strong>\uff1a<code>server_name _;<\/code> \u662f\u4e00\u79cd\u7ea6\u5b9a\u4fd7\u6210\u7684\u5199\u6cd5\uff0c\u8868\u793a\u201c\u5339\u914d\u6240\u6709\u672a\u88ab\u5176\u4ed6 <code>server<\/code> \u5757\u660e\u786e\u5904\u7406\u7684\u57df\u540d\u201d\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d\u6b67\u4e49<\/strong>\uff1a\u663e\u5f0f\u4f7f\u7528 <code>server_name _<\/code> \u53ef\u4ee5\u660e\u786e\u8fd9\u662f\u4e00\u4e2a\u515c\u5e95\u914d\u7f6e\uff0c\u800c\u975e\u5b9e\u9645\u57df\u540d\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. \u8bc1\u4e66\u7684\u5fc5\u8981\u6027<\/strong><\/h4>\n\n\n\n<p>\u5728 HTTPS \u573a\u666f\u4e2d\uff0c\u5373\u4f7f\u62e6\u622a\u975e\u6cd5\u8bf7\u6c42\uff0cNginx \u4ecd\u9700\u52a0\u8f7d\u8bc1\u4e66\uff08<code>ssl_certificate<\/code>\uff09\u4ee5\u5b8c\u6210 TLS \u63e1\u624b\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9632\u6b62\u8bc1\u4e66\u9519\u8bef<\/strong>\uff1a\u82e5\u672a\u914d\u7f6e\u8bc1\u4e66\uff0c\u6d4f\u89c8\u5668\u53ef\u80fd\u56e0\u63e1\u624b\u5931\u8d25\u5f39\u51fa\u8b66\u544a\uff0c\u800c <code>return 444<\/code> \u4f1a\u5728\u63e1\u624b\u540e\u7acb\u5373\u5173\u95ed\u8fde\u63a5\uff0c\u907f\u514d\u6cc4\u9732\u4fe1\u606f\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5b9e\u9645\u6848\u4f8b\u6f14\u793a<\/strong><\/h3>\n\n\n\n<p>\u5047\u8bbe\u670d\u52a1\u5668\u4e0a\u6709\u4ee5\u4e0b\u4e24\u4e2a <code>server<\/code> \u5757\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><em># \u9ed8\u8ba4\u5757\uff1a\u62e6\u622a\u6240\u6709\u975e\u6cd5\u57df\u540d<\/em>\nserver {\n    listen 443 ssl default_server;\n    server_name _;\n    ssl_certificate ...;\n    ssl_certificate_key ...;\n    return 444;\n}\n\n<em># \u6b63\u5e38\u4e1a\u52a1\u5757\uff1a\u5904\u7406 example.com<\/em>\nserver {\n    listen 443 ssl;\n    server_name example.com;\n    ssl_certificate ...;\n    ssl_certificate_key ...;\n    location \/ {\n        root \/var\/www\/html;\n    }\n}<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u573a\u666f 1\uff1a\u5408\u6cd5\u8bf7\u6c42<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8bf7\u6c42<\/strong>\uff1a<code>https:\/\/example.com<\/code><\/li>\n\n\n\n<li><strong>\u7ed3\u679c<\/strong>\uff1a\u5339\u914d\u5230 <code>server_name example.com<\/code>\uff0c\u8fd4\u56de\u7f51\u7ad9\u5185\u5bb9\uff08\u72b6\u6001\u7801 200\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u573a\u666f 2\uff1a\u975e\u6cd5\u8bf7\u6c42<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8bf7\u6c42<\/strong>\uff1a<code>https:\/\/unknown.com<\/code><\/li>\n\n\n\n<li><strong>\u7ed3\u679c<\/strong>\uff1a\u672a\u5339\u914d\u5230\u4efb\u4f55 <code>server_name<\/code>\uff0c\u8fdb\u5165 <code>default_server<\/code> \u5757\uff0c\u89e6\u53d1 <code>return 444<\/code>\uff0c\u8fde\u63a5\u88ab\u7acb\u5373\u5173\u95ed\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u9a8c\u8bc1\u914d\u7f6e\u662f\u5426\u751f\u6548<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. \u4f7f\u7528 <code>curl<\/code> \u6d4b\u8bd5<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6d4b\u8bd5\u5408\u6cd5\u57df\u540d\ncurl -k -H \"Host: example.com\" https:\/\/\u670d\u52a1\u5668IP\n# \u8f93\u51fa\uff1a\u6b63\u5e38 HTML \u5185\u5bb9\n\n# \u6d4b\u8bd5\u975e\u6cd5\u57df\u540d\ncurl -k -H \"Host: unknown.com\" https:\/\/\u670d\u52a1\u5668IP\n# \u8f93\u51fa\uff1acurl: (52) Empty reply from server<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. \u67e5\u770b Nginx \u65e5\u5fd7<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>tail -f \/var\/log\/nginx\/access.log<\/code><\/code><\/pre>\n\n\n\n<p>\u975e\u6cd5\u8bf7\u6c42\u4f1a\u8bb0\u5f55\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &#91;\u65f6\u95f4\u6233] \"GET \/ HTTP\/1.1\" 444 0 \"-\" \"curl\/7.68.0\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5e94\u7528\u573a\u666f\u4e0e\u4f18\u52bf<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. \u9632\u6b62\u57df\u540d\u6076\u610f\u7ed1\u5b9a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u907f\u514d\u4ed6\u4eba\u5c06\u672a\u6388\u6743\u7684\u57df\u540d\u89e3\u6790\u5230\u4f60\u7684\u670d\u52a1\u5668 IP\uff0c\u7ed5\u8fc7\u5b89\u5168\u7ba1\u63a7\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. \u62e6\u622a\u6076\u610f\u8bf7\u6c42<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u722c\u866b\u3001\u626b\u63cf\u5de5\u5177\u3001DDoS \u653b\u51fb\u7b49\u65e0\u6548\u8bf7\u6c42\uff0c\u76f4\u63a5\u65ad\u5f00\u8fde\u63a5\u4ee5\u8282\u7701\u8d44\u6e90\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. \u907f\u514d\u8bc1\u4e66\u6cc4\u9732<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5373\u4f7f\u975e\u6cd5\u57df\u540d\u89e6\u53d1\u4e86 TLS \u63e1\u624b\uff0c\u4e5f\u4e0d\u4f1a\u8fd4\u56de\u4e1a\u52a1\u6570\u636e\u6216\u8bc1\u4e66\u9519\u8bef\u4fe1\u606f\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. \u7b80\u5316\u8fd0\u7ef4<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u96c6\u4e2d\u5904\u7406\u6240\u6709\u672a\u914d\u7f6e\u7684\u57df\u540d\uff0c\u65e0\u9700\u4e3a\u6bcf\u4e2a\u975e\u6cd5\u57df\u540d\u5355\u72ec\u914d\u7f6e\u62e6\u622a\u89c4\u5219\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u603b\u7ed3<\/strong><\/h3>\n\n\n\n<p>\u901a\u8fc7 <code>default_server<\/code> \u548c <code>return 444<\/code> \u7684\u7ec4\u5408\uff0c\u6211\u4eec\u53ef\u4ee5\u9ad8\u6548\u4e14\u5b89\u5168\u5730\u62e6\u622a\u975e\u6cd5\u8bf7\u6c42\u3002\u8fd9\u79cd\u914d\u7f6e\u4e0d\u4ec5\u9690\u853d\uff08\u5ba2\u6237\u7aef\u65e0\u53cd\u9988\uff09\uff0c\u8fd8\u80fd\u663e\u8457\u964d\u4f4e\u670d\u52a1\u5668\u8d44\u6e90\u6d88\u8017\uff0c\u975e\u5e38\u9002\u5408\u7528\u4e8e\u751f\u4ea7\u73af\u5883\u7684\u9632\u62a4\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u6700\u4f73\u5b9e\u8df5\u5efa\u8bae<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4e3a\u6bcf\u4e2a\u7aef\u53e3\u8bbe\u7f6e <code>default_server<\/code><\/strong>\uff1a\u907f\u514d\u672a\u5904\u7406\u7684\u8bf7\u6c42\u843d\u5165\u9ed8\u8ba4\u914d\u7f6e\u5916\u7684\u672a\u77e5\u884c\u4e3a\u3002<\/li>\n\n\n\n<li><strong>\u5b9a\u671f\u68c0\u67e5\u65e5\u5fd7<\/strong>\uff1a\u76d1\u63a7 <code>444<\/code> \u72b6\u6001\u7801\u7684\u9891\u7387\uff0c\u5206\u6790\u6f5c\u5728\u653b\u51fb\u6765\u6e90\u3002<\/li>\n\n\n\n<li><strong>\u7ed3\u5408\u9632\u706b\u5899\u89c4\u5219<\/strong>\uff1a\u5bf9\u9ad8\u9891\u975e\u6cd5 IP\uff0c\u53ef\u5728\u9632\u706b\u5899\u5c42\u8fdb\u4e00\u6b65\u5c01\u7981\uff0c\u63d0\u5347\u6574\u4f53\u5b89\u5168\u6027\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u8fdb\u4e00\u6b65\u601d\u8003<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u9700\u8981\u5411\u5ba2\u6237\u7aef\u8fd4\u56de\u81ea\u5b9a\u4e49\u9519\u8bef\u9875\u9762\uff08\u5982 403\uff09\uff0c\u53ef\u66ff\u6362 <code>return 444<\/code> \u4e3a <code>return 403;<\/code> \u6216\u81ea\u5b9a\u4e49\u54cd\u5e94\u3002<\/li>\n\n\n\n<li>\u5728 HTTP 80 \u7aef\u53e3\u53ef\u914d\u7f6e\u7c7b\u4f3c\u903b\u8f91\uff0c\u5f3a\u5236\u8df3\u8f6c HTTPS \u6216\u62e6\u622a\u975e\u6cd5\u8bf7\u6c42\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u9a7e\u9a6d Nginx \u7684\u5b89\u5168\u9632\u62a4\u80fd\u529b\u3002\u5982\u679c\u6709\u7591\u95ee\u6216\u66f4\u591a\u5b9e\u8df5\u6280\u5de7\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\uff01 \ud83d\ude80<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00 \u5728\u7ba1\u7406 Web \u670d\u52a1\u5668\u65f6\uff0c\u6211\u4eec\u5e38\u5e38\u9700\u8981\u5904\u7406\u4e00\u4e9b\u975e\u6cd5\u8bf7\u6c42\uff0c\u6bd4\u5982\u672a\u6388\u6743\u7684\u57df\u540d\u8bbf\u95ee\u3001\u6076\u610f\u626b\u63cf\u6216 DDoS \u653b\u51fb&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-424","post","type-post","status-publish","format-standard","hentry","category-24"],"_links":{"self":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=424"}],"version-history":[{"count":4,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/424\/revisions"}],"predecessor-version":[{"id":611,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/424\/revisions\/611"}],"wp:attachment":[{"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}