准备工作

选择服务和系统

nginx-http2 - 图2

按照下面的步骤一步步执行即可

image.png

最终配置

  1. server {
  2. server_name ssl.xiaoranzife.com; # managed by Certbot
  3. root /usr/share/nginx/feup;
  4. # Load configuration files for the default server block.
  5. include /etc/nginx/default.d/\*.conf;
  6. # 初始文件是: include /etc/nginx/default.d/*.conf;
  7. # 这里为了md的高亮加了个\
  8. location / {
  9. try_files $uri /index.html @router;
  10. }
  11. error_page 404 /404.html;
  12. location = /404.html {
  13. }
  14. error_page 500 502 503 504 /50x.html;
  15. location = /50x.html {
  16. }
  17. listen [::]:443 ssl ipv6only=on; # managed by Certbot
  18. listen 443 ssl; # managed by Certbot
  19. ssl_certificate /etc/letsencrypt/live/ssl.xiaoranzife.com/fullchain.pem; # managed by Certbot
  20. ssl_certificate_key /etc/letsencrypt/live/ssl.xiaoranzife.com/privkey.pem; # managed by Certbot
  21. include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  22. ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  23. }
  24. server {
  25. if ($host = ssl.xiaoranzife.com) {
  26. return 301 https://$host$request_uri;
  27. } # managed by Certbot
  28. listen 80 ;
  29. listen [::]:80 ;
  30. server_name ssl.xiaoranzife.com;
  31. return 404; # managed by Certbot
  32. }

开启http2

  1. # [server]
  2. {
  3. ...
  4. listen 443 ssl http2;
  5. ...
  6. }
  7. nginx -t
  8. nginx -s reload

验证http2

nginx-http2 - 图4