serverpod
when i use serverpod, its listening to 3 ports, 8081, 8082 and 8080. can i have 8080 on example.com, 8081 on insights.example.com and 8082 on web.example.com? im using google domains
Solution:Jump to solution
I'd recommend caddy, as for a guide, there's nothing railway specific because this isn't all that railway specific
33 Replies
Project ID:
N/A
N/A
unfortunately this is not possible yet, railway only supports exposing one port at a time, you would need to run a proxy service to map routes to these ports across the private network
@Brody do you have link to what i could use to do that or a guide?
Solution
I'd recommend caddy, as for a guide, there's nothing railway specific because this isn't all that railway specific
however if you do run into issues when you go to implement this, I'd be happy to help
@brody192 if you have time i would appriciate any help i can get. i dont really understand how this works and neither do my friends i asked 🙂
i saw you made a caddy-proxy template on railway but idk if i can use that for my problem or how to use it
chatgpt is saying things that dont work
that proxy template would be a good starting point for sure
to do this you would need to familiarize yourself with caddy
should my caddyfile look something like this?
{
admin off persist_config off
auto_https off
log {
format console
} servers {
trusted_proxies static private_ranges } } :{$PORT} { log {
format console
} respond /health 200 root * dist encode gzip file_server try_files {path} /index.html } api.slashdesign.nl { reverse_proxy slash-design.railway.internal:8080 } web.slashdesign.nl { reverse_proxy slash-design.railway.internal:8082 }
admin off persist_config off
auto_https off
log {
format console
} servers {
trusted_proxies static private_ranges } } :{$PORT} { log {
format console
} respond /health 200 root * dist encode gzip file_server try_files {path} /index.html } api.slashdesign.nl { reverse_proxy slash-design.railway.internal:8080 } web.slashdesign.nl { reverse_proxy slash-design.railway.internal:8082 }
you dont want to use tls, railway does tls for you
and you are also missing all the global config from that templates caddyfile
unfortunately i have to run now, I will circle back around to this later, but please keep reading the caddy docs
that explains a lot iguess
kk
lets see your caddyfile?
i updated above
would you mind wrapping all code in triple backticks
its not really code but you get what i mean lol
didnt even know you could do that lol
no worries, i was told the same at one point too
let me see if i can whip something up for you
i got a proof of concept working.
i have two services in my project:
- a proxy service that handles the routing via host matching
- a mock service that listens on port 8000 to 8005 (called hello-world) that returns a simple message containing the port and the host that the incoming request used
https://api.overr.net/ will proxy to the port 8000 on the hello-world service
https://web.overr.net/ will proxy to the port 8001 on the hello-world service
the hello-world service is not exposed publicly in anyway and all proxying is done over the private network
this is the config used for the proxy
https://github.com/brody192/reverse-proxy/blob/host-matching/Caddyfile
you would need to extend the Caddyfile with more named matchers and their accompanying reverse_proxy directives.
i have these service variables set on the proxy service
you would end up also needing more of these external / internal variable pairs
please let me know if you need any more help!
Thnx so much for your clear explanation with example! It really helped with understanding with I need todo and I think I'm starting understand it.
I changed the caddyfile to with I need and added the vars and it's kinda working now but still something wrong, but I don't think the problem is with your file
When I connect my 3 ports from the image above(insights, server, Webserver) no matter in what way I match them I always have the same problem: server(API) works perfectly, webserver points me to 0.0.0.0, and server is stuck on a white screen
I don't think this is a railway problem. But can you maybe give advise on how I can debug this problem?
api.slashdesign.nl
web.slashdesign.nl
insights.slashdesign.nl
@brody192
im here, please dont tag
Ohw sorry
can i see your Caddyfile?
maybe just share the repo?
do you think you could also share your serverpod repo so i can deploy that and try to hook up the proxy myself?
my railway project should also be public, i work on production branch not staging in railway!
before I attempt to run this stuff myself, in your caddyfile I see you're using domain blocks, this will not work, please continue with the named matchers how I had set those two named matchers up
where? your part should have the matchers?
i was testing some things maybe that was what you saw or idk bad timing lol
everything should be good now except web.slashdesign.nl, if you can see my project you should see all is green now and slash-design logs say all are listening
i will leave it for now soo you can look, check you have latest pull
I see this
https://github.com/lazy-demon/reverse-proxy/blob/main/Caddyfile#L46
80 is not a valid host, is this just a placeholder for something?
Yeah that was what I was working on for my client(that will later go too topdomain), it's not working rn but it shouldnt effect the code above for the server
okay so about
web.slashdesign.nl
redirecting you to 0.0.0.0
i dont know all there is to know about caddy, but i know more than enough to know that caddy would not be sending that kind of redirect, this would be something your serverpod app is sending and caddy is just forwarding it through, and i know nothing about serverpod so would you look into any known issues serverpod has when running behind a proxy?
it might be worth giving this a shot
change line 35 of your caddyfile into this
omgggg i fixed it!
i made your change but that didnt work, then i changed some values in my config now its working
in my yaml config file, the api and insights worked when i set to 0.0.0.0 but for the webserver to work a had to put in web.slashdesign.nl that fixed it
hey that's awesome! so all works now?
yes! topdomain and all different types of subdomains(api, webserver) all work now 😄
that's great!