yeahwu / image

8 stars 1 forks source link

利用Caddy搭建HTTPS正向代理翻墙详解 | 无二自留地 #29

Open yeahwu opened 4 years ago

yeahwu commented 4 years ago

https://starts.sh/posts/caddy_https_proxy.html

利用Caddy的插件forwardproxy快速搭建HTTPS正向代理,毕竟Caddy自动请求SSL证书,能够省下许多不必要的折腾。 申请域名和填写DNS记录首先你要注册一个免费域名,这个可以到Freenom上免费搞一个,不多讲。 域名注册好后,需要添加两条DNS记录,如果没有v6IP的话,就填一个v4IP的A记录,如下:

moosetk commented 3 years ago

可以设置多个用户吗?

yeahwu commented 3 years ago

@moosetk 可以设置多个用户吗?

没研究过多用户,你可以试试下面这种写法:

                        "handle": [
                          {
                            "handler": "forward_proxy",
                            "hide_ip": true,  //隐藏客户端IP
                            "hide_via": true,
                            {
                            "auth_user": "uname", //用户名
                            "auth_pass": "password"  //密码
                            },
                            {
                            "auth_user": "uname",
                            "auth_pass": "password"
                            }
                          }
                        ]
moosetk commented 3 years ago

@yeahwu

@moosetk 可以设置多个用户吗?

没研究过多用户,你可以试试下面这种写法:

                        "handle": [
                          {
                            "handler": "forward_proxy",
                            "hide_ip": true,  //隐藏客户端IP
                            "hide_via": true,
                            {
                            "auth_user": "uname", //用户名
                            "auth_pass": "password"  //密码
                            },
                            {
                            "auth_user": "uname",
                            "auth_pass": "password"
                            }
                          }
                        ]

不可以

wuzhongyi1105 commented 3 years ago

谢谢分享🙏之前我只搞定了前面编译,配置文件看花眼 小内存 VPS 编译用了整整十个小时,人快没了😂

yushiro commented 3 years ago

按照这个教程, caddy也是直接用博主提供的版本,cf配置好以后,访问这个域名一直407错误, 可能是什么原因?

opser-gavin commented 3 years ago

大佬,caddy.json这个文件杂写的,有没教程呀?这个v2版本好难啊感觉,好多之前用的modules也没有了

yeahwu commented 3 years ago

@opser-gavin 大佬,caddy.json这个文件杂写的,有没教程呀?这个v2版本好难啊感觉,好多之前用的modules也没有了

https://caddyserver.com/docs/json/

mexia550663898 commented 3 years ago

感谢你的教程 请问你试过套cdn么

moosetk commented 3 years ago

姥爷,我下载了 arm64 版的caddy,打算在arm机上搭建,结果出错了 说不认识 forward_proxy 模块,这个该怎么解决呢?官网下载的,是不是版本不对?

2021/05/30 06:41:57.695 INFO    using provided configuration    {"config_file": "/etc/caddy/caddy.json", "config_adapter": ""}
2021/05/30 06:41:57.696 WARN    admin   admin endpoint disabled
2021/05/30 06:41:57.697 WARN    tls the 'issuer' field is deprecated and will be removed in the future; use 'issuers' instead; your issuer has been appended automatically for now
2021/05/30 06:41:57.697 INFO    tls.cache.maintenance   started background certificate maintenance  {"cache": "0x40002d6070"}
2021/05/30 06:41:57.697 INFO    http    enabling automatic HTTP->HTTPS redirects    {"server_name": "srv0"}
2021/05/30 06:41:57.697 INFO    tls.cache.maintenance   stopped background certificate maintenance  {"cache": "0x40002d6070"}
run: loading initial config: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module 'forward_proxy': unknown module: http.handlers.forward_proxy
yeahwu commented 3 years ago

@moosetk 姥爷,我下载了 arm64 版的caddy,打算在arm机上搭建,结果出错了 说不认识 forward_proxy 模块,这个该怎么解决呢?官网下载的,是不是版本不对?

2021/05/30 06:41:57.695   INFO    using provided configuration    {"config_file": "/etc/caddy/caddy.json", "config_adapter": ""}
2021/05/30 06:41:57.696   WARN    admin   admin endpoint disabled
2021/05/30 06:41:57.697   WARN    tls the 'issuer' field is deprecated and will be removed in the future; use 'issuers' instead; your issuer has been appended automatically for now
2021/05/30 06:41:57.697   INFO    tls.cache.maintenance   started background certificate maintenance  {"cache": "0x40002d6070"}
2021/05/30 06:41:57.697   INFO    http    enabling automatic HTTP->HTTPS redirects    {"server_name": "srv0"}
2021/05/30 06:41:57.697   INFO    tls.cache.maintenance   stopped background certificate maintenance  {"cache": "0x40002d6070"}
run: loading initial config: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module 'forward_proxy': unknown module: http.handlers.forward_proxy

官方的caddy2没有打入forward_proxy插件,试试下面caddy-arm64版本: https://starts.sh/cloud/docs/caddy-arm64

ghost commented 3 years ago

using provided configuration {"config_file": "/etc/caddy/caddy.json", "config_adapter": ""} run: loading initial config: decoding request body: invalid character '/' looking for beginning of object key string 请问这是什么情况

moosetk commented 3 years ago
run: loading initial config: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module 'forward_proxy': decoding module config: http.handlers.forward_proxy: json: unknown field "auth_pass"
opser-gavin commented 2 years ago

大佬请教下:file_server这块配置 是配置了个file_server服务吗?怎么访问呀,我的代理好用但是不知道杂访问file_server,求指教~~~

briteming commented 2 years ago

hi. 我读了贵文,按照你的配置文件内容,编写了caddy.json, 不过运行/root/caddy run --config /etc/caddy/caddy.json
遇到2次错误,第一次错误得到了caddy的作者的指点,第二次错误也得到他的回复,但这次没看懂,不明白该怎么再次修改caddy.json文件,你可否指点一下?非常感谢。详见https://caddy.community/t/what-does-unknown-field-issuer-mean/16491/3

ajasonwang commented 1 year ago
run: loading initial config: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module 'forward_proxy': decoding module config: http.handlers.forward_proxy: json: unknown field "auth_pass"

遭遇同样的问题,go1.19编译带了插件。./xcaddy build --with github.com/caddyserver/forwardproxy@caddy2 源码提示:// TODO: temporary/deprecated - we should try to reuse existing authentication modules instead! BasicauthUser string json:"auth_user_deprecated,omitempty" BasicauthPass string json:"auth_pass_deprecated,omitempty" 去掉auth_user和auth_pass参数可以正常执行。