How to create a websocket proxy?

:9999 {
reverse_proxy ws://121.40.165.18:8800
}
ws://121.40.165.18:8800 is a websocket test site that can be accessed
It is inaccessible after proxying, and it seems that port 9999 does not respond to the handshake information.
Why?
my caddy is v2 for lastver is today

The proxy scheme should be http:// (which is the default, so you can remove the scheme altogether) – websockets are just an HTTP upgrade.

:9999 {
reverse_proxy http://121.40.165.18:8800
}
is error too

no man sky?

How is it an error? What is failing? The logs don’t seem to print anything error related. Was the client not able to connect? What does its logs say? Add the following to the top of the Caddyfile:

{
    debug
}
2 Likes

:9999 {
debug
log
reverse_proxy 121.40.165.18:8800
}

2022/09/24 04:07:25.024 e[34mINFOe[0m using adjacent Caddyfile
2022/09/24 04:07:25.027 e[33mWARNe[0m Caddyfile input is not formatted; run the ‘caddy fmt’ command to fix inconsistencies {“adapter”: “caddyfile”, “file”: “Caddyfile”, “line”: 2}
2022/09/24 04:07:25.038 e[34mINFOe[0m admin admin endpoint started {“address”: “localhost:2019”, “enforce_origin”: false, “origins”: [“//localhost:2019”, “//[::1]:2019”, “//127.0.0.1:2019”]}
2022/09/24 04:07:25.038 e[34mINFOe[0m tls.cache.maintenance started background certificate maintenance {“cache”: “0xc000641f80”}
2022/09/24 04:07:25.039 e[34mINFOe[0m tls cleaning storage unit {“description”: “FileStorage:C:\Users\Administrator\AppData\Roaming\Caddy”}
2022/09/24 04:07:25.039 e[34mINFOe[0m http.log server running {“name”: “srv0”, “protocols”: [“h1”, “h2”, “h3”]}
2022/09/24 04:07:25.043 e[34mINFOe[0m tls finished cleaning storage units
2022/09/24 04:07:25.040 e[34mINFOe[0m autosaved config (load with --resume flag) {“file”: “C:\Users\Administrator\AppData\Roaming\Caddy\autosave.json”}
2022/09/24 04:07:25.044 e[34mINFOe[0m serving initial configuration
2022/09/24 04:07:26.946 e[34mINFOe[0m shutting down {“signal”: “SIGINT”}
2022/09/24 04:07:26.947 e[33mWARNe[0m exiting; byeee!! :wave: {“signal”: “SIGINT”}
2022/09/24 04:07:26.949 e[34mINFOe[0m tls.cache.maintenance stopped background certificate maintenance {“cache”: “0xc000641f80”}
2022/09/24 04:07:26.950 e[34mINFOe[0m admin stopped previous server {“address”: “localhost:2019”}
2022/09/24 04:07:26.951 e[34mINFOe[0m shutdown complete {“signal”: “SIGINT”, “exit_code”: 0}

D:\C>caddy fmt
*:9999 {
debug
log
reverse_proxy 121.40.165.18:8800
}

D:\C>caddy run
2022/09/24 04:10:32.849 e[34mINFOe[0m using adjacent Caddyfile
Error: adapting config using caddyfile: Caddyfile:2: unrecognized directive: debug

Can anyone give a complete sample?

D:\C>caddy fmt
*:9999 {
debug
log
reverse_proxy 121.40.165.18:8800
}

D:\C>caddy run
2022/09/24 04:10:32.849 e[34mINFOe[0m using adjacent Caddyfile
Error: adapting config using caddyfile: Caddyfile:2: unrecognized directive: debug

debug is a global option and can’t be placed in a site-block.
Instead, place it into the Global options (Caddyfile) — Caddy Documentation

{
	debug
}

:9999 {
	log
	reverse_proxy 121.40.165.18:8800
}

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.