All Templates / Starters
Reverse Proxy
Unite your frontend & backend into one domain
Caddy Proxy
railwayapp-templates/caddy-reverse-proxy
Just deployed
Combine your separate frontend and backend services into one domain!
Access the frontend from /*
and access the backend from /api/*
on the same domain
Frontend - Vue 3: https://mysite.up.railway.app/
Backend - Go Mux: https://mysite.up.railway.app/api/
The proxy configurations are done in the Caddyfile
everything is commented for your ease of use!
When deploying your Reverse Proxy service it will require you to set two service variables: FRONTEND_HOST and BACKEND_HOST
Note: You will first need to have set a fixed PORT
variable in both the frontend and backend services before deploying this template
These are the two template variables that you will be required to fill out during the first deployment of this service, replace the respective and
with the service names as they appear in the Railway project view
FRONTEND_HOST = ${{Frontend Service Name.RAILWAY_PRIVATE_DOMAIN}}:${{Frontend Service Name.PORT}}
BACKEND_HOST = ${{Backend Service Name.RAILWAY_PRIVATE_DOMAIN}}:${{Backend Service Name.PORT}}
Relevant Caddy documentation:
Some prerequisites to help with common issues that could arise:
Both the frontend and backend need to listen on fixed ports, in my Caddyfile I have used port 3000
in the proxy address, and configured my frontend and backend to both listen on port 3000
$PORT
environment variable, then setting a PORT
service variable to 3000
Since Railway's internal network is IPv6 only the frontend and backend apps will need to listen on ::
(all interfaces - both IPv4 and IPv6)
Start commands for some popular frameworks:
Gunicorn: gunicorn main:app -b [::]:$PORT
Uvicorn: uvicorn main:app --host :: --port $PORT
Hypercorn: hypercorn main:app --bind [::]:$PORT
Next: next start -H :: --port $PORT
Express/Nest: app.listen(process.env.PORT, "::");
Template Content
Caddy Proxy
railwayapp-templates/caddy-reverse-proxyDetails
Created on Jul 26, 2023
193 total projects
96 active projects
76% success on recent deploys
Dockerfile
Starters
More templates in this category
TanStack + React Starter
A barebones TypeScript React starter with TanStack Router & Query setup
Kyle Gill
14