R
Railway2y ago
Shah

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
Percy
Percy2y ago
Project ID: d7c966b3-07dd-4a31-9cb9-82de5002e54f
Shah
Shah2y ago
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
Brody
Brody2y ago
Shah
Shah2y ago
Yeah I'll give it a shot Still the same issue
Brody
Brody2y ago
can i see your caddyfile?
Shah
Shah2y ago
Brody
Brody2y ago
https://testing-service.up.railway.app/
{
auto_https off
}

:{$PORT}

reverse_proxy https://frontend-dev-9cb6.up.railway.app {
header_up Host {upstream_hostport}
}
{
auto_https off
}

:{$PORT}

reverse_proxy https://frontend-dev-9cb6.up.railway.app {
header_up Host {upstream_hostport}
}
Shah
Shah2y ago
I'll try that
Brody
Brody2y ago
works for me 🤷‍♂️
Shah
Shah2y ago
Strange it's still not working for me
Brody
Brody2y ago
skill issue whats the service url of this proxy you are setting up
Shah
Shah2y ago
There isn't one right now, I'm trying to get it working locally first
Brody
Brody2y ago
Shah
Shah2y ago
Bruh How
Brody
Brody2y ago
used that exact same caddyfile i provided
Shah
Shah2y ago
I am using that exact file and all I get is 404s
Brody
Brody2y ago
whats your start command
Shah
Shah2y ago
PORT=8080 caddy run Though it doesn't seem to be picking up the port
Brody
Brody2y ago
windows?
Shah
Shah2y ago
ubuntu
Brody
Brody2y ago
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
Shah
Shah2y ago
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
Brody
Brody2y ago
i dont think i can help much anymore, i dont have any linux machines to do further testing
Shah
Shah2y ago
No worries, thank you peepoLove2 I got it working I had the caddyfile written as "caddyfile" and not dead
Brody
Brody2y ago
omg i thought you just didnt care enough to capitalize that word when messaging like i didnt
Shah
Shah2y ago
LMAO Sorry about that
Brody
Brody2y ago
so i was right tho, skill issue but glad you got it
Shah
Shah2y ago
Thanks!
Brody
Brody2y ago
no problem!
Shah
Shah2y ago
It looks like caddy is resolving the internal network address when deployed Causing 502s
Brody
Brody2y ago
I'm sorry I don't know what to tell you, that caddyfile worked for me to proxy to your apps domain
Shah
Shah2y ago
Did it work on railway too?
Brody
Brody2y ago
Yes
Shah
Shah2y ago
I must be missing something
Brody
Brody2y ago
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
Shah
Shah2y ago
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?
Shah
Shah2y ago
Brody
Brody2y ago
And that all works locally?
Shah
Shah2y ago
Yeah Though, one thing that might be the issue BACKEND_URL and FRONTEND_URL are shared variables from other services Defined as such
Shah
Shah2y ago
Shah
Shah2y ago
The idea is the services both make a var with the RAILWAY_STATIC_URL value
Brody
Brody2y ago
Use the actual URLs in the caddyfile and see if that works Your apps are setting environment variables in code?
Shah
Shah2y ago
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
Brody
Brody2y ago
yeah those variables aren't exported
Shah
Shah2y ago
How can I get them exported?
Brody
Brody2y ago
cant as far as i know
Shah
Shah2y ago
Oh rip
Brody
Brody2y ago
just put the urls in the caddyfile
Shah
Shah2y ago
They won't work for PR environments 😦
Brody
Brody2y ago
pr?
Shah
Shah2y ago
Yeah I have PR environments enabled
Brody
Brody2y ago
i dont do github, i dont know what that is
Shah
Shah2y ago
Ahh okay It's basically a new environment that gets spun up when I open a pull request
Brody
Brody2y ago
im gonna be honest with you, i think you're overly complicating this
Shah
Shah2y ago
How so?
Brody
Brody2y ago
why must your frontend use one domain?
Shah
Shah2y ago
It makes cors handling and load balancing easier
Brody
Brody2y ago
i dont think i would call this thread easy
Shah
Shah2y ago
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
Brody
Brody2y ago
isnt the browser supposed to validate cors and host stuff?
Shah
Shah2y ago
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
Brody
Brody2y ago
sounds like youve engineered yourself into a corner
Shah
Shah2y ago
In a way yes
Brody
Brody2y ago
take a step back and reevaluate this all?
Shah
Shah2y ago
Yeah this is starting to become more trouble than we thought it'd be
Brody
Brody2y ago
i wish you good luck
Shah
Shah2y ago
Thanks!
Amrit
Amrit2y ago
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!
Brody
Brody2y ago
glad my old help is still usefull 🙂
Want results from more Discord servers?
Add your server