R
Railway•14mo ago
_LazyDemon

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
No description
Solution:
I'd recommend caddy, as for a guide, there's nothing railway specific because this isn't all that railway specific
Jump to solution
33 Replies
Percy
Percy•14mo ago
Project ID: N/A
_LazyDemon
_LazyDemon•14mo ago
N/A
Brody
Brody•14mo ago
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
_LazyDemon
_LazyDemon•14mo ago
@Brody do you have link to what i could use to do that or a guide?
Solution
Brody
Brody•14mo ago
I'd recommend caddy, as for a guide, there's nothing railway specific because this isn't all that railway specific
Brody
Brody•14mo ago
however if you do run into issues when you go to implement this, I'd be happy to help
_LazyDemon
_LazyDemon•14mo ago
@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
Brody
Brody•14mo ago
that proxy template would be a good starting point for sure to do this you would need to familiarize yourself with caddy
_LazyDemon
_LazyDemon•14mo ago
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 }
Brody
Brody•14mo ago
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
_LazyDemon
_LazyDemon•14mo ago
that explains a lot iguess kk
_LazyDemon
_LazyDemon•14mo ago
No description
_LazyDemon
_LazyDemon•14mo ago
No description
Brody
Brody•14mo ago
lets see your caddyfile?
_LazyDemon
_LazyDemon•14mo ago
i updated above
Brody
Brody•14mo ago
would you mind wrapping all code in triple backticks its not really code but you get what i mean lol
_LazyDemon
_LazyDemon•14mo ago
{
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
}
didnt even know you could do that lol
Brody
Brody•14mo ago
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
API_HOST_EXTERNAL=api.overr.net
API_HOST_INTERNAL=${{hello-world.RAILWAY_PRIVATE_DOMAIN}}:8000

WEB_HOST_EXTERNAL=web.overr.net
WEB_HOST_INTERNAL=${{hello-world.RAILWAY_PRIVATE_DOMAIN}}:8001
API_HOST_EXTERNAL=api.overr.net
API_HOST_INTERNAL=${{hello-world.RAILWAY_PRIVATE_DOMAIN}}:8000

WEB_HOST_EXTERNAL=web.overr.net
WEB_HOST_INTERNAL=${{hello-world.RAILWAY_PRIVATE_DOMAIN}}:8001
you would end up also needing more of these external / internal variable pairs please let me know if you need any more help!
_LazyDemon
_LazyDemon•14mo ago
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?
No description
No description
No description
_LazyDemon
_LazyDemon•14mo ago
api.slashdesign.nl web.slashdesign.nl insights.slashdesign.nl @brody192
Brody
Brody•14mo ago
im here, please dont tag
_LazyDemon
_LazyDemon•14mo ago
Ohw sorry
Brody
Brody•14mo ago
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?
_LazyDemon
_LazyDemon•14mo ago
my railway project should also be public, i work on production branch not staging in railway!
Brody
Brody•14mo ago
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
_LazyDemon
_LazyDemon•14mo ago
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
Brody
Brody•14mo ago
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?
_LazyDemon
_LazyDemon•14mo ago
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
Brody
Brody•14mo ago
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
reverse_proxy @web_host http://{$WEB_HOST_INTERNAL} {
header_up Host {upstream_hostport}
}
reverse_proxy @web_host http://{$WEB_HOST_INTERNAL} {
header_up Host {upstream_hostport}
}
_LazyDemon
_LazyDemon•14mo ago
omgggg i fixed it! i made your change but that didnt work, then i changed some values in my config now its working
apiServer:
port: 8000
publicHost: 0.0.0.0
publicPort: 8000
publicScheme: http

# Configuration for the Insights server.
insightsServer:
port: 8001
publicHost: 0.0.0.0
publicPort: 8001
publicScheme: http

# Configuration for the web server.
webServer:
port: 8080
publicHost: web.slashdesign.nl
publicPort: 8080
publicScheme: http
apiServer:
port: 8000
publicHost: 0.0.0.0
publicPort: 8000
publicScheme: http

# Configuration for the Insights server.
insightsServer:
port: 8001
publicHost: 0.0.0.0
publicPort: 8001
publicScheme: http

# Configuration for the web server.
webServer:
port: 8080
publicHost: web.slashdesign.nl
publicPort: 8080
publicScheme: http
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
Brody
Brody•14mo ago
hey that's awesome! so all works now?
_LazyDemon
_LazyDemon•14mo ago
yes! topdomain and all different types of subdomains(api, webserver) all work now 😄
Brody
Brody•14mo ago
that's great!
Want results from more Discord servers?
Add your server