A problem about caddy2 reverse proxy

1. Caddy version (caddy version):

2.0.0

2. How I run Caddy:

caddy start

a. System environment:

Debian sid

b. Command:



c. Service/unit/compose file:

[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-abnormal

Type=forking
User=www-data
Group=www-data
WorkingDirectory=/etc/caddy
ExecStart=/usr/bin/caddy start

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

This is my caddyfile of caddy1.

example.com {
    proxy / 127.0.0.1:8080{
        transparent
    }
    proxy /ray 127.0.0.1:10000 {
      websocket
      header_upstream -Origin
    }
}

I tried following config file but it didn’t work.

example.com 
   reverse_proxy  localhost:8080
   reverse_proxy /ray/*  localhost:10000

3. The problem I’m having:

How can I use caddy2 to do it?
“/” to :8080 but “/ray” to :10000

4. Error messages and/or full log output:

5. What I already tried:

Google Search and read document.

6. Links to relevant resources:

Can you explain what exactly you’re having trouble with? That config looks pretty correct to me. What’s not working? What behaviour are you seeing? Anything in the logs?

Also, have you see the service file we provide for Caddy v2? I think you might still be using the one you were using for Caddy v1.

Thanks.
But I have a problem of Caddyfile, not daemon.I created it and works fine.

That’s nowhere near enough information. You need to elaborate! What’s the problem exactly?

Are you testing with https://example.com/ray, og https://example.com/ray/something in the browser?

Where do you get an error? And what does the error say?

Vegard

You can try the same with nested directives for the host then the reverse_proxy using handle :

localhost {

  file_server

  handle /ray/* {
    reverse_proxy localhost:10000
  }

  handle {
    reverse_proxy localhost:8080
  }
} 

I think it’s a start :slight_smile:.

Alex

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