Skip to content

GatewaySet up

The edge proxy

Put nginx in front of the gateway to terminate TLS and route OAuth2 sign-in, tunnels and devserver pages.

The nginx configuration

nginx terminates TLS and routes each kind of traffic to its listener:

TrafficArrives atGoes to
OAuth2 sign-in and accountsgw.example.comidentity, 127.0.0.1:7000
Devservers' tunnels, long-lived HTTP/2 streamsproxy.example.com/v1/tunnelThe proxy's tunnel listener, 127.0.0.1:7100, as h2c
Proxy health and readinessproxy.example.comThe proxy, 127.0.0.1:7002
Devserver pages and WebSockets*.p1.proxy.example.comThe proxy, 127.0.0.1:7002

Save this as /etc/nginx/sites-available/chan-gateway, with your domain in place of example.com:

map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; server_name gw.example.com proxy.example.com *.p1.proxy.example.com; return 301 https://$host$request_uri; } # Sign-in, accounts, and desktop discovery. server { listen 443 ssl http2; server_name gw.example.com; ssl_certificate /etc/letsencrypt/live/gw.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/gw.example.com/privkey.pem; location / { proxy_pass http://127.0.0.1:7000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } # Tunnel ingress and proxy health/readiness. server { listen 443 ssl http2; server_name proxy.example.com; ssl_certificate /etc/letsencrypt/live/gw.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/gw.example.com/privkey.pem; client_max_body_size 0; # A tunnel is one request that lasts as long as the devserver. location /v1/tunnel { grpc_pass grpc://127.0.0.1:7100; client_body_timeout 1h; grpc_read_timeout 1h; grpc_send_timeout 1h; grpc_socket_keepalive on; } location / { proxy_pass http://127.0.0.1:7002; proxy_set_header Host $host; } } # One origin per devserver: pages, terminals, and file transfers. server { listen 443 ssl http2; server_name *.p1.proxy.example.com; ssl_certificate /etc/letsencrypt/live/gw.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/gw.example.com/privkey.pem; client_max_body_size 0; location / { proxy_pass http://127.0.0.1:7002; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering off; proxy_read_timeout 1h; proxy_send_timeout 1h; } }

Enable it and reload nginx:

$sudo ln -s /etc/nginx/sites-available/chan-gateway /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl reload nginx
Details and limits
  • The proxy routes on the Host header, so the edge passes it through unchanged.
  • nginx ends a request body idle for 60 seconds by default, and a tunnel is idle whenever nobody uses its devserver. Without the raised client_body_timeout, a devserver dials again about once a minute.
  • A low grpc_read_timeout ends a quiet tunnel with a 504 and an upstream timed out line in nginx's error log.
  • This configuration listens on every address of the server. With WireGuard, an edge that names its listen addresses also needs the tunnel address, 10.7.0.1.
  • Each further proxy node runs an edge like this one for its own wildcard. See More proxy nodes.

What stays private

ListenerPortThrough the edge
identity, public7000Yes, as gw.example.com
devserver-proxy, pages and health7002Yes
devserver-proxy, tunnels7100Yes, at /v1/tunnel only
identity, internal7004Never
profile7001Never
devserver-control, admin7003Never
devserver-control, proxy sessions7101Never

Next