1. The problem I’m having:
I am not sure if my caddy.json configuration is set up correctly for a UDP & TCP reverse proxy use case. I think my caddy.json must be incorrect, but I’m not sure how to fix. The documentation is not quite there yet for the layer4 app, but I imagine it must be very similar to the http json… which I find quite confusing TBH…
I have two virtualbox VMs running on my windows computer. One is running game server software (Enshrouded) and the other is running Caddy. I am able to connect to my game server through my windows steam client at 10.0.0.27:15637 and 10.0.0.27:15636 (the game uses two ports), but I am not able to reach the game server through the Caddy reverse proxy (10.0.0.29). I am able to get Caddy responses from my “hello world” and my admin api.
Please help me configure caddy correctly!
Diagram of my setup. Red = failure; green = success
2. Error messages and/or full log output:
Started caddy.service.
{"level":"info","ts":1709160833.3655574,"msg":"using provided configuration","config_file":"/etc/caddy/caddy.json","config_adapter":""}
{"level":"info","ts":1709160833.3666823,"logger":"admin","msg":"admin endpoint started","address":":2020","enforce_origin":false,"origins":["//:2020"]}
{"level":"warn","ts":1709160833.3667228,"logger":"admin","msg":"admin endpoint on open interface; host checking disabled","address":":2020"}
{"level":"info","ts":1709160833.367122,"logger":"http.log","msg":"server running","name":"hello_world","protocols":["h1","h2","h3"]}
{"level":"info","ts":1709160833.3679407,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000288a00"}
{"level":"info","ts":1709160833.3683507,"msg":"autosaved config (load with --resume flag)","file":"/etc/caddy/.config/caddy/autosave.json"}
{"level":"info","ts":1709160833.368376,"msg":"serving initial configuration"}
{"level":"warn","ts":1709160833.3695774,"logger":"tls","msg":"storage cleaning happened too recently; skipping for now","storage":"FileStorage:/etc/caddy/storage","instance":"b530c8bc-a031-4928-b8e6-81c2e1ec89d7","try_again":1709247233.3695767,"try_again_in":86399.999999825}
{"level":"info","ts":1709160833.369609,"logger":"tls","msg":"finished cleaning storage units"}
3. Caddy version:
v2.7.6 h1:w0NymbG2m9PcvKWsrX06EEkY9Ru4FJK8uQbYcev1p3A=
4. How I installed and ran Caddy:
This is on Nixos 23.11 on a virtualbox vm running in bridged networking mode.
a. System environment:
I ran this to create a caddy executable
xcaddy build --output /etc/caddy --with github.com/mholt/caddy-l4
And then set my configuration.nix is as follows:
{ config, lib, pkgs, ... };
{
imports =
[
./hardware-configuration.nix
];
system.stateVersion = "23.11";
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
networking.hostName = "caddy-vm";
systemd.services.caddy = {
enable = true;
wanetdBy = [ "multi-user.target" ];
after = [ "networking.target" ];
serviceConfig = {
ExecStart = "/etc/caddy/caddy run --config /etc/caddy/caddy.json";
Restart = "on-failure";
};
};
environment.systemPackages = [
pkgs.xcaddy
pkgs.go
];
networking.firewall.enable = false;
}
b. Command:
systemctl start caddy
And I get the same behavior if I directly run
/etc/caddy/caddy run --config /etc/caddy/caddy.json
c. Service/unit/compose file:
n/a
d. My complete Caddy config:
{
"admin": {
"listen": ":2020"
},
"storage": {
"module": "file_system",
"root": "/etc/caddy/storage"
},
"apps": {
"http": {
"servers": {
"hello_world": {
"listen": [":8080"],
"routes": [
{
"handle": [
{
"body": "Hello, World!",
"handler": "static_response"
}
]
}
]
}
}
},
"layer4": {
"servers": {
"game_tcp": {
"listen": [":15637"],
"routes": [
{
"handle": [
{
"handler": "proxy",
"proxy_protocol": "v1",
"upstreams": [
{"dial": ["10.0.0.27:25637"]}
]
}
]
}
]
},
"game_udp": {
"listen": [":15636"],
"routes": [
{
"handle": [
{
"handler": "proxy",
"proxy_protocol": "v2",
"upstreams": [
{"dial": ["10.0.0.27:25636"]}
]
}
]
}
]
}
}
}
}
}