The concierge's desk

Proxy block generator

Type the hostname a visitor will use and the address and port the app listens on. The desk fills in two fixed templates, one for Caddy and one for nginx. Treat the result the way you would treat a calculator's estimate: a draft to check against the documentation, not a configuration anyone has run on your server.

The guest and the room

Letters, digits, hyphens and dots, for example photos.example.com.

An IPv4 address or a hostname, for example 127.0.0.1 or a container name.

1 to 65535.

Showing the example: photos.example.com to 192.168.1.20:2283.

Your two blocks

Caddyfile

photos.example.com {
	reverse_proxy 192.168.1.20:2283
}

With default settings, Caddy manages HTTPS for site addresses that qualify: it can obtain and renew certificates and redirect HTTP to HTTPS. In the standard public setup that needs the name to point at your server, writable persistent storage, and ports 80 and 443 reachable directly or forwarded. DNS validation is a separate option and works differently. Names Caddy treats as local get a certificate from its own local certificate authority, and clients have to trust that authority. See Automatic HTTPS.

nginx server block

server {
    listen 80;
    server_name photos.example.com;

    location / {
        proxy_pass http://192.168.1.20:2283;
        proxy_set_header Host $host;
    }
}

This block serves plain HTTP on port 80 and leaves certificate issuance out. For HTTPS, add listen 443 ssl; with ssl_certificate and ssl_certificate_key lines pointing at a certificate you have obtained. See Configuring HTTPS servers.

The two templates

Nothing else is added. Both names are trimmed and lower-cased. HOST is the hostname you typed, with one final dot removed if you typed one. UPSTREAM is the upstream address, a colon and the port written in decimal, for example 192.168.1.20:2283.

Caddyfile

HOST {
	reverse_proxy UPSTREAM
}

nginx

server {
    listen 80;
    server_name HOST;

    location / {
        proxy_pass http://UPSTREAM;
        proxy_set_header Host $host;
    }
}

With the WebSocket box ticked, these three lines go inside the nginx location block, as on the nginx WebSocket proxying page. The first line pins HTTP/1.1 for the proxied connection. That page's own example includes it, so it is kept here as a compatibility setting; check the page for your nginx version:

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

What the fields accept

  • Hostname: letters, digits and hyphens in dot-separated labels, up to 63 ASCII characters per label and 253 in the whole name, not counting a final dot. This follows RFC 1035 and RFC 1123. A scheme, port, path, wildcard or IP address is rejected.
  • Upstream address: either a hostname by the same rules, or an IPv4 address of four numbers from 0 to 255, as in RFC 3986 section 3.2.2. IPv6 is not supported here.
  • Port: a whole number from 1 to 65535, the range of the 16-bit TCP port field. Port 0 is reserved, as the IANA port registry lists. Leading zeros are accepted and dropped.
  • An empty field, a zero, a negative number, text or a number above 65535 gets a plain message instead of a block.

What the templates assume

  • The app answers plain HTTP at the upstream address. Neither template encrypts the hop from the proxy to the app.
  • One hostname sends the whole site (every path) to one upstream. No load balancing, paths, headers or access rules beyond the lines shown.
  • Caddy: with default settings, a site address that qualifies switches on automatic HTTPS. In the standard public setup Caddy needs the name to point at your server, writable persistent storage, and ports 80 and 443 reachable directly or forwarded. DNS validation is a separate option. Names Caddy treats as local get a certificate from its own local certificate authority, and clients have to trust that authority. The Automatic HTTPS page lists the exact rules.
  • nginx: the block serves plain HTTP on port 80 and leaves certificate issuance out. You add the HTTPS lines and a certificate you have obtained. If this block is the default server for its listen address and port, nginx also sends it requests whose name matches no server_name; the request processing page explains how nginx chooses a server. proxy_set_header Host $host passes nginx's request host name to the app, falling back to the configured server name. Without it nginx sends the host and port written in proxy_pass.
  • The WebSocket lines are added only to the nginx block. The generator adds nothing to the Caddy block for WebSockets; the reverse_proxy page explains how Caddy handles upgraded connections.
  • The example names use example.com, which is reserved for documentation. Replace it with your own domain.

Nothing you type is stored or sent anywhere. The blocks are built in your browser.

Sources

  1. reverse_proxy (Caddyfile directive) Caddy documentation
  2. Automatic HTTPS Caddy documentation
  3. Module ngx_http_proxy_module nginx documentation
  4. Configuring HTTPS servers nginx documentation
  5. WebSocket proxying nginx documentation
  6. RFC 2606: Reserved Top Level DNS Names IETF, RFC Editor
  7. RFC 1035: Domain Names, Implementation and Specification IETF, RFC Editor
  8. RFC 1123: Requirements for Internet Hosts, Application and Support IETF, RFC Editor
  9. RFC 3986: Uniform Resource Identifier (URI), Generic Syntax, section 3.2.2 IETF, RFC Editor
  10. Service Name and Transport Protocol Port Number Registry IANA
  11. How nginx processes a request nginx documentation