10 months ago
I'm trying to set up a reverse proxy to two different web services I have running in Railway (same project). It's going to be very simple (linking to two different services) but is starting extremely simple (linking to a single service).
Here is my nginx.conf.
server {
listen 80;
server_name reverse-proxy-beta.up.railway.app;
location / {
proxy_pass http://docs/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}I'm using the internal networking name for the service in this example, but I've also tried the externally available https URL that works if I visit it directly.
For completeness, my Dockerfile:
FROM nginx:alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]Project ID: 12fe90d4-42ca-4704-980b-e16da59696c0
25 Replies
10 months ago
What if you used caddy instead?
10 months ago
there's a ready to deploy template for it
https://railway.com/template/7uDSyj
So I gave it 8080 for both the frontend and backend domains and the private networking names for each (docs and web).
I don't think it's working. If navigate to the new domain (caddy-proxy-beta.up.railway.app), I get a blank page. If I try navigating to /docs or /web, I get a blank page on those as well
10 months ago
yeah you'd want to use caddy here, nginx will cache the DNS for it's lifetime and that's a problem because the DNS will change every time you redeploy the upstream
Still struggling with Caddy. Since I had no luck with the template, I tried setting one up with Docker. Here's my Caddyfile.
{
admin off
auto_https off
}
reverse-proxy-beta.up.railway.app {
encode gzip
# Handle /docs path
handle /docs* {
uri strip_prefix /docs
reverse_proxy docs:8080
}
# Handle root path
handle /* {
reverse_proxy web:8080
}
}When I try to visit https://reverse-proxy-beta.up.railway.app/wizard, which is a path in the web service, I get a Railway "application failed to respond" page. Checking the web service's logs, I see no traffic. It does say it's listening on 8080.
(I have never even heard of Caddy today, so I'm probably doing something obviously incorrect!)
If I omit auto_https off, then Caddy complains about not being able to get a certificate. I figured that, since Railway takes care of that, I should turn it off
10 months ago
is the web service listening on IPv6?
It's an astro site I deployed using the Railway guide.
Here's from the deploy logs:23:58:49 [@astrojs/node] Server listening on local: http://localhost:8080 network: http://10.250.19.9:8080
IIRC localhost can be IPv6?
10 months ago
nope, but localhost is generally not ipv6
Hmm, so I ran npm run build, then npm run start. From what I can see, it's using the same entrypoint as shown in the doc I linked.
I'm able to see the site if I navigate to http://[::1]:4321
I'm also able to curl -6 [http://localhost:4321](http://localhost:4321)
10 months ago
how familiar are you with the dev tools of your browser?
Reasonably familiar, but I give up, lol. I'm just going to use a subdomain
10 months ago
subdomains are a good choice
10 months ago
easy work!
10 months ago
no problem!
10 months ago
!s
Status changed to Solved brody • 11 months ago