1. Caddy version (caddy version
):
v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=
2. How I run Caddy:
systemd
a. System environment:
systemd
b. Command:
Paste command here.
c. Service/unit/compose file:
Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.
d. My complete Caddyfile or JSON config:
I don’t need to post the full config, just this part, where the first one is not working, but the second one is:
route /liveview/snapshotjson/* {
uri strip_prefix /liveview
reverse_proxy * http://localhost:3004 {
import SecurityHeaders
}
}
route /liveview/* {
uri replace /liveview /socket.io
reverse_proxy * http://localhost:3004 {
import SecurityHeaders
}
}
3. The problem I’m having:
I am using JavaScript with express as the server and socket.io as the websocket. In this case, the web server and socket are sharing the same port.
In the development environment, I cannot use port 80, so I am using port 3020. And, the dev environment uses a proxy server to manage the reverse proxy.
It looks like this and works properly for both paths:
'/liveview/snapshotjson': {
target: 'http://localhost:3004',
pathRewrite: { '^/liveview/': '/' },
secure: false,
changeOrigin: true,
ws: false
},
'/liveview': {
target: 'ws://localhost:3004',
secure: false,
changeOrigin: true,
ws: true
},
My goal is to get Caddy to do the same thing. I obviously have it wrong, because on the browser URL, I can put http://localhost/liveview/snapshotjson?camera_id=1&overlay=1
and the result is {"code":0,"message":"Transport unknown"}
which is coming from socket.io
However, if I do this http://localhost:3020/liveview/snapshotjson?camera_id=1&overlay=1
while running the dev environment, then that proxy server is working because it serves up an image.
Notice above that the targets are different for the two different paths as they specify a different protocol.
Also, if I do this from the browser url, it also works: http://localhost:3004/snapshotjson?camera_id=1&overlay=1
But, I need the reverse proxy to work as the ports will be locked down from being accessed externally.
4. Error messages and/or full log output:
This is what I get in the browser:
GET http://localhost/liveview/snapshotjson?camera_id=1&overlay=1 400 (Bad Request)
5. What I already tried:
I have tried both uri strip_prefix
and uri replace
to no avail.