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 four service variables: FRONTEND_DOMAIN / FRONTEND_PORT and BACKEND_DOMAIN / BACKEND_PORT
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 four template variables that you will be required to fill out during the first deployment of this service, it is highly recommended to use reference variables.
Example:
FRONTEND_DOMAIN=${{Frontend.RAILWAY_PRIVATE_DOMAIN}}
FRONTEND_PORT=${{Frontend.PORT}}
BACKEND_DOMAIN=${{Backend.RAILWAY_PRIVATE_DOMAIN}}
BACKEND_PORT=${{Backend.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 example project I have 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:-3000}
Uvicorn: uvicorn main:app --host :: --port ${PORT:-3000}
Hypercorn: hypercorn main:app --bind [::]:${PORT:-3000}
Next: next start -H :: --port ${PORT:-3000}
Express/Nest: app.listen(process.env.PORT || 3000, "::");
Template Content
Caddy Proxy
railwayapp-templates/caddy-reverse-proxyBACKEND_PORT
The backend's internal port
Use variable references, eg. ${{Backend.PORT}}
FRONTEND_PORT
The frontend's internal port
Use variable references, eg. ${{Frontend.PORT}}
BACKEND_DOMAIN
The backend's private domain
Use variable references, eg. ${{Backend.RAILWAY_PRIVATE_DOMAIN}}
FRONTEND_DOMAIN
The frontend's private domain
Use variable references, eg. ${{Frontend.RAILWAY_PRIVATE_DOMAIN}}
Details
Brody
Created on Jul 26, 2023
276 total projects
129 active projects
96% success on recent deploys
Shell, Dockerfile
Starters
More templates in this category
Django Monolith
A Django app connected to a Postgres database with Celery and Celery Beat.
Odogwu Machalla's Projects
37