{"id":51063,"date":"2024-10-08T15:48:16","date_gmt":"2024-10-08T07:48:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/51063\/"},"modified":"2024-10-08T15:48:16","modified_gmt":"2024-10-08T07:48:16","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-ubuntu-20-04-lts-%e4%b8%8a%e4%bd%bf%e7%94%a8-lets-encrypt-ssl-%e5%ae%89%e8%a3%9d-nginx","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/51063\/","title":{"rendered":"\u5982\u4f55\u5728 Ubuntu 20.04 LTS \u4e0a\u4f7f\u7528 Let&#8217;s Encrypt SSL \u5b89\u88dd Nginx"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8-ubuntu-20-04-lts-%e4%b8%8a%e4%bd%bf%e7%94%a8-lets-encrypt-ssl-%e5%ae%89%e8%a3%9d-nginx-jnsZuJIVgC\">\u5982\u4f55\u5728 Ubuntu 20.04 LTS \u4e0a\u4f7f\u7528 Let&#8217;s Encrypt SSL \u5b89\u88dd Nginx<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u5b89\u5168\u6027\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u4f7f\u7528 SSL\uff08\u5b89\u5168\u5957\u63a5\u5c64\uff09\u8b49\u66f8\u53ef\u4ee5\u52a0\u5bc6\u7db2\u7ad9\u8207\u7528\u6236\u4e4b\u9593\u7684\u6578\u64da\u50b3\u8f38\uff0c\u5f9e\u800c\u4fdd\u8b77\u7528\u6236\u7684\u96b1\u79c1\u3002Let&#8217;s Encrypt \u662f\u4e00\u500b\u514d\u8cbb\u7684 SSL \u8b49\u66f8\u9812\u767c\u6a5f\u69cb\uff0c\u63d0\u4f9b\u7c21\u55ae\u7684\u65b9\u5f0f\u4f86\u7372\u53d6\u548c\u5b89\u88dd SSL \u8b49\u66f8\u3002\u672c\u6587\u5c07\u6307\u5c0e\u60a8\u5982\u4f55\u5728 Ubuntu 20.04 LTS \u4e0a\u4f7f\u7528 Let&#8217;s Encrypt SSL \u5b89\u88dd Nginx\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%8f%90%e6%a2%9d%e4%bb%b6-jnsZuJIVgC\">\u524d\u63d0\u689d\u4ef6<\/h2>\n<ul>\n<li>\u4e00\u53f0\u904b\u884c Ubuntu 20.04 LTS \u7684\u4f3a\u670d\u5668\u3002<\/li>\n<li>\u5df2\u5b89\u88dd Nginx \u7db2\u9801\u4f3a\u670d\u5668\u3002<\/li>\n<li>\u57df\u540d\u5df2\u6307\u5411\u60a8\u7684\u4f3a\u670d\u5668 IP \u5730\u5740\u3002<\/li>\n<li>\u5177\u6709 sudo \u6b0a\u9650\u7684\u7528\u6236\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%ad%a5%e9%a9%9f-1%ef%bc%9a%e6%9b%b4%e6%96%b0%e7%b3%bb%e7%b5%b1-jnsZuJIVgC\">\u6b65\u9a5f 1\uff1a\u66f4\u65b0\u7cfb\u7d71<\/h2>\n<p>\u9996\u5148\uff0c\u78ba\u4fdd\u60a8\u7684\u7cfb\u7d71\u662f\u6700\u65b0\u7684\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u66f4\u65b0\u7cfb\u7d71\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt upgrade<\/code><\/pre>\n<h2 id=\"%e6%ad%a5%e9%a9%9f-2%ef%bc%9a%e5%ae%89%e8%a3%9d-certbot-jnsZuJIVgC\">\u6b65\u9a5f 2\uff1a\u5b89\u88dd Certbot<\/h2>\n<p>Certbot \u662f\u4e00\u500b\u7528\u65bc\u7372\u53d6\u548c\u7ba1\u7406 Let&#8217;s Encrypt \u8b49\u66f8\u7684\u5de5\u5177\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Certbot \u53ca\u5176 Nginx \u63d2\u4ef6\uff1a<\/p>\n<pre><code>sudo apt install certbot python3-certbot-nginx<\/code><\/pre>\n<h2 id=\"%e6%ad%a5%e9%a9%9f-3%ef%bc%9a%e9%85%8d%e7%bd%ae-nginx-jnsZuJIVgC\">\u6b65\u9a5f 3\uff1a\u914d\u7f6e Nginx<\/h2>\n<p>\u5728\u7372\u53d6 SSL \u8b49\u66f8\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd Nginx \u914d\u7f6e\u6b63\u78ba\u3002\u6253\u958b\u60a8\u7684 Nginx \u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u5e38\u4f4d\u65bc \/etc\/nginx\/sites-available\/ \u76ee\u9304\u4e0b\uff1a<\/p>\n<pre><code>sudo nano \/etc\/nginx\/sites-available\/default<\/code><\/pre>\n<p>\u78ba\u4fdd\u60a8\u7684 server \u5340\u584a\u5305\u542b\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name your_domain.com www.your_domain.com;\n\n    location \/ {\n        root \/var\/www\/html;\n        index index.html index.htm;\n    }\n}<\/code><\/pre>\n<p>\u8acb\u5c07 &#8220;your_domain.com&#8221; \u66ff\u63db\u70ba\u60a8\u7684\u5be6\u969b\u57df\u540d\u3002\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\u3002<\/p>\n<h2 id=\"%e6%ad%a5%e9%a9%9f-4%ef%bc%9a%e7%8d%b2%e5%8f%96-ssl-%e8%ad%89%e6%9b%b8-jnsZuJIVgC\">\u6b65\u9a5f 4\uff1a\u7372\u53d6 SSL \u8b49\u66f8<\/h2>\n<p>\u4f7f\u7528 Certbot \u7372\u53d6 SSL \u8b49\u66f8\uff0c\u60a8\u53ef\u4ee5\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo certbot --nginx -d your_domain.com -d www.your_domain.com<\/code><\/pre>\n<p>Certbot \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\u66f4\u65b0\u901a\u77e5\uff0c\u4e26\u540c\u610f\u670d\u52d9\u689d\u6b3e\u3002<\/p>\n<h2 id=\"%e6%ad%a5%e9%a9%9f-5%ef%bc%9a%e9%a9%97%e8%ad%89-ssl-%e8%ad%89%e6%9b%b8-jnsZuJIVgC\">\u6b65\u9a5f 5\uff1a\u9a57\u8b49 SSL \u8b49\u66f8<\/h2>\n<p>\u7372\u53d6\u8b49\u66f8\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\u8b49\u66f8\u7684\u6709\u6548\u6027\uff1a<\/p>\n<pre><code>sudo certbot renew --dry-run<\/code><\/pre>\n<p>\u9019\u5c07\u6a21\u64ec\u8b49\u66f8\u7e8c\u671f\u904e\u7a0b\uff0c\u78ba\u4fdd\u4e00\u5207\u6b63\u5e38\u3002<\/p>\n<h2 id=\"%e6%ad%a5%e9%a9%9f-6%ef%bc%9a%e8%87%aa%e5%8b%95%e7%ba%8c%e6%9c%9f-jnsZuJIVgC\">\u6b65\u9a5f 6\uff1a\u81ea\u52d5\u7e8c\u671f<\/h2>\n<p>Let&#8217;s Encrypt \u8b49\u66f8\u7684\u6709\u6548\u671f\u70ba 90 \u5929\uff0c\u56e0\u6b64\u5efa\u8b70\u8a2d\u7f6e\u81ea\u52d5\u7e8c\u671f\u3002Certbot \u901a\u5e38\u6703\u81ea\u52d5\u6dfb\u52a0\u4e00\u500b cron \u4efb\u52d9\u4f86\u8655\u7406\u9019\u4e00\u9ede\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 cron \u4efb\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl status certbot.timer<\/code><\/pre>\n<p>\u5982\u679c\u986f\u793a\u70ba\u555f\u7528\u72c0\u614b\uff0c\u5247\u8868\u793a\u81ea\u52d5\u7e8c\u671f\u5df2\u8a2d\u7f6e\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-jnsZuJIVgC\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u5df2\u6210\u529f\u5728 Ubuntu 20.04 LTS \u4e0a\u4f7f\u7528 Let&#8217;s Encrypt SSL \u5b89\u88dd Nginx\u3002\u9019\u4e0d\u50c5\u63d0\u9ad8\u4e86\u7db2\u7ad9\u7684\u5b89\u5168\u6027\uff0c\u9084\u80fd\u589e\u5f37\u7528\u6236\u7684\u4fe1\u4efb\u611f\u3002\u82e5\u60a8\u9700\u8981\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\uff0c\u4e86\u89e3\u66f4\u591a\u95dc\u65bc\u4f3a\u670d\u5668\u548c\u96f2\u670d\u52d9\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Ubuntu 20.04 LTS \u4e0a\u4f7f\u7528 Let&#8217;s Encrypt SSL \u5b89\u88dd Nginx\uff0c\u78ba\u4fdd\u7db2\u7ad9\u5b89\u5168\u4e14\u514d\u8cbb\u7372\u5f97 SSL \u8b49\u66f8\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-51063","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51063","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=51063"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51063\/revisions"}],"predecessor-version":[{"id":51064,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51063\/revisions\/51064"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=51063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=51063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=51063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}