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:
| Traffic | Arrives at | Goes to |
|---|---|---|
| OAuth2 sign-in and accounts | gw.example.com | identity, 127.0.0.1:7000 |
| Devservers' tunnels, long-lived HTTP/2 streams | proxy.example.com/v1/tunnel | The proxy's tunnel listener, 127.0.0.1:7100, as h2c |
| Proxy health and readiness | proxy.example.com | The proxy, 127.0.0.1:7002 |
| Devserver pages and WebSockets | *.p1.proxy.example.com | The 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
Hostheader, 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_timeoutends a quiet tunnel with a504and anupstream timed outline 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
| Listener | Port | Through the edge |
|---|---|---|
| identity, public | 7000 | Yes, as gw.example.com |
| devserver-proxy, pages and health | 7002 | Yes |
| devserver-proxy, tunnels | 7100 | Yes, at /v1/tunnel only |
| identity, internal | 7004 | Never |
| profile | 7001 | Never |
| devserver-control, admin | 7003 | Never |
| devserver-control, proxy sessions | 7101 | Never |