关于域名 http https 之间相互跳转 证书 问题


日常工作中经常会有需求说强制用户http 或 https访问,这里我们通常会用到 301 跳转。

测试手段

浏览器访问可能会存在缓存问题,可以使用curl -i http://domain.com

正常返回:HTTP/1.1 301 Moved Permanently

使用curl -L -v 查看整个跳转的过程

curl -L -v http://domain.com

跳转场景

跳转需要留意ssl证书问题,一般会有如下几种场景

1. http ---> https

前提:跳转后的https域名需要有证书。

可以直接在前端nginx 之类的负载均衡配置rewrite ,或cdn开启强制http->https跳转(目前cdn厂商都支持类似功能);

2. https ---> http

前提:跳转前的https域名需要有证书。

可以直接在前端nginx 之类的负载均衡配置rewrite ,或cdn开启强制https->http跳转(目前cdn厂商都支持类似功能);

3. https ---> https

前提:跳转前、后两个域名都有ssl证书。

如果证书不一致可能会出现下列报错:

curl https://b.com -i

curl: (51) SSL: certificate subject name 'a.com' does not match target host name 'b.com'