{"id":45276,"date":"2024-10-06T21:43:15","date_gmt":"2024-10-06T13:43:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/45276\/"},"modified":"2024-10-06T21:43:15","modified_gmt":"2024-10-06T13:43:15","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-ubuntu-%e5%92%8c-centos-%e4%b8%8a%e5%95%9f%e7%94%a8-nginx-%e7%9a%84-http-2-%e5%8d%94%e8%ad%b0%e6%94%af%e6%8c%81","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/45276\/","title":{"rendered":"\u5982\u4f55\u5728 Ubuntu \u548c CentOS \u4e0a\u555f\u7528 Nginx \u7684 HTTP\/2 \u5354\u8b70\u652f\u6301"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8-ubuntu-%e5%92%8c-centos-%e4%b8%8a%e5%95%9f%e7%94%a8-nginx-%e7%9a%84-http-2-%e5%8d%94%e8%ad%b0%e6%94%af%e6%8c%81-eIkQVUUQES\">\u5982\u4f55\u5728 Ubuntu \u548c CentOS \u4e0a\u555f\u7528 Nginx \u7684 HTTP\/2 \u5354\u8b70\u652f\u6301<\/h1>\n<p>\u96a8\u8457\u7db2\u7d61\u6280\u8853\u7684\u767c\u5c55\uff0cHTTP\/2 \u5354\u8b70\u9010\u6f38\u6210\u70ba\u7db2\u7ad9\u6027\u80fd\u512a\u5316\u7684\u91cd\u8981\u5de5\u5177\u3002\u76f8\u6bd4\u65bc HTTP\/1.1\uff0cHTTP\/2 \u63d0\u4f9b\u4e86\u66f4\u5feb\u7684\u52a0\u8f09\u901f\u5ea6\u548c\u66f4\u9ad8\u7684\u6548\u7387\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u591a\u500b\u8acb\u6c42\u6642\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu \u548c CentOS \u7cfb\u7d71\u4e0a\u555f\u7528 Nginx \u7684 HTTP\/2 \u5354\u8b70\u652f\u6301\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-http-2%ef%bc%9f-eIkQVUUQES\">\u4ec0\u9ebc\u662f HTTP\/2\uff1f<\/h2>\n<p>HTTP\/2 \u662f HTTP \u5354\u8b70\u7684\u7b2c\u4e8c\u500b\u4e3b\u8981\u7248\u672c\uff0c\u65e8\u5728\u63d0\u9ad8\u7db2\u7d61\u6027\u80fd\u3002\u5b83\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u591a\u8def\u5fa9\u7528\uff1a<\/strong>\u5141\u8a31\u540c\u6642\u767c\u9001\u591a\u500b\u8acb\u6c42\u548c\u97ff\u61c9\uff0c\u6e1b\u5c11\u5ef6\u9072\u3002<\/li>\n<li><strong>\u982d\u90e8\u58d3\u7e2e\uff1a<\/strong>\u6e1b\u5c11\u8acb\u6c42\u548c\u97ff\u61c9\u7684\u5927\u5c0f\uff0c\u63d0\u9ad8\u50b3\u8f38\u6548\u7387\u3002<\/li>\n<li><strong>\u670d\u52d9\u5668\u63a8\u9001\uff1a<\/strong>\u670d\u52d9\u5668\u53ef\u4ee5\u4e3b\u52d5\u5411\u5ba2\u6236\u7aef\u63a8\u9001\u8cc7\u6e90\uff0c\u9032\u4e00\u6b65\u52a0\u5feb\u52a0\u8f09\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%9c%a8-ubuntu-%e4%b8%8a%e5%95%9f%e7%94%a8-nginx-%e7%9a%84-http-2-eIkQVUUQES\">\u5728 Ubuntu \u4e0a\u555f\u7528 Nginx \u7684 HTTP\/2<\/h2>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-1%ef%bc%9a%e5%ae%89%e8%a3%9d-nginx-eIkQVUUQES\">\u6b65\u9a5f 1\uff1a\u5b89\u88dd Nginx<\/h3>\n<p>\u9996\u5148\uff0c\u78ba\u4fdd\u4f60\u7684\u7cfb\u7d71\u5df2\u7d93\u5b89\u88dd\u4e86 Nginx\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-2%ef%bc%9a%e5%95%9f%e7%94%a8-ssl-eIkQVUUQES\">\u6b65\u9a5f 2\uff1a\u555f\u7528 SSL<\/h3>\n<p>HTTP\/2 \u9700\u8981 SSL\/TLS \u652f\u6301\uff0c\u56e0\u6b64\u9700\u8981\u70ba\u4f60\u7684\u7db2\u7ad9\u914d\u7f6e SSL \u8b49\u66f8\u3002\u53ef\u4ee5\u4f7f\u7528 Let&#8217;s Encrypt \u63d0\u4f9b\u7684\u514d\u8cbb\u8b49\u66f8\u3002\u5b89\u88dd Certbot \u5de5\u5177\uff1a<\/p>\n<pre><code>sudo apt install certbot python3-certbot-nginx<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7372\u53d6\u8b49\u66f8\uff1a<\/p>\n<pre><code>sudo certbot --nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-3%ef%bc%9a%e9%85%8d%e7%bd%ae-nginx-%e6%94%af%e6%8c%81-http-2-eIkQVUUQES\">\u6b65\u9a5f 3\uff1a\u914d\u7f6e Nginx \u652f\u6301 HTTP\/2<\/h3>\n<p>\u6253\u958b Nginx \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<\/code><\/pre>\n<p>\u5728 server \u5340\u584a\u4e2d\uff0c\u5c07 listen \u6307\u4ee4\u4fee\u6539\u70ba\u652f\u6301 HTTP\/2\uff1a<\/p>\n<pre><code>listen 443 ssl http2;<\/code><\/pre>\n<p>\u78ba\u4fdd\u4f60\u7684\u914d\u7f6e\u6587\u4ef6\u770b\u8d77\u4f86\u50cf\u9019\u6a23\uff1a<\/p>\n<pre><code>server {\n    listen 443 ssl http2;\n    server_name your_domain.com;\n\n    ssl_certificate \/etc\/letsencrypt\/live\/your_domain.com\/fullchain.pem;\n    ssl_certificate_key \/etc\/letsencrypt\/live\/your_domain.com\/privkey.pem;\n\n    location \/ {\n        root \/var\/www\/html;\n        index index.html index.htm;\n    }\n}<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-4%ef%bc%9a%e9%87%8d%e5%95%9f-nginx-eIkQVUUQES\">\u6b65\u9a5f 4\uff1a\u91cd\u555f Nginx<\/h3>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u91cd\u555f Nginx \u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e5%9c%a8-centos-%e4%b8%8a%e5%95%9f%e7%94%a8-nginx-%e7%9a%84-http-2-eIkQVUUQES\">\u5728 CentOS \u4e0a\u555f\u7528 Nginx \u7684 HTTP\/2<\/h2>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-1%ef%bc%9a%e5%ae%89%e8%a3%9d-nginx-eIkQVUUQES\">\u6b65\u9a5f 1\uff1a\u5b89\u88dd Nginx<\/h3>\n<p>\u5728 CentOS \u4e0a\u5b89\u88dd Nginx\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo yum install epel-release\nsudo yum install nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-2%ef%bc%9a%e5%95%9f%e7%94%a8-ssl-eIkQVUUQES\">\u6b65\u9a5f 2\uff1a\u555f\u7528 SSL<\/h3>\n<p>\u540c\u6a23\u9700\u8981\u914d\u7f6e SSL \u8b49\u66f8\uff0c\u53ef\u4ee5\u4f7f\u7528 Certbot\uff1a<\/p>\n<pre><code>sudo yum install certbot python2-certbot-nginx<\/code><\/pre>\n<p>\u7136\u5f8c\u7372\u53d6\u8b49\u66f8\uff1a<\/p>\n<pre><code>sudo certbot --nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-3%ef%bc%9a%e9%85%8d%e7%bd%ae-nginx-%e6%94%af%e6%8c%81-http-2-eIkQVUUQES\">\u6b65\u9a5f 3\uff1a\u914d\u7f6e Nginx \u652f\u6301 HTTP\/2<\/h3>\n<p>\u7de8\u8f2f Nginx \u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u5e38\u4f4d\u65bc \/etc\/nginx\/nginx.conf\uff1a<\/p>\n<pre><code>sudo nano \/etc\/nginx\/nginx.conf<\/code><\/pre>\n<p>\u5728 server \u5340\u584a\u4e2d\uff0c\u5c07 listen \u6307\u4ee4\u4fee\u6539\u70ba\u652f\u6301 HTTP\/2\uff1a<\/p>\n<pre><code>listen 443 ssl http2;<\/code><\/pre>\n<p>\u78ba\u4fdd\u914d\u7f6e\u6587\u4ef6\u6b63\u78ba\u7121\u8aa4\uff0c\u7136\u5f8c\u91cd\u555f Nginx\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-eIkQVUUQES\">\u7e3d\u7d50<\/h2>\n<p>\u555f\u7528 Nginx \u7684 HTTP\/2 \u5354\u8b70\u652f\u6301\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u3002\u7121\u8ad6\u662f\u5728 Ubuntu \u9084\u662f CentOS \u4e0a\uff0c\u901a\u904e\u7c21\u55ae\u7684\u914d\u7f6e\u6b65\u9a5f\uff0c\u4f60\u90fd\u53ef\u4ee5\u8f15\u9b06\u5be6\u73fe\u9019\u4e00\u76ee\u6a19\u3002\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u4e86\u89e3\u66f4\u591a\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Ubuntu \u548c CentOS \u4e0a\u555f\u7528 Nginx \u7684 HTTP\/2 \u5354\u8b70\u652f\u6301\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u548c\u52a0\u8f09\u901f\u5ea6\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-45276","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45276","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=45276"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45276\/revisions"}],"predecessor-version":[{"id":45277,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45276\/revisions\/45277"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=45276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=45276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=45276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}