{"id":45448,"date":"2024-10-06T23:26:15","date_gmt":"2024-10-06T15:26:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/45448\/"},"modified":"2024-10-06T23:26:15","modified_gmt":"2024-10-06T15:26:15","slug":"%e5%9c%a8-centos-linux-7-5-%e4%b8%8a%e4%bd%bf%e7%94%a8-lets-encrypt-%e4%bb%a5%e4%bf%9d%e8%ad%b7-nginx","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/45448\/","title":{"rendered":"\u5728 CentOS Linux 7.5 \u4e0a\u4f7f\u7528 Let\u2019s Encrypt \u4ee5\u4fdd\u8b77 Nginx"},"content":{"rendered":"<h1 id=\"%e5%9c%a8-centos-linux-7-5-%e4%b8%8a%e4%bd%bf%e7%94%a8-lets-encrypt-%e4%bb%a5%e4%bf%9d%e8%ad%b7-nginx-rvNnygpMYb\">\u5728 CentOS Linux 7.5 \u4e0a\u4f7f\u7528 Let\u2019s Encrypt \u4ee5\u4fdd\u8b77 Nginx<\/h1>\n<p>\u96a8\u8457\u7db2\u7d61\u5b89\u5168\u610f\u8b58\u7684\u63d0\u9ad8\uff0c\u8d8a\u4f86\u8d8a\u591a\u7684\u7db2\u7ad9\u9078\u64c7\u4f7f\u7528 SSL\/TLS \u8b49\u66f8\u4f86\u52a0\u5bc6\u6578\u64da\u50b3\u8f38\u3002Let\u2019s Encrypt \u662f\u4e00\u500b\u514d\u8cbb\u7684\u8b49\u66f8\u9812\u767c\u6a5f\u69cb\uff0c\u63d0\u4f9b\u81ea\u52d5\u5316\u7684 SSL \u8b49\u66f8\u7533\u8acb\u548c\u66f4\u65b0\u670d\u52d9\uff0c\u7279\u5225\u9069\u5408\u65bc\u4f7f\u7528 Nginx \u7684\u4f3a\u670d\u5668\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS Linux 7.5 \u4e0a\u4f7f\u7528 Let\u2019s Encrypt \u4f86\u4fdd\u8b77 Nginx\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-rvNnygpMYb\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u7684\u4f3a\u670d\u5668\u4e0a\u5df2\u7d93\u5b89\u88dd\u4e86 Nginx \u548c EPEL\uff08Extra Packages for Enterprise Linux\uff09\u5eab\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88dd EPEL\uff1a<\/p>\n<pre><code>sudo yum install epel-release<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5b89\u88dd Nginx\uff1a<\/p>\n<pre><code>sudo yum install nginx<\/code><\/pre>\n<p>\u555f\u52d5 Nginx \u4e26\u8a2d\u7f6e\u5176\u5728\u958b\u6a5f\u6642\u81ea\u52d5\u555f\u52d5\uff1a<\/p>\n<pre><code>sudo systemctl start nginx\nsudo systemctl enable nginx<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-certbot-rvNnygpMYb\">\u5b89\u88dd Certbot<\/h2>\n<p>Certbot \u662f\u4e00\u500b\u7528\u65bc\u7372\u53d6\u548c\u7ba1\u7406 Let\u2019s Encrypt \u8b49\u66f8\u7684\u5de5\u5177\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Certbot\uff1a<\/p>\n<pre><code>sudo yum install certbot python2-certbot-nginx<\/code><\/pre>\n<h2 id=\"%e7%8d%b2%e5%8f%96-ssl-%e8%ad%89%e6%9b%b8-rvNnygpMYb\">\u7372\u53d6 SSL \u8b49\u66f8<\/h2>\n<p>\u5728\u7372\u53d6\u8b49\u66f8\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u7684\u57df\u540d\u5df2\u7d93\u6307\u5411\u60a8\u7684\u4f3a\u670d\u5668 IP \u5730\u5740\u3002\u7136\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u7372\u53d6 SSL \u8b49\u66f8\uff1a<\/p>\n<pre><code>sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com<\/code><\/pre>\n<p>\u8acb\u5c07 &#8220;yourdomain.com&#8221; \u548c &#8220;www.yourdomain.com&#8221; \u66ff\u63db\u70ba\u60a8\u7684\u5be6\u969b\u57df\u540d\u3002\u57f7\u884c\u6b64\u547d\u4ee4\u5f8c\uff0cCertbot \u5c07\u81ea\u52d5\u914d\u7f6e Nginx \u4e26\u7372\u53d6 SSL \u8b49\u66f8\u3002\u60a8\u5c07\u88ab\u8981\u6c42\u8f38\u5165\u96fb\u5b50\u90f5\u4ef6\u5730\u5740\u4ee5\u63a5\u6536\u91cd\u8981\u7684\u901a\u77e5\uff0c\u4e26\u540c\u610f Let\u2019s Encrypt \u7684\u670d\u52d9\u689d\u6b3e\u3002<\/p>\n<h2 id=\"%e8%87%aa%e5%8b%95%e6%9b%b4%e6%96%b0%e8%ad%89%e6%9b%b8-rvNnygpMYb\">\u81ea\u52d5\u66f4\u65b0\u8b49\u66f8<\/h2>\n<p>Let\u2019s Encrypt \u7684\u8b49\u66f8\u6709\u6548\u671f\u70ba 90 \u5929\uff0c\u56e0\u6b64\u5efa\u8b70\u8a2d\u7f6e\u81ea\u52d5\u66f4\u65b0\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u6dfb\u52a0\u4e00\u500b cron \u4efb\u52d9\u4f86\u5be6\u73fe\u9019\u4e00\u9ede\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7de8\u8f2f crontab\uff1a<\/p>\n<pre><code>sudo crontab -e<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>0 0 * * * \/usr\/bin\/certbot renew --quiet<\/code><\/pre>\n<p>\u9019\u5c07\u6bcf\u5929\u5348\u591c\u81ea\u52d5\u6aa2\u67e5\u4e26\u66f4\u65b0\u8b49\u66f8\u3002<\/p>\n<h2 id=\"%e6%aa%a2%e6%9f%a5-nginx-%e9%85%8d%e7%bd%ae-rvNnygpMYb\">\u6aa2\u67e5 Nginx \u914d\u7f6e<\/h2>\n<p>\u5728\u5b8c\u6210\u8b49\u66f8\u5b89\u88dd\u5f8c\uff0c\u60a8\u53ef\u4ee5\u6aa2\u67e5 Nginx \u7684\u914d\u7f6e\u662f\u5426\u6b63\u78ba\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u5c07\u770b\u5230 &#8220;syntax is ok&#8221; \u548c &#8220;test is successful&#8221; \u7684\u6d88\u606f\u3002\u7136\u5f8c\uff0c\u91cd\u65b0\u52a0\u8f09 Nginx \u4ee5\u61c9\u7528\u66f4\u6539\uff1a<\/p>\n<pre><code>sudo systemctl reload nginx<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-rvNnygpMYb\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u5df2\u7d93\u6210\u529f\u5728 CentOS Linux 7.5 \u4e0a\u4f7f\u7528 Let\u2019s Encrypt \u70ba Nginx \u914d\u7f6e\u4e86 SSL \u8b49\u66f8\u3002\u9019\u4e0d\u50c5\u80fd\u63d0\u9ad8\u7db2\u7ad9\u7684\u5b89\u5168\u6027\uff0c\u9084\u80fd\u589e\u5f37\u7528\u6236\u7684\u4fe1\u4efb\u611f\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u5b89\u5168\u7684\u7db2\u7ad9\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u81f3\u95dc\u91cd\u8981\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u5730\u5340\u7684\u4f3a\u670d\u5668\uff0c\u78ba\u4fdd\u60a8\u7684\u7db2\u7ad9\u5b89\u5168\u904b\u884c\u662f\u6bcf\u4f4d\u7db2\u7ad9\u7ba1\u7406\u54e1\u7684\u8cac\u4efb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 CentOS Linux 7.5 \u4e0a\u4f7f\u7528 Let\u2019s Encrypt \u70ba Nginx \u914d\u7f6e SSL \u8b49\u66f8\uff0c\u63d0\u5347\u7db2\u7ad9\u5b89\u5168\u6027\u3002<\/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-45448","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45448","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=45448"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45448\/revisions"}],"predecessor-version":[{"id":45449,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45448\/revisions\/45449"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=45448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=45448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=45448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}