From af25de5d9e659ba3f91fea49414c12dd8e037b83 Mon Sep 17 00:00:00 2001 From: CHL Date: Mon, 20 Feb 2017 22:06:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B3=E8=AF=B7=E7=BF=BB=E8=AF=91Hosting=20D?= =?UTF-8?q?jango=20With=20Nginx=20and=20Gunicorn=20on=20Linux=20(#5158)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Translating]72% Of The People I Follow On Twitter Are Men Translating by Flowsnow! 72% Of The People I Follow On Twitter Are Men * update * [Translating by flowsnow] How to Enable HTTP/2 in Nginx on Ubuntu and CentOS * Translaed--20170217 How to Enable HTTP2 in Nginx on Ubuntu and CentOS * [Translating by Flowsnow] Hosting Django With Nginx and Gunicorn on Linux * 删去不必要修改 --- ...Django With Nginx and Gunicorn on Linux.md | 1 + ...ble HTTP2 in Nginx on Ubuntu and CentOS.md | 111 ------------------ ...ble HTTP2 in Nginx on Ubuntu and CentOS.md | 110 +++++++++++++++++ 3 files changed, 111 insertions(+), 111 deletions(-) delete mode 100644 sources/tech/20170217 How to Enable HTTP2 in Nginx on Ubuntu and CentOS.md create mode 100644 translated/tech/20170217 How to Enable HTTP2 in Nginx on Ubuntu and CentOS.md diff --git a/sources/tech/20170205 Hosting Django With Nginx and Gunicorn on Linux.md b/sources/tech/20170205 Hosting Django With Nginx and Gunicorn on Linux.md index 95203f013e..cba811c59e 100644 --- a/sources/tech/20170205 Hosting Django With Nginx and Gunicorn on Linux.md +++ b/sources/tech/20170205 Hosting Django With Nginx and Gunicorn on Linux.md @@ -1,3 +1,4 @@ +Translating by Flowsnow ### Hosting Django With Nginx and Gunicorn on Linux ![](https://linuxconfig.org/images/gunicorn_logo.png?58963dfd) diff --git a/sources/tech/20170217 How to Enable HTTP2 in Nginx on Ubuntu and CentOS.md b/sources/tech/20170217 How to Enable HTTP2 in Nginx on Ubuntu and CentOS.md deleted file mode 100644 index 740acbb8ac..0000000000 --- a/sources/tech/20170217 How to Enable HTTP2 in Nginx on Ubuntu and CentOS.md +++ /dev/null @@ -1,111 +0,0 @@ -How to Enable HTTP/2 in Nginx on Ubuntu and CentOS -============================================================ - - - ![](https://www.rosehosting.com/blog/wp-content/uploads/2017/02/enable-http2-nginx.jpg) - -HTTP/2 is a major revision of the HTTP network protocol and it focuses on performance improvements. Its goal is to reduce the latency as well as to make the web applications faster by allowing multiple concurrent requests between the web browser and the server across a single TCP connection. In this tutorial, we are going to show you how to enable HTTP/2 in Nginx on a Linux VPS using Ubuntu or CentOS as an operating system. If you use Apache, you can check our tutorial on [how to enable HTTP/2 in Apache on Ubuntu][6]. - -### Prerequisites - -In order to be able to follow the instructions and enable HTTP/2 on your server, you need to have [Nginx][7] already preinstalled. Make sure that it is functional and there are no errors with its configuration. You can check this using the command below: - -``` -sudo nginx -t -``` - -Additionally, you need to have root access to the server or at least you need to have a non-root system user with sudo privileges so you can make changes in the Nginx configuration files without having permission problems. Finally, you need to have a [domain name][8] and valid [SSL certificate][9] issued for the domain name. - -### Enable HTTP/2 in Nginx on Ubuntu - -To enable HTTP/2 in Nginx on an [Ubuntu VPS][10] you should edit the default Nginx server block. We will use `nano`but you can use a text editor of your choice. - -``` -sudo nano /etc/nginx/sites-available/default -``` - -Add the following server block: - -``` -server { - server_name domain.com www.domain.com; - listen 443 ssl http2 default_server; - root /var/www/html; - index index.html; - - location / { - try_files $uri $uri/ =404; - } - - ssl_certificate /etc/nginx/ssl/domain.com.crt; - ssl_certificate_key /etc/nginx/ssl/domain.com.key; -} - -server { - listen 80; - server_name domain.com www.domain.com; - return 301 https://$server_name$request_uri; -} -``` - -Make sure that `domain.com` is replaced with your real domain name. Additionally, the document root and the path to the SSL certificate and key should be correctly set. - -Once you finish with editing the server block, save and close the file. Check if there are errors in the Nginx configuration using the command: - -``` -sudo nginx -t -``` - -And then restart Nginx for the changes to take effect - -``` -sudo systemctl restart nginx.service -``` - -If you’d like to enable HTTP/2 for another domain name, you can check our blog post on [how to set up Nginx server blocks on Ubuntu and CentOS][11]. - -### Enable HTTP/2 in Nginx on CentOS - -To enable HTTP/2 on a [CentOS VPS][12] you need to follow the exact same steps as on Ubuntu. The location of the Nginx block file is the only difference. To edit the default Nginx server block on CentOS you should look into the `/etc/nginx/conf.d` directory. - -``` -# nano /etc/nginx/conf.d/default.conf -``` - -Once again, check if there are errors with the configuration, save and close the file, then restart the Nginx service using the command below: - -``` -# systemctl restart nginx.service -``` - -To check whether HTTP/2 is enabled in Nginx you can use some [online HTTP/2 checker tool][13]. - -Of course you don’t have to do any of this if you use one of our [Linux VPS hosting][14] services, in which case you can simply ask our expert Linux admins to help you enable HTTP/2 in Nginx on your server. They are available 24×7 and will take care of your request immediately. - -PS. If you liked this post please share it with your friends on the social networks using the buttons below or simply leave a comment. Thanks. - --------------------------------------------------------------------------------- - -via: https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/ - -作者:[rosehosting.com][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/ -[1]:https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/ -[2]:https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/#comments -[3]:https://www.rosehosting.com/blog/category/tutorials/ -[4]:https://plus.google.com/share?url=https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/ -[5]:http://www.linkedin.com/shareArticle?mini=true&url=https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/&title=How%20to%20Enable%20HTTP%2F2%20in%20Nginx%20on%20Ubuntu%20and%20CentOS&summary=HTTP/2%20is%20a%20major%20revision%20of%20the%20HTTP%20network%20protocol%20and%20it%20focuses%20on%20performance%20improvements.%20Its%20goal%20is%20to%20reduce%20the%20latency%20as%20well%20as%20to%20make%20the%20web%20applications%20faster%20by%20allowing%20multiple%20concurrent%20requests%20between%20the%20web%20browser%20and%20the%20server%20across%20a%20single%20TCP%20connection.%20In%20... -[6]:https://www.rosehosting.com/blog/how-to-set-up-apache-with-http2-support-on-ubuntu-16-04/ -[7]:https://www.rosehosting.com/nginx-hosting.html -[8]:https://secure.rosehosting.com/clientarea/index.php?/checkdomain/domain-registration/ -[9]:https://www.rosehosting.com/ssl-certificates.html -[10]:https://www.rosehosting.com/ubuntu-vps.html -[11]:https://www.rosehosting.com/blog/how-to-set-up-nginx-server-blocks-on-ubuntu-and-centos/ -[12]:https://www.rosehosting.com/centos-vps.html -[13]:https://www.rosehosting.com/network-tools/http2-support.html -[14]:https://www.rosehosting.com/linux-vps-hosting.html diff --git a/translated/tech/20170217 How to Enable HTTP2 in Nginx on Ubuntu and CentOS.md b/translated/tech/20170217 How to Enable HTTP2 in Nginx on Ubuntu and CentOS.md new file mode 100644 index 0000000000..0a031c16bf --- /dev/null +++ b/translated/tech/20170217 How to Enable HTTP2 in Nginx on Ubuntu and CentOS.md @@ -0,0 +1,110 @@ +如何在Ubuntu和CentOS上启用Nginx的HTTP/2协议 +=== + + ![](https://www.rosehosting.com/blog/wp-content/uploads/2017/02/enable-http2-nginx.jpg) + +HTTP/2是HTTP网络协议的主要修订版本,它专注于HTTP协议的性能改进。HTTP/2协议的目标是减少延迟,并且允许在Web浏览器和服务器之间发起多个并发请求,因此Web应用程序会更快。在本篇教程中,我们将像你展示如何在安装有Ubuntu或CentOS作为操作系统的Linux VPS上使用开启Nginx的HTTP/2协议。如果你使用Apache,你可以查看我们的另一篇教程:[如何在Ubuntu上开启Apache的HTTP/2协议][6]。 + +### 必备条件 + +为了能够按照本篇教程最终在服务器上启用HTTP/2协议,你需要先安装好 [Nginx][7] 。并且确保功能正常而且配置没有错误。你可以使用下面的命令来检查一下: + +``` +sudo nginx -t +``` + +此外,你需要有服务器的root访问权限,或者至少有一个具有sudo权限的非root系统用户,以便你在修改Nginx配置文件的时候不会出现权限问题。最后你需要有一个[域名][8]和一个颁发给这个域名的有效的[SSL证书][9]。 + +### 在Ubuntu上开启Nginx的HTTP/2协议 + +为了在[Ubuntu VPS][10]上开启Nginx的HTTP/2协议,你需要编辑默认的Nginx的服务块,我们使用的是 `nano`,你可以使用你自己的文本编辑器。 + +``` +sudo nano /etc/nginx/sites-available/default +``` + +增加下面的服务块: + +``` +server { + server_name domain.com www.domain.com; + listen 443 ssl http2 default_server; + root /var/www/html; + index index.html; + + location / { + try_files $uri $uri/ =404; + } + + ssl_certificate /etc/nginx/ssl/domain.com.crt; + ssl_certificate_key /etc/nginx/ssl/domain.com.key; +} + +server { + listen 80; + server_name domain.com www.domain.com; + return 301 https://$server_name$request_uri; +} +``` + +确保 `domain.com` 被你真正的域名替换掉了。 此外,应正确设置文档根目录,还有SSL证书和密钥的路径。 + +当你编辑完成这个服务块之后,需要保存并关闭文件。使用以下命令检查Nginx配置是否有错误: + +``` +sudo nginx -t +``` + +为了刚刚的改变生效,需要重启Nginx: + +``` +sudo systemctl restart nginx.service +``` + +如果你想为另一个域名开启HTTP/2协议,你可以查看我们的博客[如何在Ubuntu和CentOS上设置Nginx服务块][11]。 + +### 在CentOS上开启Nginx的HTTP/2协议 + +为了在[CentOS VPS][12] 开启Nginx的HTTP/2协议,你需要按照Ubuntu上完全相同的步骤做。唯一的不同点是Nginx块文件的位置。为了在CentOS上编辑默认的Nginx服务块,你需要进入`/etc/nginx/conf.d` 这个文件夹。 + +``` +# nano /etc/nginx/conf.d/default.conf +``` + +再次检查配置是否有错误,保存并关闭文件,然后使用以下命令重新启动Nginx服务: + +``` +# systemctl restart nginx.service +``` + +为了检测Nginx的HTTP/2协议是否开启成功,你可以使用一些[在线HTTP/2检测工具][13]。 + +当然如果你使用我们的[Linux VPS主机][14]服务,在这种情况下你可以简易地要求我们的专家级的Linux管理员帮助你在你的服务器上启用Nginx的HTTP/2协议。他们提供7×24小时的服务,并且会很快关注的你要求。 + +PS:如果你喜欢这篇文章,请使用下面的按钮分享给你社交网络上的朋友们,或者发表一下评论。谢谢。 + +-------------------------------------------------------------------------------- + +via: https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/ + +作者:[rosehosting.com][a] +译者:[Flowsnow](https://github.com/Flowsnow) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/ +[1]: https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/ +[2]: https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/#comments +[3]: https://www.rosehosting.com/blog/category/tutorials/ +[4]: https://plus.google.com/share?url=https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/ +[5]: http://www.linkedin.com/shareArticle?mini=true&url=https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/&title=How%20to%20Enable%20HTTP%2F2%20in%20Nginx%20on%20Ubuntu%20and%20CentOS&summary=HTTP/2%20is%20a%20major%20revision%20of%20the%20HTTP%20network%20protocol%20and%20it%20focuses%20on%20performance%20improvements.%20Its%20goal%20is%20to%20reduce%20the%20latency%20as%20well%20as%20to%20make%20the%20web%20applications%20faster%20by%20allowing%20multiple%20concurrent%20requests%20between%20the%20web%20browser%20and%20the%20server%20across%20a%20single%20TCP%20connection.%20In%20... +[6]: https://www.rosehosting.com/blog/how-to-set-up-apache-with-http2-support-on-ubuntu-16-04/ +[7]: https://www.rosehosting.com/nginx-hosting.html +[8]: https://secure.rosehosting.com/clientarea/index.php?/checkdomain/domain-registration/ +[9]: https://www.rosehosting.com/ssl-certificates.html +[10]: https://www.rosehosting.com/ubuntu-vps.html +[11]: https://www.rosehosting.com/blog/how-to-set-up-nginx-server-blocks-on-ubuntu-and-centos/ +[12]: https://www.rosehosting.com/centos-vps.html +[13]: https://www.rosehosting.com/network-tools/http2-support.html +[14]: https://www.rosehosting.com/linux-vps-hosting.html \ No newline at end of file