Nginx配置免费SSL证书

墨蓝 2024-04-17 16:03 185阅读 0赞

SSL证书HTTPS优势

购买域名型免费版(DV)SSL证书

安装SSL证书:参考官方文档

nginx中的配置:nginx配置https转发到tomcat

  1. server {
  2. listen 443;
  3. server_name lzhhuo.wordpython.com www.lzhhuo.wordpython.com;
  4. ssl on;
  5. index index.html index.htm;
  6. if ($http_host ~ "^lzhhuo.wordpython.com$") {
  7. rewrite ^(.*) https://www.lzhhuo.wordpython.com$1 permanent;
  8. }
  9. ssl_certificate 1_www.lzhhuo.wordpython.com_bundle.crt;
  10. ssl_certificate_key 2_www.lzhhuo.wordpython.com.key;
  11. ssl_session_timeout 5m;
  12. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  13. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  14. ssl_prefer_server_ciphers on;
  15. location / {
  16. proxy_pass http://127.0.0.1:8080/;
  17. proxy_connect_timeout 600;
  18. proxy_read_timeout 600;
  19. }
  20. }
  21. server {
  22. listen 80;
  23. server_name lzhhuo.wordpython.com www.lzhhuo.wordpython.com;
  24. if ($http_host ~ "^lzhhuo.wordpython.com$") {
  25. rewrite ^(.*) https://www.lzhhuo.wordpython.com$1 permanent;
  26. }
  27. rewrite ^(.*) https://www.lzhhuo.wordpython.com$1 permanent;
  28. location / {
  29. root /usr/local/apache-tomcat-8.5.28/webapps/ROOT;
  30. index index.html index.htm;
  31. }
  32. }

可能出现的问题:

错误:nginx:[emerg]unknown directive ssl错误

原因:配置SSL证书需要引用到nginx的中SSL这模块,然而我们一开始编译的Nginx的时候并没有把SSL模块一起编译进去。

解决: Nginx配置SSL证书时——nginx:[emerg]unknown directive ssl错误

效果:

Chrome:
在这里插入图片描述
Firefox:
在这里插入图片描述
IE:
在这里插入图片描述
Opera:
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,185人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Nginx 配置 ssl 证书

    > 在部署线下测试环境时浏览器会自动将http替换成https,又因为测试环境没有证书经常会导致跳转错误,所以自己配置一个ssl证书就可以避免这个问题。 > 下面记录我在M