
Reverse Proxy
Unite your frontend & backend into one domain
Caddy Proxy
railwayapp-templates/caddy-reverse-proxy
Just deployed
Deploy and Host Caddy Reverse Proxy on Railway
Caddy is a powerful, enterprise-ready, open source web server that can combine your separate frontend and backend services into one domain. This template configures Caddy as a reverse proxy to route traffic between your services seamlessly.
About Hosting Caddy Reverse Proxy
Hosting a Caddy reverse proxy involves deploying a web server that routes incoming requests to different backend services based on URL patterns. This allows you to access your frontend from /*
and your backend from /api/*
on the same domain, eliminating CORS issues and simplifying your application architecture. Caddy handles automatic HTTPS, compression, and load balancing while providing a clean configuration through the Caddyfile format.
Common Use Cases
- Single Domain Applications: Combine separate frontend and backend services under one domain to avoid CORS issues and simplify client-side API calls
- Microservice Routing: Route different URL paths to various microservices while maintaining a unified entry point for your application
- Development and Staging: Create consistent environments where frontend and backend services work together seamlessly across different deployment stages
- Legacy System Integration: Bridge modern frontend applications with existing backend APIs by providing a unified interface and handling protocol differences
Dependencies for Caddy Reverse Proxy Hosting
- Caddy Web Server: Core Caddy binary for reverse proxy functionality and configuration management
- Target Services: Frontend and backend services that need to be accessible through fixed ports and IPv6 compatibility
Deployment Dependencies
Implementation Details
Example Configuration:
Access your services on the same domain:
- Frontend: https://yourdomain.com/
- Backend: https://yourdomain.com/api/
Required Environment Variables:
When deploying your reverse proxy service, you'll need to configure four service variables using Railway's reference variables:
FRONTEND_DOMAIN=${{Frontend.RAILWAY_PRIVATE_DOMAIN}}
FRONTEND_PORT=${{Frontend.PORT}}
BACKEND_DOMAIN=${{Backend.RAILWAY_PRIVATE_DOMAIN}}
BACKEND_PORT=${{Backend.PORT}}
Sample Caddyfile Configuration:
{
auto_https off
}
:$PORT {
# Route API requests to backend
handle /api/* {
reverse_proxy {$BACKEND_DOMAIN}:{$BACKEND_PORT}
}
# Route all other requests to frontend
handle {
reverse_proxy {$FRONTEND_DOMAIN}:{$FRONTEND_PORT}
}
}
Prerequisites for Target Services:
Both frontend and backend services need to meet these requirements:
- Fixed Ports: Configure services to listen on fixed ports by setting a
PORT
environment variable - IPv6 Compatibility: Services must listen on
::
(all interfaces) since Railway's internal network is IPv6 only
Framework-Specific Start Commands:
# Gunicorn (Python)
gunicorn main:app -b [::]:${PORT:-3000}
# Uvicorn (Python)
uvicorn main:app --host :: --port ${PORT:-3000}
# Hypercorn (Python) - Recommended over Uvicorn for dual-stack support
hypercorn main:app --bind [::]:${PORT:-3000}
# Next.js (Node.js)
next start -H :: --port ${PORT:-3000}
# Express/Nest (Node.js)
app.listen(process.env.PORT || 3000, "::");
Important Notes:
- Set fixed
PORT
variables in both frontend and backend services before deploying the reverse proxy - Uvicorn doesn't support dual-stack binding from CLI; consider using Hypercorn instead for better compatibility
- The proxy utilizes Railway's private network for communication between services
Advanced Features:
- Load Balancing: Distribute traffic across multiple backend instances
- Health Checks: Monitor backend service availability
- Rate Limiting: Control request rates to protect backend services
- Request/Response Modification: Transform headers and content as needed
View the example public project that demonstrates sleeping frontend and backend services with wake via the private network.
Why Deploy Caddy Reverse Proxy on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Caddy Reverse Proxy on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
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}}