caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
55.71k stars 3.92k forks source link

How to use Caddy2 to reverse-proxy diffirent website? #2944

Closed AP0rPi7uQ9 closed 4 years ago

AP0rPi7uQ9 commented 4 years ago

I have two website written by Golang Gin Framework. I want to do this. When i open abc123.com, i can see localhsot:8080 page. When i open def456.com, i can see localhsot:8081 page.

But in terminal line , i type this two line

$ caddy reverse-proxy --from https://abc123.com --to localhost:8080 $ caddy reverse-proxy --from https://def456.com --to localhost:8081

and return [reverse-proxy: loading new config: http app module: start: tcp: listening on :443: listen tcp :443: bind: address already in use]

Only one website is avalible. WHy? I need help. thanks

mohammed90 commented 4 years ago

Questions are preferred to go to the forum https://caddy.community

To proxy different FQDN to different backends, you need to forget about the CLI and use the JSON config or Caddyfile. You'll find complete example in the wiki here https://github.com/caddyserver/caddy/wiki/v2:-Config-from-Scratch

tobya commented 4 years ago

You can get this up and running very easily with Caddy 1

https://caddyserver.com/v1/docs

AP0rPi7uQ9 commented 4 years ago

Questions are preferred to go to the forum https://caddy.community

To proxy different FQDN to different backends, you need to forget about the CLI and use the JSON config or Caddyfile. You'll find complete example in the wiki here https://github.com/caddyserver/caddy/wiki/v2:-Config-from-Scratch

Thank you very much! you are kind and help me a lot. I'm newbie in github.

But i found a problem.

when i "listen": ["127.0.0.1:80"], i cant open the web in client. But when i use "listen": [":80"], its successful, i can open it.

mohammed90 commented 4 years ago

If you use "listen": ["127.0.0.1:80"] then only clients on the same machine can access the served website. If you need access to the website from an external device, then you can't use "listen": ["127.0.0.1:80"].