How to use a reverse proxy with railway
Note: Yes I know railway offers it's own reverse proxy and load balancing.
I'm trying to set up a reverse proxy to front my services so that they can all "use" the same custom domain. I've got HAProxy set up, however when I try using it I actually end up hitting the railway backboard. Does anyone know how to get by this?
69 Replies
Project ID:
d7c966b3-07dd-4a31-9cb9-82de5002e54f
d7c966b3-07dd-4a31-9cb9-82de5002e54f
It seems that the proxy is resolving the internal IP of my service and attempting to connect to that
Edit: nope nvm I was logging the wrong thing, the ip address is resolved correctly but I'm still hitting railway's backboard
might not be a very useful suggestion, but you could try caddy instead?
https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#examples
https://github.com/alphasecio/caddy-on-railway
Yeah I'll give it a shot
Still the same issue
can i see your caddyfile?
I'll try that
works for me 🤷♂️
Strange it's still not working for me
skill issue
whats the service url of this proxy you are setting up
There isn't one right now, I'm trying to get it working locally first
Bruh
How
used that exact same caddyfile i provided
I am using that exact file and all I get is 404s
whats your start command
PORT=8080 caddy run
Though it doesn't seem to be picking up the port
windows?
ubuntu
well if it works on windows, nows a good time to switch
kidding
but yeah i dont know, on windows i ran "set PORT=3000" then ran "caddy.exe run" and it just worked
I wonder if something is using my 8080
Nope setting other values doesn't do anything
And the reverse proxy still gives 404s on the port caddy auto grabs
i dont think i can help much anymore, i dont have any linux machines to do further testing
No worries, thank you I got it working
I had the caddyfile written as "caddyfile" and not
omg i thought you just didnt care enough to capitalize that word when messaging like i didnt
LMAO
Sorry about that
so i was right tho, skill issue
but glad you got it
Thanks!
no problem!
It looks like caddy is resolving the internal network address when deployed
Causing 502s
I'm sorry I don't know what to tell you, that caddyfile worked for me to proxy to your apps domain
Did it work on railway too?
Yes
I must be missing something
I sent you that testing domain, that was me deploying caddy with that caddyfile to a testing service I have for these types of help requests
I have since removed the deployment tho
No worries, there must be something else
The proxy works running locally
It's just in railway it's resolving the internal IPs for my other services
Is there something in here that sticks out to you?
And that all works locally?
Yeah
Though, one thing that might be the issue
BACKEND_URL and FRONTEND_URL are shared variables from other services
Defined as such
The idea is the services both make a var with the RAILWAY_STATIC_URL value
Use the actual URLs in the caddyfile and see if that works
Your apps are setting environment variables in code?
No, these are set purely from the UI
Each service has a RAILWAY_STATIC_URL variable which I am saving into BACKEND_URL for example, and then sharing that
yeah those variables aren't exported
How can I get them exported?
cant as far as i know
Oh rip
just put the urls in the caddyfile
They won't work for PR environments 😦
pr?
Yeah I have PR environments enabled
i dont do github, i dont know what that is
Ahh okay
It's basically a new environment that gets spun up when I open a pull request
im gonna be honest with you, i think you're overly complicating this
How so?
why must your frontend use one domain?
It makes cors handling and load balancing easier
i dont think i would call this thread easy
Yeah it's not easy, but our current solution is getting dumb lol
We have middleware in each service that uses regex patterns to validate hosts
isnt the browser supposed to validate cors and host stuff?
It also makes it harder to send analytics data since it gets blocked by firewall etc
Yes but it uses preflight requests for that
Those requests have to be handled by the backend
That's where the middleware runs
sounds like youve engineered yourself into a corner
In a way yes
take a step back and reevaluate this all?
Yeah this is starting to become more trouble than we thought it'd be
i wish you good luck
Thanks!
Just came to say I was trying to use nginx for a reverse proxy as well for a similar use case. Ended up trying out caddy and it worked on the first try. Many thanks!
glad my old help is still usefull 🙂