Nginx+Tomcat反向代理利用certbot实现https

一、利用Let‘s Encrypt 免费生成HTTPS证书

1、下载安装certbot(Let‘s Encrypt )

2、利用certbot生成证书

3、配置nginx的https证书

安装cerbot

[[email protected] ~]# wget https://dl.eff.org/certbot-auto

[[email protected] ~]# chmod a+x certbot-auto

[[email protected] ~]#./certbot-auto 

利用certbot生成证书

[[email protected] certbot]# ./certbot-auto certonly --email  [email protected] --agree-tos --webroot -w  /alidata1/www/timecash22/api3  -d  xxxx.zjm.cn/root/.local/share/letsencrypt/lib/python2.6/site-packages/cryptography/__init__.py:26: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of cryptography will drop support for Python 2.6

  DeprecationWarning

Saving debug log to /var/log/letsencrypt/letsencrypt.log

Obtaining a new certificate

Performing the following challenges:

http-01 challenge for xxx.zjm.cn

Using the webroot path /alidata1/www/timecash22/api3 for all unmatched domains.

Waiting for verification...

Cleaning up challenges

IMPORTANT NOTES:

 - Congratulations! Your certificate and chain have been saved at

   /etc/letsencrypt/live/xxx.zjm.cn/fullchain.pem. Your

   cert will expire on 2017-09-06. To obtain a new or tweaked version

   of this certificate in the future, simply run certbot-auto again.

   To non-interactively renew *all* of your certificates, run

   "certbot-auto renew"

 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let‘s Encrypt:   https://letsencrypt.org/donate

   Donating to EFF:                    https://eff.org/donate-le

-w:指定域名的根目录

-d:指定域名

Note:证书已经生成到了/etc/letsencrypy/live/xxx.zjm.cn下

Nginx配置https证书

#http访问

        server {   

        listen       80;

        server_name  www.xxx.cn;

        return     301  https://$server_name$request_uri;

    }

#https访问   

   server {

        listen 443 ssl;

        server_name www.xxx.cn;

        ssl_certificate /etc/letsencrypt/live/www.xxx.cn/fullchain.pem;

       ssl_certificate_key/etc/letsencrypt/live/www.xxx.cn/privkey.pem;

     ssl_trusted_certificate/etc/letsencrypt/live/www.xxx.cn/chain.pem;

     ssl_dhparam /etc/nginx/ssl/dhparam.pem;

          location  / {

                        proxy_pass http://www.xxx.cn/;

                      }

           }

ssl_certificate和ssl_certificate_key分别对应fullchain.pem,privkey.pem

ssl_dhparam通过以下命令生成

$ mkdir /etc/nginx/ssl

$ openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048

自动更新https证书

由于这个免费的证书只有90天的使用时间,所以遇到定时更新以下证书,这里是利用certbot每隔一段时间自动更新证书

手动执行更新

./certbot-auto  renew --dry-run

结合crontab每隔一段时间自动更新证书

30 2 * * 1 ./certbot-auto  renew  >> /var/log/le-renew.log

PS:

1、生成证书的时候切记-w参数后边的站点目录要写对,不然会报错

2、只需配nginx支持https就好,tomcat不用配置

3、前端代码和后端接口必须支持https

时间: 2024-08-25 16:12:25

Nginx+Tomcat反向代理利用certbot实现https的相关文章

详解Nginx + Tomcat 反向代理 如何在高效的在一台服务器部署多个站点

转载请注明出处:http://blog.csdn.net/smartbetter/article/details/53615313 上一篇分享了 Nginx + Tomcat 反向代理 负载均衡 集群 部署指南,感觉还是相当实用型的,但是一般集群部署是基于大访问量的,可能有的企业用不到,类似一些企业官网,访问量并不是很大,基于这个新需求,今天专门为大家分享一下 Nginx + Tomcat 反向代理 如何在一台服务器部署多个站点,节省服务器开支,就在这篇文章了. 首先我们需要安装好Nginx.j

Nginx + Tomcat 反向代理 如何在高效的在一台服务器部署多个站点

转载请注明出处:http://blog.csdn.net/smartbetter/article/details/53615313 上一篇分享了 Nginx + Tomcat 反向代理 负载均衡 集群 部署指南,感觉还是相当实用型的,但是一般集群部署是基于大访问量的,可能有的企业用不到,类似一些企业官网,访问量并不是很大,基于这个新需求,今天专门为大家分享一下 Nginx + Tomcat 反向代理 如何在一台服务器部署多个站点,节省服务器开支,就在这篇文章了. 首先我们需要安装好Nginx.j

Nginx + Tomcat 反向代理 负载均衡 集群 部署指南

转载请注明出处:http://blog.csdn.net/smartbetter/article/details/53535435 Nginx是一种服务器软件,也是一种高性能的http和反向代理服务器,同时还是一个代理邮件服务器.也就是说,我们在Nginx上可以发布网站,可以实现负载均衡(提高应答效率,避免服务器崩溃),还可以作为邮件服务器实现收发邮件等功能.而最常见的就是使用Nginx实现负载均衡. Nginx与其他服务器的性能比较: Tomcat服务器面向Java语言,是重量级的服务器,而N

nginx+Tomcat反向代理实现session会话保持

环境:nginx+tomcat一台nginx:192.168.2.198一台tomcat1:192.168.2.197一台tomcat2:192.168.2.199 一.Tomcat上操作(2台机器相同操作)1.jdk安装2.tomcat安装3.配置path环境变量4.启动tomcat5.创建测试页面并测试页面[[email protected] conf]#vi /usr/local/tomcat_a/webapps/test/index.jsp <%@ page language="j

nginx+tomcat 反向代理 负载均衡配置

1.nginx的安装和配置见:http://www.cnblogs.com/ll409546297/p/6795362.html 2.tomcat部署项目到对应的服务器上面并启动,不详解 3.在nginx中配置nginx.conf文件: user nobody; worker_processes 4; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid

NGINX如何反向代理Tomcat并且实现Session保持

简介 LNMT=Linux+Nginx+MySQL+Tomcat: Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器: 在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选: 架构需求 Tomcat实现JSP动态请求解析的基本架构 说明:由后端Tomcat负责解析动态jsp请求,但为了提高响应性能,在同一主机内配置Nginx做反向代理,转发所有请求至tomcat即可: 完整的LNMT架构设计 说明:本篇博客主要讲解单台Hapro

Nginx构建反向代理缓存服务器

防伪码:曾经沧海难为水,除却巫山不是云. 代理服务可简单的分为正向代理和反向代理: 正向代理: 用于代理内部网络对Internet的连接请求(如VPN/NAT),客户端指定代理服务器,并将本来要直接发送给目标Web服务器的HTTP请求先发送到代理服务器上,然后由代理服务器去访问Web服务器, 并将Web服务器的Response回传给客户端:  反向代理: 与正向代理相反,如果局域网向Internet提供资源,并让Internet上的其他用户可以访问局域网内资源, 也可以设置一个代理服务器, 它提

nginx配置反向代理概述

一.nginx反向代理:Web服务器的调度器 1.反向代理(Reverse Proxy)方式是指以代理服务器来接受客户端的连接请求,然后将请求转发给网络上的web服务器(可能是apache.nginx.tomcat.iis等),并将从web服务器上得到的结果返回给请求连接的客户端,此时代理服务器对外就表现为一个服务器. 图上可以看出:反向代理服务器代理网站Web服务器接收Http请求,对请求进行转发.而且nginx作为反向代理服务器可以根据用户请求的内容把请求转发给后端不同的web服务器,例如静

Nginx实现反向代理负载均衡与静态缓存

介绍: Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.在连接高并发的情况下,Nginx是Apache服务器不错的替代品,能够支持高达50000个并发连接数的响应. 实验环境: Hostname IP 系统 规划 n2.preferred 192.168.1.2 Centos 6.5 Web server n3.preferred 192.168.1.3 Centos 6.5 Web server n6.preferred 192.168.1.6