Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持 https 降级代理 #176

Closed
maxming2333 opened this issue Jun 27, 2018 · 17 comments
Closed

支持 https 降级代理 #176

maxming2333 opened this issue Jun 27, 2018 · 17 comments

Comments

@maxming2333
Copy link

maxming2333 commented Jun 27, 2018

平时我配置代理都是 ip domain 形式滴

类似这种形式

10.2.3.4 test.github.com

如果访问 http://test.github.com 这个很正常,可以正确得到需要的东西,因为访问了 10.2.3.480 端口

但是如果访问 https://test.github.com 就不正常了,这个时候 whistle 自动去访问了 10.2.3.4443 端口,但是因为内网机器上是不会部署证书滴,而且也只开放 80 端口

所以我加了一个全局的 rule

/^https:\/\/(.*)/i http://$1

这样就可以 hack 把 443 端口强制改成访问 80 端口了

但是问题来了,如果我想设置其他 rule 就不行了

因为 rule 只能存在一个,所以就很麻烦

如果你要让 https 降级 rule,就没办法自定义其他 rule 了

如果要自定义 rule 就必须带上 https 转换,https -> http

所以看一下这边有没有办法弄一个方法可以既满足 https 转 http,并且也支持自定义 rule

@maxming2333
Copy link
Author

应该是如果检测到该请求有 host 定义滴话,就启动 https 转换 http

比如

10.2.3.4 test.github.com

那么访问 https://test.github.com 的时候就做 https 转换 http
如果访问 https://www.github.com 的时候就不做转换了,因为没有配置 host 映射

@maxming2333
Copy link
Author

https 降级成 http 就必须用 rule

但是 rule 又是只能存在一个

所以没办法既要降级 https 也要使用 rule

@avwo
Copy link
Owner

avwo commented Jun 27, 2018

不需要设置对所有请求都生效,可以设置只对某个域名或路径生效:

# 所有该域名请求都转成http
www.test.com http://www.test.com

# 所有该路径及其子路径的请求都转成http请求
www.test.com/xxx http://www.test.com/xxx

用https访问http服务器的问题确实比较普遍,自定义host的请求自动把https转成http这个建议很好,下个版本加上。

@maxming2333
Copy link
Author

这个功能,计划那个版本添加上去呢

@avwo
Copy link
Owner

avwo commented Jul 2, 2018

这周会发布 v1.11.0 版本带上这个功能

@avwo
Copy link
Owner

avwo commented Jul 5, 2018

更新下whistle

@avwo avwo closed this as completed Jul 5, 2018
@maxming2333
Copy link
Author

还是不行,最终还是到了 443 端口了

image

@maxming2333
Copy link
Author

我去掉了全局 rule

/^https:\/\/(.*)/i http://$1

@avwo
Copy link
Owner

avwo commented Jul 9, 2018

不是返回200了吗

@maxming2333
Copy link
Author

这是因为我开发机同时监听了 80 和 443

可以看到截图上 server port 还是 443,并不是 80

@maxming2333
Copy link
Author

如果我开发机不监听 443 端口,就 404 了

按道理 自动降级 应该把数据转发到 80 端口才正确

@avwo
Copy link
Owner

avwo commented Jul 9, 2018

要确保443端口没有服务监听,不然的话不会自动降级,在服务器上 lsof -i:443 看看

@freeozyl80
Copy link

额,我这里是想https 转 https,不是想让降级

@avwo
Copy link
Owner

avwo commented Jul 9, 2018

他先会以https的方式去请求,如果是https报错,才会请求http,你是起http服务?

@freeozyl80
Copy link

tsw服务

@avwo
Copy link
Owner

avwo commented Jul 9, 2018

默认起http服务的吧,企业微信私聊

@maxming2333
Copy link
Author

@avwo 验证 ok

原来你的内部流程是先探测 443 端口是否可用,如果不可用,才会降级到默认的 80 端口

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants