{"id":51401,"date":"2024-10-08T18:18:16","date_gmt":"2024-10-08T10:18:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/51401\/"},"modified":"2024-11-14T10:43:25","modified_gmt":"2024-11-14T02:43:25","slug":"ubuntu-16-04-17-10-%e4%b8%8b-nginx-%e4%bd%bf%e7%94%a8-lets-encrypt-%e6%ad%a3%e7%a2%ba%e5%95%9f%e7%94%a8%e5%8a%a0%e5%af%86-https","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/51401\/","title":{"rendered":"Ubuntu 16.04\/17.10 \u4e0b Nginx \u4f7f\u7528 Let\u2019s Encrypt \u6b63\u78ba\u555f\u7528\u52a0\u5bc6 HTTPS"},"content":{"rendered":"<h1 id=\"ubuntu-16-04-17-10-%e4%b8%8b-nginx-%e4%bd%bf%e7%94%a8-lets-encrypt-%e6%ad%a3%e7%a2%ba%e5%95%9f%e7%94%a8%e5%8a%a0%e5%af%86-https-cXGhzmNbqP\">Ubuntu 16.04\/17.10 \u4e0b Nginx \u4f7f\u7528 Let\u2019s Encrypt \u6b63\u78ba\u555f\u7528\u52a0\u5bc6 HTTPS<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u7684\u5b89\u5168\u6027\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u4f7f\u7528 HTTPS \u52a0\u5bc6\u5354\u8b70\u4e0d\u50c5\u80fd\u4fdd\u8b77\u7528\u6236\u7684\u6578\u64da\uff0c\u9084\u80fd\u63d0\u9ad8\u7db2\u7ad9\u7684\u641c\u7d22\u5f15\u64ce\u6392\u540d\u3002Let\u2019s Encrypt \u662f\u4e00\u500b\u514d\u8cbb\u7684\u8b49\u66f8\u9812\u767c\u6a5f\u69cb\uff0c\u63d0\u4f9b\u7c21\u55ae\u7684\u65b9\u5f0f\u4f86\u7372\u53d6\u548c\u5b89\u88dd SSL\/TLS \u8b49\u66f8\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu 16.04 \u548c 17.10 \u7cfb\u7d71\u4e0a\uff0c\u4f7f\u7528 Nginx \u914d\u7f6e Let\u2019s Encrypt \u4ee5\u555f\u7528 HTTPS\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-cXGhzmNbqP\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u5df2\u7d93\u5b89\u88dd\u4e86 Nginx \u548c Certbot\u3002Certbot \u662f\u4e00\u500b\u81ea\u52d5\u5316\u5de5\u5177\uff0c\u53ef\u4ee5\u5e6b\u52a9\u60a8\u7372\u53d6\u548c\u5b89\u88dd Let\u2019s Encrypt \u8b49\u66f8\u3002<\/p>\n<h3 id=\"%e5%ae%89%e8%a3%9d-nginx-cXGhzmNbqP\">\u5b89\u88dd Nginx<\/h3>\n<pre><code>sudo apt update\nsudo apt install nginx\n<\/code><\/pre>\n<h3 id=\"%e5%ae%89%e8%a3%9d-certbot-cXGhzmNbqP\">\u5b89\u88dd Certbot<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5b89\u88dd Certbot \u53ca\u5176 Nginx \u63d2\u4ef6\uff1a<\/p>\n<pre><code>sudo apt install certbot python3-certbot-nginx\n<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-nginx-cXGhzmNbqP\">\u914d\u7f6e Nginx<\/h2>\n<p>\u5728\u7372\u53d6\u8b49\u66f8\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd Nginx \u6b63\u5728\u904b\u884c\u4e26\u4e14\u914d\u7f6e\u6b63\u78ba\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 Nginx \u7684\u72c0\u614b\uff1a<\/p>\n<pre><code>sudo systemctl status nginx\n<\/code><\/pre>\n<p>\u5982\u679c Nginx \u5c1a\u672a\u555f\u52d5\uff0c\u8acb\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5\u5b83\uff1a<\/p>\n<pre><code>sudo systemctl start nginx\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u914d\u7f6e Nginx \u7684\u865b\u64ec\u4e3b\u6a5f\u3002\u7de8\u8f2f Nginx \u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u5e38\u4f4d\u65bc \/etc\/nginx\/sites-available\/default\uff1a<\/p>\n<pre><code>sudo nano \/etc\/nginx\/sites-available\/default\n<\/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}\n<\/code><\/pre>\n<p>\u5c07 your_domain.com \u66ff\u63db\u70ba\u60a8\u7684\u5be6\u969b\u57df\u540d\u3002\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\uff0c\u7136\u5f8c\u6aa2\u67e5 Nginx \u914d\u7f6e\u662f\u5426\u6b63\u78ba\uff1a<\/p>\n<pre><code>sudo nginx -t\n<\/code><\/pre>\n<p>\u5982\u679c\u6c92\u6709\u932f\u8aa4\uff0c\u8acb\u91cd\u65b0\u52a0\u8f09 Nginx\uff1a<\/p>\n<pre><code>sudo systemctl reload nginx\n<\/code><\/pre>\n<h2 id=\"%e7%8d%b2%e5%8f%96-lets-encrypt-%e8%ad%89%e6%9b%b8-cXGhzmNbqP\">\u7372\u53d6 Let\u2019s Encrypt \u8b49\u66f8<\/h2>\n<p>\u73fe\u5728\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Certbot \u7372\u53d6 Let\u2019s Encrypt \u8b49\u66f8\u3002\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo certbot --nginx -d your_domain.com -d www.your_domain.com\n<\/code><\/pre>\n<p>Certbot \u5c07\u81ea\u52d5\u70ba\u60a8\u914d\u7f6e Nginx \u4e26\u7372\u53d6\u8b49\u66f8\u3002\u904e\u7a0b\u4e2d\uff0c\u60a8\u9700\u8981\u540c\u610f Let\u2019s Encrypt \u7684\u670d\u52d9\u689d\u6b3e\uff0c\u4e26\u9078\u64c7\u662f\u5426\u5c07 HTTP \u6d41\u91cf\u91cd\u5b9a\u5411\u5230 HTTPS\u3002<\/p>\n<h2 id=\"%e8%87%aa%e5%8b%95%e7%ba%8c%e6%9c%9f%e8%ad%89%e6%9b%b8-cXGhzmNbqP\">\u81ea\u52d5\u7e8c\u671f\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\u7e8c\u671f\u3002Certbot \u63d0\u4f9b\u4e86\u4e00\u500b\u7c21\u55ae\u7684\u547d\u4ee4\u4f86\u5be6\u73fe\u9019\u4e00\u9ede\uff1a<\/p>\n<pre><code>sudo certbot renew --dry-run\n<\/code><\/pre>\n<p>\u9019\u500b\u547d\u4ee4\u5c07\u6a21\u64ec\u8b49\u66f8\u7e8c\u671f\u904e\u7a0b\uff0c\u78ba\u4fdd\u4e00\u5207\u6b63\u5e38\u904b\u884c\u3002\u5982\u679c\u6c92\u6709\u932f\u8aa4\uff0c\u60a8\u53ef\u4ee5\u653e\u5fc3\u5730\u8b93 Certbot \u81ea\u52d5\u7e8c\u671f\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-cXGhzmNbqP\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u5df2\u7d93\u6210\u529f\u5728 Ubuntu 16.04\/17.10 \u4e0a\u4f7f\u7528 Nginx \u914d\u7f6e\u4e86 Let\u2019s Encrypt \u8b49\u66f8\uff0c\u4e26\u555f\u7528\u4e86 HTTPS\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\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to correctly enable encrypted HTTPS on Nginx using Let\u2019s Encrypt in Ubuntu 16.04\/17.10 for secure web hosting.<\/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-51401","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51401","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=51401"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51401\/revisions"}],"predecessor-version":[{"id":51402,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51401\/revisions\/51402"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=51401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=51401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=51401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}