java配置ssl证书实现https请求,一级域名和二级域名配置
2019-09-20 本文已影响0人
编程小石头666
上一节给大家讲了服务器的部署,正常的http请求都可以实现了,但是我们做小程序开发时需要用到https,所以这一节要教大家如何让自己的后台服务器实现https请求。这节是以java部署服务器并配置https为例,别的语言可以把这篇文章作为参考。
我们实现https必须先具备下面条件
1,申请一个ssl证书(阿里云腾讯云都可以免费申请)
2,有一台自己的服务器(阿里云腾讯云都可以)
一,申请ssl证书
这里以腾讯云为例,我们首先要登录自己的腾讯云服务器,然后进入ssl证书申请页。

然后选择免费的ssl证书,申请即可

给证书绑定域名,一个证书只能绑定一个顶级域名或者二级域名。

证书申请成功

二,下载ssl证书
点击下载证书后,会得到一个压缩包,解压后可以看到每种服务器对应的证书,选择自己的即可。

我们看下tomcat对应的文件都有什么

把证书放到我们项目里

三,springboot项目配置ssl证书

配置好以后,我们就可以使用maven打包了。

打包完成后,我们把打包好的jar包改下名字

改名完成后,我们通过FileZilla 把这个jar包上传到服务器。

上面上个脚本是我提前定义好的,我的上一篇文章里有讲怎么定义脚本文件,这三个脚本是为了我们的项目可以长期运行在后台用的。
四,进入服务器,部署项目。
点击登录,登录服务器

进入服务器对应的目录

我们通过执行 ./run.sh 来运行项目, 如果遇到没有权限运行的问题,就在run.sh所在目录下执行 chmod u+x *.sh 这样就ok了。

通过上图可以看到,我们成功执行来 run.sh脚本。
然后执行下面命令可以查看我们项目是否成功启动
tail -f nohup.out

五,访问https

通过上图我们可以看到,我们成功的访问到了https。到这里我们的https就配置好了,然后把我们的域名配置到小程序里就可以直接在小程序里使用https了。