---
title: "Deploy Second Port"
description: "Expose a second container port on its own public Railway domain via Caddy"
category: "Other"
url: https://railway.com/deploy/second-port
---

# Deploy Second Port

Expose a second container port on its own public Railway domain via Caddy

**[Deploy Second Port on Railway](https://railway.com/template/second-port)**

- **Creator:** RBR Digital
- **Category:** Other
- **Total deploys:** 1

## Template content

### Second Port https://cdn-icons-png.flaticon.com/512/11152/11152993.png

- **Source:** douglasrubims/railway-second-port
- **Public domain:** Yes

## Documentation

# Deploy and Host Second Port on Railway

Second Port is a lightweight Caddy reverse proxy for Railway. It gives a second container port its own public HTTPS domain while forwarding traffic to the target service over Railway's private network—ideal when one service listens on multiple ports but Railway only exposes one per domain.

## About Hosting Second Port

Deploy Second Port as a separate Railway service alongside the application you want to expose. The proxy listens on port **3000** and forwards all requests to a target hostname and port you configure with `TARGET_DOMAIN` and `TARGET_PORT`. Railway handles TLS on the public domain; Caddy handles reverse proxying over the private network with dynamic DNS resolution, load balancing across replicas, and passive health checks.

Before deploying, ensure your target service listens on a fixed port and binds to **`::`** so it is reachable over Railway private networking. Set reference variables pointing at the target service's `RAILWAY_PRIVATE_DOMAIN` and the port to expose, then assign a public domain to this proxy service with port **3000**. No database or persistent storage is required.

## Common Use Cases

- Exposing an admin UI or internal API on a dedicated public URL while the main app keeps its primary domain
- Publishing a secondary endpoint from multi-process containers (e.g. frontend on one port, backend API on another)
- Giving webhooks, WebSockets, or auxiliary services a separate domain without running a second full deployment

## Dependencies for Second Port Hosting

- A target Railway service running in the **same project and environment**
- The target must bind to **`::`** on the port you want to expose
- `TARGET_DOMAIN` and `TARGET_PORT` configured on this proxy service

### Deployment Dependencies

- [Railway private networking](https://docs.railway.app/guides/private-networking)
- [Railway service variables and reference variables](https://docs.railway.app/guides/variables)
- [Caddy reverse_proxy](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy)
- [Caddy dynamic upstreams](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#dynamic)

### Implementation Details

Configure the proxy service with reference variables to your target:

```
TARGET_DOMAIN=${{MyService.RAILWAY_PRIVATE_DOMAIN}}
TARGET_PORT=8080
```

Or pass both in one variable:

```
TARGET_HOST=${{MyService.RAILWAY_PRIVATE_DOMAIN}}:8080
```

Assign a public domain to this proxy service and set its port to **3000**. Example layout:

- **Main service** — `https://myapp.up.railway.app` → port `3000`
- **Second Port proxy** — `https://myapp-admin.up.railway.app` → port `3000`, forwarding to target port `8080`

## Why Deploy Second Port 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 Second Port 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 Author

Created and maintained by **Douglas Rubim**.

GitHub: https://github.com/douglasrubims

## Similar templates

- [Rocky Linux](https://railway.com/deploy/rocky-linux) — Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀
- [Foundry Virtual Tabletop](https://railway.com/deploy/X5tR6G) — A Self-Hosted & Modern Roleplaying Platform
- [Letta Code Remote](https://railway.com/deploy/letta-code-remote) — Run a Letta Code agent 24/7. No inbound ports, just deploy.

Open this page in a browser: https://railway.com/deploy/second-port
