Trying use reverse-proxy using Caddy template

glorko
PRO

a year ago

Hi everyone!

I have FE on Node and BE on Java

I'm trying to use Caddy template as reverse proxy - in Caddy variables I hardcoded internal urls for both FE and BE services, and ports set in variables of both

It doesn't work I have timeouts both for FE and /api BE, could anyone share settings that I can use? I feel something wrong with my variables settings in FE and BE components, can I copy someone's settings? Doc won't help, I don't understand where to take variables proposed to use from - I just hardcode internal URL and PORT

Solved

18 Replies

a year ago

Please never hard code urls as that can only lead to issues.


glorko
PRO

a year ago

can I see variables setup example for FE and BE that may be used for me to not try to hardcode urls to try to make it work at least somehow?


a year ago

Of course! the template overview contains examples and explanations - https://railway.app/template/7uDSyj


glorko
PRO

a year ago

Okay I tried to use variables - seems like it's taking it properly (required for me to rename all services), now I can access BE via /api, but FE still returning 502 dial tcp [fd12:eb49:f64::77:6dd6:aa39]:3000: connect: connection refused
How can I check what part my FE uses?


a year ago

What port do you have it listening on?


Status changed to Awaiting User Response christian about 1 year ago


glorko
PRO

a year ago

Okay seems like I fixed all issues with port.

My fe app is made with create-react-app, so it's runned by scripts:
"scripts": {
"start": "react-scripts start",
"build": "CI=false react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},

start runned on Railway CI

I parametrized my FE app to try to resolve issues with host and port:
.env
REACT_APP_API_URL=process.env.API_URL
REACT_APP_PORT=process.env.PORT
REACT_APP_HOST=::

With my current configuration BE is available via /api. but when I try to access root url it redirects me to some ip address with port 80 and browser shows ERR_SSL_PROTOCOL_ERROR

Should I make some additional settings on my FE app to properly listen ipv6 and not be redirected? In logs of Caddy all okay - reuqest is handled


Status changed to Awaiting Railway Response railway 12 months ago


glorko
PRO

a year ago

GET on root url gives 301 Moved Permanently


a year ago

react-scripts start

This starts a development server, this is a far bigger issue than listening on IPv6.

I put together a create-react-app starter that runs a production ready web server - https://github.com/brody192/create-react-app-starter

Copy the nixpacks.toml and Caddyfile from this repo into your frontend project folder.


glorko
PRO

a year ago

Brody, could you elaborate how development server is making my FE application not available in this particular configuration? It's non production environment of my app


a year ago

Development servers are only meant to be used in a local development environment, you stick it in a production environment such as Railway (regardless of your intended use) things just don't work correctly, aside from the massive memory usage you would pay for with a development server.


glorko
PRO

a year ago

Brody, I applied your configuration from https://github.com/brody192/create-react-app-starter

Accroding to logs now my FE app is driven by Caddy, but still behavior is the same - I have redirect to IP address

I googled similar behavior and solution was about tls_ondemand
https://caddy.community/t/reverse-proxy-is-changing-url-with-a-301-status/14828/3

Can you help me extend current configuration with that option? Should I change caddyfile in FE or I should modify reverse proxy config somehow?


a year ago

You wouldn't want to do anything with TLS as that's something Railway handles for you.

Are you using the internal domain for the proxy configuration?


glorko
PRO

a year ago

Yes!


a year ago

Looks good, can you send me a link to where I can experience this redirect?


glorko
PRO

a year ago

https://enot-admin-dev.up.railway.app/

Is there any chance it's cached response because of my previous misconfigurations?


a year ago

Cache from your browser, yes, because I am not seeing any redirect, just getting a basic auth login prompt.


glorko
PRO

a year ago

Wow it started work after resetting the browser cache! Brody thank you so much it was a life saver (and memory saver it eats 20 mb instead of 1000 now hahhahaha)


a year ago

No problem, and yeah for sure you never want to be running development servers on Railway even if memory isn't a concern.


Status changed to Solved brody 12 months ago


Trying use reverse-proxy using Caddy template - Railway Help Station