宝塔设置A站点SSL,同服务器下其他未设SSL站点访问HTTPS默认会打开A站点

2019-09-18 23:47:23 举例宝塔创建A站点开去SSL,HTTPS,其它站点未开去SSL,但以HTTPS访问这些未设置SSL的站点时,默认打开时A站点内容。在未指定SSL默认站点时,未开启SSL的站点使用HTTPS会直接访问到已开启

在未指定SSL默认站点时,未开启SSL的站点使用HTTPS会直接访问到已开启SSL的站点,串站点。

举例宝塔创建A站点开去SSL,HTTPS,其它站点未开去SSL,但以HTTPS访问这些未设置SSL的站点时,默认打开时A站点内容。

一个网站A接入了https,网站B没有使用ssl,但是使用https访问会进去到网站A的https,请问这个怎么解决?

官方的说法是:【在未指定SSL默认站点时,未开启SSL的站点使用HTTPS会直接访问到已开启SSL的站点】。但是即使设置了默认站点,还是存在这个问题。

解决方法(以Nginx环境为例):

设置默认站点,让默认站点不能访问,开启ssl但不解析域名,这个ssl也是随便找的。

第一步:创建一个站点

创建一个站点域名就使用你域名乱命名二级域名(避免以后使用),比如你域名时abc.com,你们你新建站点就绑定aaaakkd2dd.abc.com,这里aaaakkd2dd就是乱取的,需要注意新建站点不需要解析。

新建站点绑定一个无用域名
新建站点绑定一个无用域名

第二步:删除新建站点的默认文件

默认创建站点对应站点根目录中会有index.html,将其删除。
目的是让站点不能访问

删除创建站点index.html文件
删除创建站点index.html文件

第三步:开启SSL

需要准备SSL证书文件.pem和.key文件,这里为大家准备一个过期的但可以使用的证书内容。

1、证书key和pem文件(Nginx环境用的)

.key文件代码:

-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAlcZJiGVMbbzrWzkmhBJxjoMbFSSCtLzcY0poxwTxyxzd2pw1
45OIV9WllYNTotQyOheiJEN9hGgU/qjIRpKg/1KrSnxsykYwevMjsyM/Rs3W7MRr
EGjCqr9VfWCnC/mOhwrSeEtL76DaMTpYIYIVemK+W+BajKD5nNekjs6567phMFbm
Bsqil3hXWE31GyIaYwQqbMWI1gCSX/Tvh3dmt2dVE2/7q4soZPVSlNqEq92U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UHAwEGCCsGAQUFBwMCMBIGA1UdEwEB/wQIMAYBAf8C
AQAwNAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdp
Y2VydC5jb20wQgYDVR0fBDswOTA3oDWgM4YxaHR0cDovL2NybDMuZGlnaWNlcnQu
Y29tL0RpZ2lDZXJ0R2xvYmFsUm9vdENBLmNybDBMBgNVHSAERTBDMDcGCWCGSAGG
/WwBAjAqMCgGCCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BT
MAgGBmeBDAECATANBgkqhkiG9w0BAQsFAAOCAQEAK3Gp6/aGq7aBZsxf/oQ+TD/B
SwW3AU4ETK+GQf2kFzYZkby5SFrHdPomunx2HBzViUchGoofGgg7gHW0W3MlQAXW
M0r5LUvStcr82QDWYNPaUy4taCQmyaJ+VB+6wxHstSigOlSNF2a6vg4rgexixeiV
4YSB03Yqp2t3TeZHM9ESfkus74nQyW7pRGezj+TC44xCagCQQOzzNmzEAP2SnCrJ
sNE2DpRVMnL8J6xBRdjmOsC3N6cQuKuRXbzByVBjCqAA8t1L0I+9wXJerLPyErjy
rMKWaBFLmfK/AHNF4ZihwPGOc7w6UHczBZXH5RFzJNnww+WnKuTPI0HfnVH8lg==
-----END CERTIFICATE-----

以上代码直接拷贝即可使用。虽然以上是过期的证书,但也是可以用于解决问题。

2、宝塔后台开启SSL

拷贝证书代码开启这个新建站点ssl
拷贝SSL证书代码开启这个新建站点

完成站点SSL HTTPS

第四步:设置默认站点 完成问题解决

将这个新建站点设置为默认站点
将这个新建站点设置为默认站点

到此完成解决访问非开启ssl的站点以https访问却打开是开启ssl站点,这种有点像串站感觉。

最后如果以https访问未开启SSL站点,将不会打开SSL站点了。

更新