{"id":1520,"date":"2018-11-06T10:43:53","date_gmt":"2018-11-06T02:43:53","guid":{"rendered":"https:\/\/www.strongd.net\/?p=1520"},"modified":"2018-11-06T10:43:53","modified_gmt":"2018-11-06T02:43:53","slug":"%e6%9c%ac%e5%8d%9a%e5%ae%a2nginx-%e9%85%8d%e7%bd%ae%e4%b9%8b%e5%ae%89%e5%85%a8%e7%af%87","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=1520","title":{"rendered":"\u672c\u535a\u5ba2Nginx \u914d\u7f6e\u4e4b\u5b89\u5168\u7bc7"},"content":{"rendered":"<p><span>\u4e4b\u524d\u6709\u7d30\u5fc3\u7684\u670b\u53cb\u554f\u6211\uff0c\u70ba\u4ec0\u9ebc\u4f60\u7684\u535a\u5ba2\u526f\u6a19\u984c\u662f\u300c\u5c08\u6ce8WEB \u7aef\u958b\u767c\u300d\uff0c\u662f\u4e0d\u662f\u5c11\u4e86\u300c\u524d\u7aef\u300d\u7684\u300c\u524d\u300d\u3002\u6211\u60f3\u8aaa\u7684\u662f\uff0c\u5118\u7ba1\u6211\u5f9e\u7562\u696d\u5230\u73fe\u5728\u4e03\u5e74\u5de6\u53f3\u7684\u6642\u9593\u4e00\u76f4\u90fd\u5728\u5c08\u696d\u524d\u7aef\u5718\u968a\u5f9e\u4e8b\u524d\u7aef\u76f8\u95dc\u5de5\u4f5c\uff0c\u4f46\u9019\u4e26\u4e0d\u610f\u5473\u8457\u6211\u7684\u77e5\u8b58\u9ad4\u4fc2\u5c31\u5fc5\u9808\u5c40\u9650\u65bc\u524d\u7aef\u9019\u500b\u7bc4\u7587\u5167\u3002\u73fe\u5728\u6bd4\u8f03\u6d41\u884c\u300c\u5168\u68e7\u5de5\u7a0b\u5e2b\u300d\u7684\u6982\u5ff5\uff0c\u6211\u89ba\u5f97\u5168\u68e7\u610f\u5473\u8457\u4e00\u500b\u9805\u76ee\u4e2d\uff0c\u5404\u500b\u5d17\u4f4d\u6240\u9700\u8981\u7684\u6280\u80fd\u4f60\u90fd\u5177\u5099\uff0c\u4f46\u4e26\u4e0d\u4e00\u5b9a\u610f\u5473\u8457\u4f60\u4ec0\u9ebc\u90fd\u9700\u8981\u505a\u3002\u4f60\u9700\u8981\u505a\u4ec0\u9ebc\uff0c\u66f4\u591a\u662f\u7531\u80fd\u529b\u3001\u4eba\u54e1\u914d\u6bd4\u4ee5\u53ca\u6210\u672c\u7b49\u5404\u500b\u56e0\u7d20\u6240\u6c7a\u5b9a\u3002\u5118\u7ba1\u6211\u73fe\u5728\u7684\u5de5\u4f5c\u8077\u8cac\u662f\u5728WEB \u524d\u7aef\u9818\u57df\uff0c\u4f46\u662f\u6211\u7684\u95dc\u6ce8\u9ede\u5728\u6574\u500bWEB \u7aef\u3002<\/span><\/p>\n<p><span>\u6211\u63a5\u89f8\u904e\u7684\u6709\u4e9b\u524d\u7aef\u670b\u53cb\uff0c\u5f9e\u4e00\u958b\u59cb\u5c31\u628a\u81ea\u5df1\u5c40\u9650\u5728\u4e00\u500b\u5f88\u5c0f\u7684\u7bc4\u570d\u4e4b\u4e2d\uff0c\u9019\u5728\u5927\u516c\u53f8\u5230\u4e5f\u7121\u6240\u8b02\uff0c\u5927\u516c\u53f8\u5206\u5de5\u660e\u78ba\uff0c\u57fa\u790e\u8a2d\u65bd\u9f4a\u5168\uff0c\u4f60\u53ea\u8981\u505a\u597d\u81ea\u5df1\u64c5\u9577\u7684\u90a3\u90e8\u5206\u5c31\u53ef\u4ee5\u4e86\u3002\u4f46\u662f\u7576\u4ed6\u5011\u9032\u5165\u5275\u696d\u516c\u53f8\u4e4b\u5f8c\uff0c\u6703\u767c\u73fe\u4e00\u4e0b\u5b50\u4f86\u4e86\u597d\u591a\u4e4b\u524d\u5b8c\u5168\u6c92\u6709\u63a5\u89f8\u904e\u7684\u6771\u897f\uff0c\u5341\u5206\u88ab\u52d5\u3002<\/span><\/p>\n<p><span>\u53bb\u5e74\u6211\u7528Lua +\u00a0<\/span><a href=\"http:\/\/openresty.org\/\"><span>OpenResty<\/span><\/a><span>\u66ff\u63db\u4e86\u7dda\u4e0a\u5343\u842c\u7d1a\u7684PHP + Nginx\u670d\u52d9\uff0c\u81f3\u4eca\u7a69\u5b9a\u904b\u884c\uff0c\u7b97\u662f\u524d\u7aef\u4e4b\u5916\u7684\u4e00\u9ede\u5617\u8a66\u3002\u6211\u4e00\u76f4\u8a8d\u70ba\u5b78\u7fd2\u4efb\u4f55\u77e5\u8b58\u5f88\u91cd\u8981\u7684\u4e00\u9ede\u662f\u5be6\u8e10\uff0c\u6240\u4ee5\u6211\u4e00\u76f4\u90fd\u5728\u6298\u9a30\u6211\u7684VPS\uff0c\u9032\u884c\u5404\u7a2eWEB\u5b89\u5168\u3001\u512a\u5316\u76f8\u95dc\u7684\u5617\u8a66\u3002\u6211\u6253\u7b97\u5f9e\u5b89\u5168\u548c\u6027\u80fd\u5169\u65b9\u9762\u4ecb\u7d39\u4e00\u4e0b\u672c\u535a\u5ba2\u6240\u7528Nginx\u7684\u76f8\u95dc\u914d\u7f6e\uff0c\u4eca\u5929\u5148\u5beb\u5b89\u5168\u76f8\u95dc\u7684\u3002<\/span><\/p>\n<h3 id=\"toc-0\"><span>\u96b1\u85cf\u4e0d\u5fc5\u8981\u7684\u4fe1\u606f<\/span><\/h3>\n<p><span>\u5927\u5bb6\u53ef\u4ee5\u770b\u4e00\u4e0b\u6211\u7684\u535a\u5ba2\u8acb\u6c42\u97ff\u61c9\u982d\uff0c\u6709\u9019\u9ebc\u4e00\u884c<\/span><code>server: nginx<\/code><span>\uff0c\u8aaa\u660e\u6211\u7528\u7684\u662fNginx\u670d\u52d9\u5668\uff0c\u4f46\u4e26\u6c92\u6709\u5177\u9ad4\u7684\u7248\u672c\u865f\u3002\u7531\u65bc\u67d0\u4e9bNginx\u6f0f\u6d1e\u53ea\u5b58\u5728\u65bc\u7279\u5b9a\u7684\u7248\u672c\uff0c\u96b1\u85cf\u7248\u672c\u865f\u53ef\u4ee5\u63d0\u9ad8\u5b89\u5168\u6027\u3002\u9019\u53ea\u9700\u8981\u5728\u914d\u7f6e\u88e1\u52a0\u4e0a\u9019\u500b\u5c31\u53ef\u4ee5\u4e86\uff1a<\/span><\/p>\n<pre><code class=\"lang-nginx\"><span class=\"hljs-title\">server_tokens<\/span>   <span class=\"hljs-built_in\">off<\/span>;\r\n<\/code><\/pre>\n<p><span>\u5982\u679c\u60f3\u8981\u66f4\u5fb9\u5e95\u96b1\u85cf\u6240\u7528Web Server\uff0c\u53ef\u4ee5\u4fee\u6539Nginx\u6e90\u78bc\uff0c\u628aServer Name\u6539\u6389\u518d\u7de8\u8b6f\uff0c\u5177\u9ad4\u6b65\u9a5f\u53ef\u4ee5\u81ea\u5df1\u641c\u7d22\u3002\u9700\u8981\u63d0\u9192\u7684\u662f\uff1a\u5982\u679c\u4f60\u7684\u7db2\u7ad9\u652f\u6301SPDY\uff0c\u53ea\u6539\u52d5\u7db2\u4e0a\u90a3\u4e9b\u6587\u7ae0\u5beb\u5230\u7684\u5730\u65b9\u9084\u4e0d\u5920\uff0c\u8ddfSPDY\u6709\u95dc\u7684\u4ee3\u78bc\u4e5f\u8981\u6539\u3002\u66f4\u7c21\u55ae\u7684\u505a\u6cd5\u662f\u6539\u7528<\/span><a href=\"http:\/\/tengine.taobao.org\/index_cn.html\"><span>Tengine<\/span><\/a><span>\u9019\u500bNginx\u7684\u589e\u5f37\u7248\uff0c\u4e26\u6307\u5b9a<\/span><code>server_tag<\/code><span>\u70baoff\u6216\u8005\u4efb\u4f55\u60f3\u8981\u7684\u503c\u5c31\u53ef\u4ee5\u4e86\u3002\u53e6\u5916\uff0c\u65e2\u7136\u60f3\u8981\u5fb9\u5e95\u96b1\u85cfNginx\uff0c404\u3001500\u7b49\u5404\u7a2e\u51fa\u932f\u9801\u4e5f\u9700\u8981\u81ea\u5b9a\u7fa9\u3002<\/span><\/p>\n<p><span>\u540c\u6a23\uff0c\u4e00\u4e9bWEB\u8a9e\u8a00\u6216\u6846\u67b6\u9ed8\u8a8d\u8f38\u51fa\u7684<\/span><code>x-powered-by<\/code><span>\u4e5f\u6703\u6d29\u9732\u7db2\u7ad9\u4fe1\u606f\uff0c\u4ed6\u5011\u4e00\u822c\u90fd\u63d0\u4f9b\u4e86\u4fee\u6539\u6216\u79fb\u9664\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u81ea\u884c\u67e5\u770b\u624b\u518a\u3002\u5982\u679c\u90e8\u7f72\u4e0a\u7528\u5230\u4e86Nginx\u7684\u53cd\u5411\u4ee3\u7406\uff0c\u4e5f\u53ef\u4ee5\u901a\u904eproxy_hide_header\u6307\u4ee4\u96b1\u85cf\u5b83\uff1a<\/span><\/p>\n<pre><code class=\"lang-nginx\"><span class=\"hljs-title\">proxy_hide_header<\/span>        X-Powered-By;\r\n<\/code><\/pre>\n<h3 id=\"toc-1\"><span>\u7981\u7528\u975e\u5fc5\u8981\u7684\u65b9\u6cd5<\/span><\/h3>\n<p><span>\u7531\u65bc\u6211\u7684\u535a\u5ba2\u53ea\u8655\u7406\u4e86GET\u3001POST \u5169\u7a2e\u8acb\u6c42\u65b9\u6cd5\uff0c\u800cHTTP\/1 \u5354\u8b70\u9084\u898f\u5b9a\u4e86TRACE \u9019\u6a23\u7684\u65b9\u6cd5\u7528\u65bc\u7db2\u7d61\u8a3a\u65b7\uff0c\u9019\u4e5f\u53ef\u80fd\u6703\u66b4\u9732\u4e00\u4e9b\u4fe1\u606f\u3002\u6240\u4ee5\u6211\u91dd\u5c0dGET\u3001POST \u4ee5\u53caHEAD \u4e4b\u5916\u7684\u8acb\u6c42\uff0c\u76f4\u63a5\u8fd4\u56de\u4e86444 \u72c0\u614b\u78bc\uff08444 \u662fNginx \u5b9a\u7fa9\u7684\u97ff\u61c9\u72c0\u614b\u78bc\uff0c\u6703\u7acb\u5373\u65b7\u958b\u9023\u63a5\uff0c\u6c92\u6709\u97ff\u61c9\u6b63\u6587\uff09\u3002\u5177\u9ad4\u914d\u7f6e\u662f\u9019\u6a23\u7684\uff1a<\/span><\/p>\n<pre><b class=\"name\"><span>NGINX<\/span><\/b><code class=\"lang-nginx\"><span class=\"hljs-title\">if<\/span> (<span class=\"hljs-variable\">$request_method<\/span> !<span class=\"hljs-regexp\">~ ^(GET|HEAD|POST)$<\/span> ) {\r\n    <span class=\"hljs-title\">return<\/span>    <span class=\"hljs-number\">444<\/span>;\r\n}\r\n<\/code><\/pre>\n<h3 id=\"toc-2\"><span>\u5408\u7406\u914d\u7f6e\u97ff\u61c9\u982d<\/span><\/h3>\n<p><span>\u6211\u7684\u535a\u5ba2\u662f\u7531\u81ea\u5df1\u7528ThinkJS \u5beb\u7684Node \u7a0b\u5e8f\u63d0\u4f9b\u670d\u52d9\uff0cNginx \u901a\u904eproxy_pass \u628a\u8acb\u6c42\u53cd\u5411\u4ee3\u7406\u7d66Node \u7d81\u5b9a\u7684IP \u548c\u7aef\u53e3\u3002\u5728\u6700\u7d42\u8f38\u51fa\u6642\uff0c\u6211\u7d66\u97ff\u61c9\u589e\u52a0\u4e86\u4ee5\u4e0b\u982d\u90e8\uff1a<\/span><\/p>\n<pre><b class=\"name\"><span>NGINX<\/span><\/b><code class=\"lang-nginx\"><span class=\"hljs-title\">add_header<\/span>  Strict-Transport-Security  <span class=\"hljs-string\">\"max-age=31536000\"<\/span>;\r\n<span class=\"hljs-title\">add_header<\/span>  X-Frame-Options  deny;\r\n<span class=\"hljs-title\">add_header<\/span>  X-Content-Type-Options  nosniff;\r\n<span class=\"hljs-title\">add_header<\/span>  Content-Security-Policy  <span class=\"hljs-string\">\"default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:\/\/a.disquscdn.com; img-src 'self' data: https:\/\/www.google-analytics.com; style-src 'self' 'unsafe-inline'; frame-src https:\/\/disqus.com\"<\/span>;\r\n<\/code><\/pre>\n<p><code>Strict-Transport-Security<\/code><span>\uff08\u7c21\u7a31\u70baHSTS\uff09\u53ef\u4ee5\u544a\u8a34\u700f\u89bd\u5668\uff0c\u5728\u6307\u5b9a\u7684max-age\u5167\uff0c\u59cb\u7d42\u901a\u904eHTTPS\u8a2a\u554f\u6211\u7684\u535a\u5ba2\u3002\u5373\u4f7f\u7528\u6236\u81ea\u5df1\u8f38\u5165HTTP\u7684\u5730\u5740\uff0c\u6216\u8005\u9ede\u64ca\u4e86HTTP\u93c8\u63a5\uff0c\u700f\u89bd\u5668\u4e5f\u6703\u5728\u672c\u5730\u66ff\u63db\u70baHTTPS\u518d\u767c\u9001\u8acb\u6c42\u3002\u53e6\u5916\u7531\u65bc\u6211\u7684\u8b49\u66f8\u4e0d\u652f\u6301\u591a\u57df\u540d\uff0c\u6211\u6c92\u6709\u52a0\u4e0a<\/span><code>includeSubDomains<\/code><span>\u3002\u95dc\u65bcHSTS\u66f4\u591a\u4fe1\u606f\uff0c\u53ef\u4ee5\u67e5\u770b<\/span><a href=\"https:\/\/imququ.com\/post\/web-security-and-response-header.html#toc-0\"><span>\u6211\u4e4b\u524d\u7684\u4ecb\u7d39<\/span><\/a><span>\u3002<\/span><\/p>\n<p><code>X-Frame-Options<\/code><span>\u7528\u4f86\u6307\u5b9a\u6b64\u7db2\u9801\u662f\u5426\u5141\u8a31\u88abiframe\u5d4c\u5957\uff0cdeny\u5c31\u662f\u4e0d\u5141\u8a31\u4efb\u4f55\u5d4c\u5957\u767c\u751f\u3002\u95dc\u65bc\u9019\u500b\u97ff\u61c9\u982d\u7684\u66f4\u591a\u4ecb\u7d39\u53ef\u4ee5<\/span><a href=\"https:\/\/imququ.com\/post\/web-security-and-response-header.html#toc-1\"><span>\u770b\u9019\u88e1<\/span><\/a><span>\u3002<\/span><\/p>\n<p><code>X-Content-Type-Options<\/code><span>\u7528\u4f86\u6307\u5b9a\u700f\u89bd\u5668\u5c0d\u672a\u6307\u5b9a\u6216\u932f\u8aa4\u6307\u5b9aContent-Type\u8cc7\u6e90\u771f\u6b63\u985e\u578b\u7684\u731c\u6e2c\u884c\u70ba\uff0cnosniff\u8868\u793a\u4e0d\u5141\u8a31\u4efb\u4f55\u731c\u6e2c\u3002\u9019\u90e8\u5206\u5167\u5bb9\u66f4\u591a\u4ecb\u7d39<\/span><a href=\"https:\/\/imququ.com\/post\/web-security-and-response-header.html#toc-3\"><span>\u898b\u9019\u88e1<\/span><\/a><span>\u3002<\/span><\/p>\n<p><code>Content-Security-Policy<\/code><span>\uff08\u7c21\u7a31\u70baCSP\uff09\u7528\u4f86\u6307\u5b9a\u9801\u9762\u53ef\u4ee5\u52a0\u8f09\u54ea\u4e9b\u8cc7\u6e90\uff0c\u4e3b\u8981\u76ee\u7684\u662f\u6e1b\u5c11XSS\u7684\u767c\u751f\u3002\u6211\u5141\u8a31\u4e86\u4f86\u81ea\u672c\u7ad9\u3001disquscdn\u7684\u5916\u93c8JS\uff0c\u9084\u5141\u8a31\u5167\u806fJS\uff0c\u4ee5\u53ca\u5728JS\u4e2d\u4f7f\u7528eval\uff1b\u5141\u8a31\u4f86\u81ea\u672c\u7ad9\u548cgoogle\u7d71\u8a08\u7684\u5716\u7247\uff0c\u4ee5\u53ca\u5167\u806f\u5716\u7247\uff08Data URI\u5f62\u5f0f\uff09\uff1b\u5141\u8a31\u672c\u7ad9\u5916\u93c8CSS\u4ee5\u53ca\u5167\u806fCSS\uff1b\u5141\u8a31iframe\u52a0\u8f09\u4f86\u81eadisqus\u7684\u9801\u9762\u3002\u5c0d\u65bc\u5176\u4ed6\u672a\u6307\u5b9a\u7684\u8cc7\u6e90\uff0c\u90fd\u6703\u8d70\u9ed8\u8a8d\u898f\u5247<\/span><code>self<\/code><span>\uff0c\u4e5f\u5c31\u662f\u53ea\u5141\u8a31\u52a0\u8f09\u672c\u7ad9\u7684\u3002\u95dc\u65bcCSP\u7684\u8a73\u7d30\u4ecb\u7d39<\/span><a href=\"https:\/\/imququ.com\/post\/content-security-policy-reference.html\"><span>\u8acb\u770b\u9019\u88e1<\/span><\/a><span>\u3002<\/span><\/p>\n<p><a href=\"https:\/\/imququ.com\/post\/web-security-and-response-header.html#toc-2\"><span>\u4e4b\u524d\u7684\u535a\u5ba2\u4e2d<\/span><\/a><span>\uff0c\u6211\u9084\u4ecb\u7d39\u904e<\/span><code>X-XSS-Protection<\/code><span>\u9019\u500b\u97ff\u61c9\u982d\uff0c\u4e5f\u53ef\u4ee5\u7528\u4f86\u9632\u7bc4XSS\u3002\u4e0d\u904e\u7531\u65bc\u6709\u4e86CSP\uff0c\u6240\u4ee5\u6211\u6c92\u914d\u7f6e\u5b83\u3002<\/span><\/p>\n<p><span>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4ee5\u4e0a\u9019\u4e9b\u97ff\u61c9\u982d\u73fe\u4ee3\u700f\u89bd\u5668\u624d\u652f\u6301\uff0c\u6240\u4ee5\u4e26\u4e0d\u662f\u8aaa\u52a0\u4e0a\u4ed6\u5011\uff0c\u7db2\u7ad9\u5c31\u53ef\u4ee5\u4e0d\u7ba1XSS\uff0c\u842c\u4e8b\u5927\u5409\u4e86\u3002\u4f46\u662f\u9451\u65bc\u4f4e\u5ec9\u7684\u6210\u672c\uff0c\u9084\u662f\u90fd\u914d\u4e0a\u3002<\/span><\/p>\n<h3 id=\"toc-3\"><span>HTTPS \u5b89\u5168\u914d\u7f6e<\/span><\/h3>\n<p><span>\u555f\u7528HTTPS \u4e26\u6b63\u78ba\u914d\u7f6e\u4e86\u8b49\u66f8\uff0c\u610f\u5473\u8457\u6578\u64da\u50b3\u8f38\u904e\u7a0b\u4e2d\u7121\u6cd5\u88ab\u7b2c\u4e09\u8005\u89e3\u5bc6\u6216\u4fee\u6539\u3002\u6709\u4e86HTTPS\uff0c\u4e5f\u5f97\u5408\u7406\u914d\u7f6e\u597dWeb Server\uff0c\u624d\u80fd\u767c\u63ee\u6700\u5927\u50f9\u503c\u3002\u6211\u7684\u535a\u5ba2\u95dc\u65bcHTTPS \u9019\u4e00\u584a\u6709\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/span><\/p>\n<pre><b class=\"name\"><span>NGINX<\/span><\/b><code class=\"lang-nginx\"><span class=\"hljs-title\">ssl_certificate<\/span>      \/home\/jerry\/ssl\/server.crt;\r\n<span class=\"hljs-title\">ssl_certificate_key<\/span>  \/home\/jerry\/ssl\/server.key;\r\n<span class=\"hljs-title\">ssl_dhparam<\/span>          \/home\/jerry\/ssl\/dhparams.pem;\r\n\r\n<span class=\"hljs-title\">ssl_ciphers<\/span>          ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:DES-CBC3-SHA;\r\n\r\n<span class=\"hljs-title\">ssl_prefer_server_ciphers<\/span>  <span class=\"hljs-built_in\">on<\/span>;\r\n\r\n<span class=\"hljs-title\">ssl_protocols<\/span>        TLSv1 TLSv1.<span class=\"hljs-number\">1<\/span> TLSv1.<span class=\"hljs-number\">2<\/span>;\r\n<\/code><\/pre>\n<p><span>\u6700\u7d42\u6548\u679c\u662f\u6211\u7684\u535a\u5ba2\u5728<\/span><a href=\"https:\/\/www.ssllabs.com\/ssltest\/index.html\"><span>ssllabs<\/span><\/a><span>\u7684\u6e2c\u8a66\u4e2d\u9054\u5230\u4e86A+\uff0c\u5982\u4e0b\u5716\uff1a<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"loaded\" src=\"https:\/\/st.imququ.com\/i\/webp\/static\/uploads\/2015\/05\/ssl_lab.png.webp\" alt=\"ssllabs test\" width=\"600\" height=\"420\" \/><\/p>\n<p><span>\u5982\u4f55\u914d\u7f6e<\/span><code>ssl_ciphers<\/code><span>\u53ef\u4ee5\u53c3\u8003<\/span><a href=\"https:\/\/cipherli.st\/\"><span>\u9019\u500b\u7db2\u7ad9<\/span><\/a><span>\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u9019\u500b\u7db2\u7ad9\u9ed8\u8a8d\u63d0\u4f9b\u7684\u52a0\u5bc6\u65b9\u5f0f\u5b89\u5168\u6027\u8f03\u9ad8\uff0c\u4e00\u4e9b\u4f4e\u7248\u672c\u5ba2\u6236\u7aef\u4e26\u4e0d\u652f\u6301\uff0c\u4f8b\u5982IE9-\u3001Android2.2-\u548cJava6-\u3002\u5982\u679c\u9700\u8981\u652f\u6301\u9019\u4e9b\u8001\u820a\u7684\u5ba2\u6236\u7aef\uff0c\u9700\u8981\u9ede\u4e00\u4e0b\u7db2\u7ad9\u4e0a\u7684\u300cYes, give me a ciphersuite that works with legacy \/ old software\u300d\u93c8\u63a5\u3002<\/span><\/p>\n<p><span>\u53e6\u5916\uff0c\u6211\u5728<\/span><code>ssl_ciphers<\/code><span>\u6700\u958b\u59cb\u52a0\u4e0a\u4e86<\/span><code>CHACHA20<\/code><span>\uff0c\u9019\u662f\u56e0\u70ba\u6211\u7684Nginx\u652f\u6301\u4e86CHACHA20_POLY1305\u52a0\u5bc6\u7b97\u6cd5\uff0c\u9019\u662f\u7531Google\u958b\u767c\u7684\u65b0\u4e00\u4ee3\u52a0\u5bc6\u65b9\u5f0f\uff0c\u5b83\u6709\u5169\u65b9\u9762\u512a\u52e2\uff1a\u66f4\u597d\u7684\u5b89\u5168\u6027\u548c\u66f4\u597d\u7684\u6027\u80fd\uff08\u5c24\u5176\u662f\u5728\u79fb\u52d5\u548c\u53ef\u7a7f\u6234\u8a2d\u5099\u4e0a\uff09\u3002\u4e0b\u9762\u6709\u4e00\u5f35\u79fb\u52d5\u5e73\u53f0\u4e0a\u5b83\u8207AES-GCM\u7684\u52a0\u5bc6\u901f\u5ea6\u5c0d\u6bd4\u5716\uff08<\/span><a href=\"http:\/\/googleonlinesecurity.blogspot.jp\/2014\/04\/speeding-up-and-strengthening-https.html\"><span>via<\/span><\/a><span>\uff09\uff1a<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"loaded\" src=\"https:\/\/st.imququ.com\/i\/webp\/static\/uploads\/2015\/05\/chacha.png.webp\" alt=\"chacha20 poly1305\" width=\"600\" height=\"371\" \/><\/p>\n<p><span>\u555f\u7528CHACHA20_POLY1305\u6700\u7c21\u55ae\u7684\u65b9\u6cd5\u662f\u5728\u7de8\u8b6fNginx\u6642\uff0c\u4f7f\u7528<\/span><a href=\"http:\/\/www.libressl.org\/\"><span>LibreSSL<\/span><\/a><span>\u4ee3\u66ffOpenSSL\u3002\u4e0b\u9762\u662f\u7528Chrome\u8a2a\u554f\u6211\u7684\u535a\u5ba2\u6642\uff0c\u9ede\u64ca\u5730\u5740\u6b04\u5c0f\u9396\u986f\u793a\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u770b\u5230\u52a0\u5bc6\u65b9\u5f0f\u4f7f\u7528\u7684\u5c31\u662fCHACHA20_POLY1305\uff1a<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"loaded\" src=\"https:\/\/st.imququ.com\/i\/webp\/static\/uploads\/2015\/05\/imququ-chacha.png.webp\" alt=\"imququ.com\" width=\"320\" height=\"455\" \/><\/p>\n<p><span>\u95dc\u65bcCHACHA20_POLY1305\u5b89\u5168\u6027\u548c\u6027\u80fd\u7684\u8a73\u7d30\u4ecb\u7d39\u53ef\u4ee5<\/span><a href=\"https:\/\/blog.cloudflare.com\/do-the-chacha-better-mobile-performance-with-cryptography\/\"><span>\u67e5\u770b\u672c\u6587<\/span><\/a><span>\u3002<\/span><\/p>\n<blockquote><p><span>\u88dc\u5145\uff1a\u4f7f\u7528CHACHA20_POLY1305\u7684\u6700\u4f73\u5be6\u8e10\u662f\u300c\u50c5\u91dd\u5c0d\u4e0d\u652f\u6301AES-NI\u7684\u7d42\u7aef\u4f7f\u7528CHACHA20\u7b97\u6cd5\uff0c\u5426\u5247\u4f7f\u7528AES-GCM\u300d\u3002\u95dc\u65bc\u9019\u500b\u8a71\u984c\u7684\u8a73\u7d30\u89e3\u91cb\u548c\u914d\u7f6e\u65b9\u6cd5\uff0c\u8acb\u53c3\u8003\u6211\u7684\u9019\u7bc7\u6587\u7ae0\uff1a<\/span><a href=\"https:\/\/imququ.com\/post\/optimize-ssl-ciphers-with-boringssl.html\"><span>\u4f7f\u7528BoringSSL\u512a\u5316HTTPS\u52a0\u5bc6\u7b97\u6cd5\u9078\u64c7<\/span><\/a><span>\u3002<\/span><\/p><\/blockquote>\n<p><span>\u95dc\u65bc<\/span><code>ssl_dhparam<\/code><span>\u7684\u914d\u7f6e\uff0c\u53ef\u4ee5\u53c3\u8003\u9019\u7bc7\u6587\u7ae0\uff1a<\/span><a href=\"https:\/\/weakdh.org\/sysadmin.html\"><span>Guide to Deploying Diffie-Hellman for TLS<\/span><\/a><span>\u3002<\/span><\/p>\n<p><span>SSLv3\u5df2\u88ab\u8b49\u5be6\u4e0d\u5b89\u5168\uff0c\u6240\u4ee5\u5728<\/span><code>ssl_protocols<\/code><span>\u6307\u4ee4\u4e2d\uff0c\u6211\u4e26\u6c92\u6709\u5305\u542b\u5b83\u3002<\/span><\/p>\n<p><span>\u5c07<\/span><code>ssl_prefer_server_ciphers<\/code><span>\u914d\u7f6e\u70baon\uff0c\u53ef\u4ee5\u78ba\u4fdd\u5728TLSv1\u63e1\u624b\u6642\uff0c\u4f7f\u7528\u670d\u52d9\u7aef\u7684\u914d\u7f6e\u9805\uff0c\u4ee5\u589e\u5f37\u5b89\u5168\u6027\u3002<\/span><\/p>\n<p><span>\u597d\u4e86\uff0c\u672c\u6587\u5148\u5c31\u9019\u6a23\uff0c\u5f8c\u9762\u518d\u5beb\u8ddf\u6027\u80fd\u6709\u95dc\u7684\u914d\u7f6e\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u6709\u7d30\u5fc3\u7684\u670b\u53cb\u554f\u6211\uff0c\u70ba\u4ec0\u9ebc\u4f60\u7684\u535a\u5ba2\u526f\u6a19\u984c\u662f\u300c\u5c08\u6ce8WEB \u7aef\u958b\u767c\u300d\uff0c\u662f\u4e0d\u662f\u5c11\u4e86\u300c\u524d\u7aef\u300d\u7684\u300c\u524d\u300d\u3002\u6211\u60f3\u8aaa\u7684\u662f\uff0c\u5118\u7ba1\u6211\u5f9e\u7562\u696d\u5230\u73fe\u5728\u4e03\u5e74\u5de6\u53f3\u7684\u6642\u9593\u4e00\u76f4\u90fd\u5728\u5c08\u696d\u524d\u7aef\u5718\u968a\u5f9e\u4e8b\u524d\u7aef\u76f8\u95dc\u5de5\u4f5c\uff0c\u4f46\u9019\u4e26\u4e0d\u610f\u5473\u8457\u6211\u7684\u77e5\u8b58\u9ad4\u4fc2\u5c31\u5fc5\u9808\u5c40\u9650\u65bc\u524d\u7aef\u9019\u500b\u7bc4\u7587\u5167\u3002\u73fe\u5728\u6bd4\u8f03\u6d41\u884c\u300c\u5168\u68e7\u5de5\u7a0b\u5e2b\u300d\u7684\u6982\u5ff5\uff0c\u6211\u89ba\u5f97\u5168\u68e7\u610f\u5473\u8457\u4e00\u500b\u9805\u76ee\u4e2d\uff0c\u5404\u500b\u5d17\u4f4d\u6240\u9700\u8981\u7684\u6280\u80fd\u4f60\u90fd\u5177\u5099\uff0c\u4f46\u4e26\u4e0d\u4e00\u5b9a\u610f\u5473\u8457\u4f60\u4ec0\u9ebc\u90fd\u9700\u8981\u505a\u3002\u4f60\u9700\u8981\u505a\u4ec0\u9ebc\uff0c\u66f4\u591a\u662f\u7531\u80fd\u529b\u3001\u4eba\u54e1\u914d\u6bd4\u4ee5\u53ca\u6210\u672c\u7b49\u5404\u500b\u56e0\u7d20\u6240\u6c7a\u5b9a\u3002\u5118\u7ba1\u6211\u73fe\u5728\u7684\u5de5\u4f5c\u8077\u8cac\u662f\u5728WEB \u524d\u7aef\u9818\u57df\uff0c\u4f46\u662f\u6211\u7684\u95dc\u6ce8\u9ede\u5728\u6574\u500bWEB \u7aef\u3002 \u6211\u63a5\u89f8\u904e\u7684\u6709\u4e9b\u524d\u7aef\u670b\u53cb\uff0c\u5f9e\u4e00\u958b\u59cb\u5c31\u628a\u81ea\u5df1\u5c40\u9650\u5728\u4e00\u500b\u5f88\u5c0f\u7684\u7bc4\u570d\u4e4b\u4e2d\uff0c\u9019\u5728\u5927\u516c\u53f8\u5230\u4e5f\u7121\u6240\u8b02\uff0c\u5927\u516c\u53f8\u5206\u5de5\u660e\u78ba\uff0c\u57fa\u790e\u8a2d\u65bd\u9f4a\u5168\uff0c\u4f60\u53ea\u8981\u505a\u597d\u81ea\u5df1\u64c5\u9577\u7684\u90a3\u90e8\u5206\u5c31\u53ef\u4ee5\u4e86\u3002\u4f46\u662f\u7576\u4ed6\u5011\u9032\u5165\u5275\u696d\u516c\u53f8\u4e4b\u5f8c\uff0c\u6703\u767c\u73fe\u4e00\u4e0b\u5b50\u4f86\u4e86\u597d\u591a\u4e4b\u524d\u5b8c\u5168\u6c92\u6709\u63a5\u89f8\u904e\u7684\u6771\u897f\uff0c\u5341\u5206\u88ab\u52d5\u3002 \u53bb\u5e74\u6211\u7528Lua +\u00a0OpenResty\u66ff\u63db\u4e86\u7dda\u4e0a\u5343\u842c\u7d1a\u7684PHP + Nginx\u670d\u52d9\uff0c\u81f3\u4eca\u7a69\u5b9a\u904b\u884c\uff0c\u7b97\u662f\u524d\u7aef\u4e4b\u5916\u7684\u4e00\u9ede\u5617\u8a66\u3002\u6211\u4e00\u76f4\u8a8d\u70ba\u5b78\u7fd2\u4efb\u4f55\u77e5\u8b58\u5f88\u91cd\u8981\u7684\u4e00\u9ede\u662f\u5be6\u8e10\uff0c\u6240\u4ee5\u6211\u4e00\u76f4\u90fd\u5728\u6298\u9a30\u6211\u7684VPS\uff0c\u9032\u884c\u5404\u7a2eWEB\u5b89\u5168\u3001\u512a\u5316\u76f8\u95dc\u7684\u5617\u8a66\u3002\u6211\u6253\u7b97\u5f9e\u5b89\u5168\u548c\u6027\u80fd\u5169\u65b9\u9762\u4ecb\u7d39\u4e00\u4e0b\u672c\u535a\u5ba2\u6240\u7528Nginx\u7684\u76f8\u95dc\u914d\u7f6e\uff0c\u4eca\u5929\u5148\u5beb\u5b89\u5168\u76f8\u95dc\u7684\u3002 \u96b1\u85cf\u4e0d\u5fc5\u8981\u7684\u4fe1\u606f \u5927\u5bb6\u53ef\u4ee5\u770b\u4e00\u4e0b\u6211\u7684\u535a\u5ba2\u8acb\u6c42\u97ff\u61c9\u982d\uff0c\u6709\u9019\u9ebc\u4e00\u884cserver: nginx\uff0c\u8aaa\u660e\u6211\u7528\u7684\u662fNginx\u670d\u52d9\u5668\uff0c\u4f46\u4e26\u6c92\u6709\u5177\u9ad4\u7684\u7248\u672c\u865f\u3002\u7531\u65bc\u67d0\u4e9bNginx\u6f0f\u6d1e\u53ea\u5b58\u5728\u65bc\u7279\u5b9a\u7684\u7248\u672c\uff0c\u96b1\u85cf\u7248\u672c\u865f\u53ef\u4ee5\u63d0\u9ad8\u5b89\u5168\u6027\u3002\u9019\u53ea\u9700\u8981\u5728\u914d\u7f6e\u88e1\u52a0\u4e0a\u9019\u500b\u5c31\u53ef\u4ee5\u4e86\uff1a server_tokens off; \u5982\u679c\u60f3\u8981\u66f4\u5fb9\u5e95\u96b1\u85cf\u6240\u7528Web Server\uff0c\u53ef\u4ee5\u4fee\u6539Nginx\u6e90\u78bc\uff0c\u628aServer Name\u6539\u6389\u518d\u7de8\u8b6f\uff0c\u5177\u9ad4\u6b65\u9a5f\u53ef\u4ee5\u81ea\u5df1\u641c\u7d22\u3002\u9700\u8981\u63d0\u9192\u7684\u662f\uff1a\u5982\u679c\u4f60\u7684\u7db2\u7ad9\u652f\u6301SPDY\uff0c\u53ea\u6539\u52d5\u7db2\u4e0a\u90a3\u4e9b\u6587\u7ae0\u5beb\u5230\u7684\u5730\u65b9\u9084\u4e0d\u5920\uff0c\u8ddfSPDY\u6709\u95dc\u7684\u4ee3\u78bc\u4e5f\u8981\u6539\u3002\u66f4\u7c21\u55ae\u7684\u505a\u6cd5\u662f\u6539\u7528Tengine\u9019\u500bNginx\u7684\u589e\u5f37\u7248\uff0c\u4e26\u6307\u5b9aserver_tag\u70baoff\u6216\u8005\u4efb\u4f55\u60f3\u8981\u7684\u503c\u5c31\u53ef\u4ee5\u4e86\u3002\u53e6\u5916\uff0c\u65e2\u7136\u60f3\u8981\u5fb9\u5e95\u96b1\u85cfNginx\uff0c404\u3001500\u7b49\u5404\u7a2e\u51fa\u932f\u9801\u4e5f\u9700\u8981\u81ea\u5b9a\u7fa9\u3002 \u540c\u6a23\uff0c\u4e00\u4e9bWEB\u8a9e\u8a00\u6216\u6846\u67b6\u9ed8\u8a8d\u8f38\u51fa\u7684x-powered-by\u4e5f\u6703\u6d29\u9732\u7db2\u7ad9\u4fe1\u606f\uff0c\u4ed6\u5011\u4e00\u822c\u90fd\u63d0\u4f9b\u4e86\u4fee\u6539\u6216\u79fb\u9664\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u81ea\u884c\u67e5\u770b\u624b\u518a\u3002\u5982\u679c\u90e8\u7f72\u4e0a\u7528\u5230\u4e86Nginx\u7684\u53cd\u5411\u4ee3\u7406\uff0c\u4e5f\u53ef\u4ee5\u901a\u904eproxy_hide_header\u6307\u4ee4\u96b1\u85cf\u5b83\uff1a proxy_hide_header X-Powered-By; \u7981\u7528\u975e\u5fc5\u8981\u7684\u65b9\u6cd5 \u7531\u65bc\u6211\u7684\u535a\u5ba2\u53ea\u8655\u7406\u4e86GET\u3001POST \u5169\u7a2e\u8acb\u6c42\u65b9\u6cd5\uff0c\u800cHTTP\/1 \u5354\u8b70\u9084\u898f\u5b9a\u4e86TRACE \u9019\u6a23\u7684\u65b9\u6cd5\u7528\u65bc\u7db2\u7d61\u8a3a\u65b7\uff0c\u9019\u4e5f\u53ef\u80fd\u6703\u66b4\u9732\u4e00\u4e9b\u4fe1\u606f\u3002\u6240\u4ee5\u6211\u91dd\u5c0dGET\u3001POST \u4ee5\u53caHEAD \u4e4b\u5916\u7684\u8acb\u6c42\uff0c\u76f4\u63a5\u8fd4\u56de\u4e86444 \u72c0\u614b\u78bc\uff08444 \u662fNginx \u5b9a\u7fa9\u7684\u97ff\u61c9\u72c0\u614b\u78bc\uff0c\u6703\u7acb\u5373\u65b7\u958b\u9023\u63a5\uff0c\u6c92\u6709\u97ff\u61c9\u6b63\u6587\uff09\u3002\u5177\u9ad4\u914d\u7f6e\u662f\u9019\u6a23\u7684\uff1a NGINXif ($request_method !~ ^(GET|HEAD|POST)$ ) { return 444; } \u5408\u7406\u914d\u7f6e\u97ff\u61c9\u982d \u6211\u7684\u535a\u5ba2\u662f\u7531\u81ea\u5df1\u7528ThinkJS \u5beb\u7684Node \u7a0b\u5e8f\u63d0\u4f9b\u670d\u52d9\uff0cNginx \u901a\u904eproxy_pass \u628a\u8acb\u6c42\u53cd\u5411\u4ee3\u7406\u7d66Node \u7d81\u5b9a\u7684IP \u548c\u7aef\u53e3\u3002\u5728\u6700\u7d42\u8f38\u51fa\u6642\uff0c\u6211\u7d66\u97ff\u61c9\u589e\u52a0\u4e86\u4ee5\u4e0b\u982d\u90e8\uff1a NGINXadd_header Strict-Transport-Security &#8220;max-age=31536000&#8221;; add_header X-Frame-Options deny; add_header X-Content-Type-Options &hellip; <a href=\"https:\/\/www.strongd.net\/?p=1520\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u672c\u535a\u5ba2Nginx \u914d\u7f6e\u4e4b\u5b89\u5168\u7bc7<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,20],"tags":[13],"class_list":["post-1520","post","type-post","status-publish","format-standard","hentry","category-linux","category-20","tag-nginx"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1520"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1520\/revisions"}],"predecessor-version":[{"id":1521,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1520\/revisions\/1521"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}