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

Proxying Redis #173

Open
mbuckbee opened this issue Jan 10, 2024 · 2 comments
Open

Proxying Redis #173

mbuckbee opened this issue Jan 10, 2024 · 2 comments

Comments

@mbuckbee
Copy link

I was experimenting with proxying Redis connections for an app that I run. I have an existing HA Proxy setup that works and attempted to port the config over to L4 as I'm using Caddy already for HTTP and it would be fantastic to have all this in a single app.

For reference here is the HA Proxy config:

defaults REDIS
 mode tcp
 timeout connect  4s
 timeout server  30s
 timeout client  30s
frontend ft_redis
 bind 0.0.0.0:6379 name redisv4
 bind :::6379 name redisv6
 default_backend bk_redis
backend bk_redis
 timeout client 360s
 timeout server 360s
 server upstash_redis INTERNAL_REDIS_HOST:6379 check inter 1s

and here is my L4 config

{
  "logging": {
    "logs": {
      "default": {
        "level": "DEBUG"
      }
    }
  },
	"apps": {
    "layer4": {
      "servers": {
        "redis": {
          "listen": ["0.0.0.0:6379"],
          "routes": [
            {
              "handle": [
                {
                  "handler": "proxy",     
                  "proxy_protocol": "v1",             
                  "upstreams": [
                    {"dial": ["INTERNAL-REDIS-HOST:6379"]}
                  ]
                }
              ]
            }
          ]
        }
      }
    }
	}
}

This was being deployed to Fly.io, and I'm not sure if I was botching up the handler or proxy config. Any help is appreciated.

@francislavoie
Copy link
Collaborator

Are you sure redis supports proxy protocol? Remove that if you're not sure.

@divyam234
Copy link

divyam234 commented Oct 19, 2024

{
    servers {
        listener_wrappers {
            layer4 {
                @redis regexp ^[+\-$:_#,!=\(\*\%\~\|\>]$ 1
                route @redis {
                    proxy redis:6379
                }
                route
            }
            tls
        }
    }
}

This is working for me for redis it matches first byte of RESP protocol which redis uses.For redis you can use tls sni matching also.

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