Skip to content

Instantly share code, notes, and snippets.

@LukeLambert
Last active April 10, 2024 23:02
Show Gist options
  • Save LukeLambert/c8ab8f8eb1cb31f528ee57dfac596293 to your computer and use it in GitHub Desktop.
Save LukeLambert/c8ab8f8eb1cb31f528ee57dfac596293 to your computer and use it in GitHub Desktop.
An nginx config to make Tinypilot work with reverse proxies like Traefik, Caddy, Cloudflare Tunnel, ngrok, etc. Updates to Tinypilot should not delete or overwrite this file.
# Save this file as /etc/nginx/sites-enabled/proxyable-tinypilot.conf
# Restart nginx: service nginx restart
# Point your reverse proxy to 127.0.0.1:8899
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
default $http_x_forwarded_proto;
'' $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
default $http_x_forwarded_port;
'' $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
default upgrade;
'' close;
}
server {
listen 8899 default_server;
server_name _;
root /opt/tinypilot;
index index.html;
proxy_buffers 16 16k;
proxy_buffer_size 16k;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
proxy_set_header X-Forwarded-Host $http_host;
proxy_http_version 1.1;
location /state {
proxy_pass http://ustreamer;
}
location /stream {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
proxy_pass http://ustreamer;
}
location /snapshot {
proxy_pass http://ustreamer;
}
location /janus/ws {
proxy_pass http://janus-ws;
}
location / {
proxy_pass http://tinypilot;
}
location ~* ^/.+\.(html|js|js.map|css|woff|woff2)$ {
root "/opt/tinypilot/app/static";
# We cache assets to prevent the browser from making redundant
# requests to the same files while loading the page. (Observed on
# Chrome 91.) We don’t want caching otherwise, though, in order to
# avoid stale files after users update their device. Note, that in
# addition to `max-age`, the browser’s caching behaviour is relative
# to the `Last-Modified` header, so we make that seem recent.
add_header Last-Modified $date_gmt;
add_header Cache-Control 'public, max-age=10s';
}
location ~* ^/.+\.(jpg|jpeg|png|ico)$ {
root "/opt/tinypilot/app/static";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment