玩转SpringBoot
来源:互联网 发布:淘宝的昵称有什么用 编辑:程序博客网 时间:2024/05/21 05:56
玩转SpringBoot - 03 开启https协议访问
- 玩转SpringBoot - 03 开启https协议访问
- 前言
- 配置方式
- 密匙配置方式
- trust 密匙
- 修改hosts 文件
- windows 系统
- linux 系统
0. 前言
如果将SpringBoot 项目直接暴露在外网前端,有时http 协议已经无法满足个人需要,这时,就需要开启https 协议访问方式。
本次测试域名为www.test.com
1. 配置方式
密匙配置方式
在项目配置文件中,增加以下属性:
server.port = 9444server.ssl.key-store = classpath:www.test.com.jksserver.ssl.key-store-password = 11111111server.ssl.key-store-type = JKS
server.port
– 项目启动端口号:
– 自我修改启动端口号,https 协议默认访问端口为433,如为其他端口号,访问时则需要携带。server.ssl.key-store
– jks 密匙路径
– 将jks 文件放置在src/mian/resources 目录下即可搜索到。- server.ssl.key-store-password
– 密匙密码
– 生成jks 文件时的密码 - server.ssl.key-store-type
– 密匙类型
– 填写JKS 即可,如为其他可用密匙文件,可填写相应密匙类型
当项目启动后,即可通过https 协议访问项目了。
trust 密匙
此配置方式不常用,只做记录。
server.ssl.trust-store= # Trust store that holds SSL certificates.server.ssl.trust-store-password= # Password used to access the trust store.server.ssl.trust-store-provider= # Provider for the trust store.server.ssl.trust-store-type= # Type of the trust store.
官方提供以上属性进行配置,可自行配置测试。
2. 修改hosts 文件
Hosts - The static table lookup for host name(主机名查询静态表)
由于https 协议区分域名,所以本地测试时,可以修改系统hosts 文件来达到本地完美测试的程度。
windows 系统
win7/8/10 系统,可使用管理员权限编辑C:\Windows\System32\drivers\etc
下的hosts 文件内容,添加记录:
127.0.0.1 www.test.com
然后可以使用cmd 命令工具,运行ping www.test.com,即可发现解析后的ip 地址为127.0.0.1
,此时即可正常测试。
如果ip 解析没有改变,可运行
ipconfig /flushdns
刷新本地dns 缓存。
linux 系统
可访问/etc/hosts
文件,使用vim 工具编辑,添加以下记录:
127.0.0.1 www.test.com
输入:wq 保存并退出,即可实现域名解析,进行访问。
由于当前市场linux 系统层出不穷,不同的linux 版本,配置文件也可能不同。比如Debian的对应文件是/etc/hostname,详细的文件位置,可进行自行进行搜索。
- 玩转SpringBoot
- 玩转SpringBoot
- 玩转SpringBoot
- 玩转SpringBoot
- Spring开发居家旅行必备神器,从零开始玩转SpringBoot
- 玩转指针,玩转C语言
- 玩转static, 玩转模块化设计
- springboot注解大全(转)
- springboot
- SpringBoot
- SpringBoot
- springboot
- SpringBoot
- springboot
- SpringBoot
- springboot
- Springboot
- springboot
- 中序线索化二叉树并遍历
- Android录音
- USTC软件工程课程项目— 1、团队介绍
- ajax异步加载使用post方法时一直输出相同结果,不能实现翻页
- 我常用的排他处理
- 玩转SpringBoot
- [hdu 6191 Query on A Tree] 字典树启发式合并
- 最大子数组--线性非递归实现
- 作业调度框架 Quartz 学习笔记
- Java 懒汉模式之Volatile优化
- Python基础-函数
- linux下的FTP服务
- 看完这些,你就知道为什么Xmanager这么好用?
- Python基础-类和对象