|Docs

Deploy Caddy

deploymentfrontendcaddyproxy

Caddy is a powerful, extensible, open-source web server written in Go. It is best known for its automatic HTTPS capabilities, simple configuration via the Caddyfile, and a rich plugin ecosystem.

Whether you need a static file server, a reverse proxy, or a custom build with additional modules, Railway is a great way to deploy Caddy. Railway's platform is an effortless way to deploy Caddy with plugins, without needing to build it yourself.

First, this guide will show you how to deploy Caddy in a way of your choosing. Then, you will learn how to customize the deployment to your needs.

Deploying Caddy

Choose one of these ways to deploy Caddy on Railway:

  1. One-click deploy from a template.
  2. Deploy using the CLI.

One-click deploy from a template

The fastest way to get Caddy running on Railway is to use the official template.

Click the button below to begin:

Deploy on Railway

On the deployment screen, click Deploy Now. If you'd like to include any Caddy plugins at this stage, click Configure and enter the Go module paths of the plugins you want, separated by spaces, in the CADDY_PLUGINS variable, for example:

You can browse the list of known, available plugins on the Caddy Download page. Once you're happy with the configuration, click Save Config, then click Deploy.

After deployment finishes, click the generated URL in your project to visit your new Caddy server. You should see a welcome page confirming it is live.

It is highly recommended that you eject from the template after deployment to create a copy of the repo on your GitHub account so you can customize the configuration.

Deploy from the CLI

  1. Install the Railway CLI:

  2. Clone the template repository:

  3. Initialize a Railway Project:

    • Run the command below in your Caddy project directory.
    • Follow the prompts to name your project.
    • After the project is created, click the provided link to view it in your browser.
  4. Deploy the Application:

    • Run railway up to deploy your app.
      • This command will scan, compress, and upload your app's files to Railway. You'll see real-time deployment logs in your terminal.
    • Once the deployment is complete, proceed to generate a domain for the app service.
  5. Set Up a Public URL:

    • Run railway domain to generate a public URL for your app.
    • Visit the new URL to see your app live in action!

Customize the deployment

Once deployed, there are two main ways you'll want to customize your Caddy service: changing the configuration and adding/removing plugins.

Changing the configuration is done by committing changes of the Caddyfile to your repository and pushing. Learn how to write a Caddyfile.

Adding and removing plugins is done by changing the CADDY_PLUGINS variable in your Railway project, then redeploying.

The following sections describe some common ways Caddy is configured on Railway.

Serving a static site

Place your HTML, CSS, and other static assets in the www directory of your repository. The initial Caddyfile already points Caddy's file_server at /www, so simply committing your files and pushing will redeploy with your content served. There may be no need to change your Caddyfile, as long as it contains something like the following:

Using Caddy as a reverse proxy

Caddy is often used to proxy to other services in Railway projects using private networking. Update your Caddyfile to proxy traffic to the internal hostname of your upstream service:

Because Railway terminates TLS before traffic reaches Caddy, you should add auto_https off in the global options block when using site addresses with hostnames, to prevent Caddy from attempting to manage certificates itself.

Environment variables

The following environment variable is supported by the Caddy Railway template:

NameDescriptionExample
CADDY_PLUGINSSpace-separated list of Caddy plugin Go module paths to include in the buildgithub.com/caddy-dns/cloudflare github.com/mholt/caddy-ratelimit

Notes on TLS and HTTPS

Railway terminates TLS at the edge before traffic reaches your Caddy service, so Caddy operates behind a proxy and is not directly internet-facing. As a result:

  • You do not need Caddy to manage certificates. Railway handles this for you.
  • If your Caddyfile uses explicit site addresses (e.g., hostnames), add auto_https off in the global options block to prevent Caddy from trying to obtain certificates unnecessarily.
  • Caddy's port in the Caddyfile should match the PORT environment variable Railway injects, or simply listen on :8080 which is the default exposed by the template.

Next steps

You can make the most of Railway with these other resources: