解决浏览器强制https问题
在将服务尝试着从http
协议往https
协议迁移成功之后,又出于测试调试的目的将服务转回到http
协议,却发现在浏览器输入http
会被自动跳转到https
。
HTTP Strict Transport Security (HSTS) is an opt-in security enhancement that is specified by a web application through the use of a special response header. Once a supported browser receives this header that browser will prevent any communications from being sent over HTTP to the specified domain and will instead send all communications over HTTPS. It also prevents HTTPS click through prompts on browsers.
查阅相关资料,发现这是浏览器的HSTS
(HTTP Strict Transport Security
)功能引起的。在安装配置SSL
证书时,可以使用一种能使数据传输更加安全的Web
安全协议,即在服务器端上开启HSTS
,它会告诉浏览器只能通过HTTPS
访问,而绝对禁止HTTP
方式。
因此,只要关闭浏览器的HSTS
功能就可以解决这个问题,但是只能通过特定的方式,而不是清除浏览器缓存那么简单。
Chrome浏览器
- 地址栏中输入
chrome://net-internals/#hsts
。 - 在
Delete domain
中输入项目的域名,并Delete
(删除)。 - 可以在
Query domain
测试是否删除成功。
在最下面的Delete domain security policies
里输入想要删除的网址,注意是去掉http://
前缀的网址,如:h5.baidu.com
edge浏览器
- 地址栏输入
edge://net-internals/#hsts
- 接着操作同Chrome浏览器