From 86f7c9680799f1037751b450ada2da1bc94451b4 Mon Sep 17 00:00:00 2001 From: iRedTea Date: Fri, 16 Oct 2026 20:18:06 +0300 Subject: [PATCH] feat: rewrite nginx files --- deploy/nginx.conf.http.example | 51 +++++++++++++++++++ ....conf.example => nginx.conf.https.example} | 4 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 deploy/nginx.conf.http.example rename deploy/{nginx.conf.example => nginx.conf.https.example} (98%) diff --git a/deploy/nginx.conf.http.example b/deploy/nginx.conf.http.example new file mode 100644 index 0000000..5f6d5f1 --- /dev/null +++ b/deploy/nginx.conf.http.example @@ -0,0 +1,51 @@ +# nginx reverse proxy for the LPRA server. +# TLS is terminated here; the Go server listens on 127.0.0.1:8091. +# +# Put this in /etc/nginx/sites-available/lp_agent and symlink it into +# sites-enabled, then: sudo nginx -t && sudo systemctl reload nginx +# +# Agents connect by WebSocket (from 0.1.0), with HTTP long polling to fall +# back on; the browser uses plain HTTP. The settings that matter: +# - Upgrade / Connection headers -> let the agents' WebSocket through +# - proxy_buffering off -> deliver long-poll responses immediately +# - proxy_read_timeout 300s -> longer than the 25s long-poll hold +# +# NOTE: proxy_pass MUST start with "http://". A bare "proxy_pass 127.0.0.1:8091;" +# causes nginx error: [emerg] invalid URL prefix. + +# "Connection: upgrade" for a WebSocket, "close" for everything else. + + +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + +server { + listen 80; + server_name example.ru; + + client_max_body_size 120m; + + location / { + proxy_pass http://127.0.0.1:8091; + + proxy_http_version 1.1; + proxy_set_header Host $host; + 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 $scheme; + # Agents' WebSocket. + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + + # Long-poll behaviour: no buffering, generous read timeout. + proxy_buffering off; + proxy_cache off; + # Pass uploads on as they arrive: the speed test through the browser + # times them on the client. + proxy_request_buffering off; + proxy_read_timeout 300s; + proxy_send_timeout 300s; + } +} diff --git a/deploy/nginx.conf.example b/deploy/nginx.conf.https.example similarity index 98% rename from deploy/nginx.conf.example rename to deploy/nginx.conf.https.example index 66f0f5c..8a02172 100644 --- a/deploy/nginx.conf.example +++ b/deploy/nginx.conf.https.example @@ -14,6 +14,8 @@ # causes nginx error: [emerg] invalid URL prefix. # "Connection: upgrade" for a WebSocket, "close" for everything else. + + map $http_upgrade $connection_upgrade { default upgrade; '' close; @@ -21,7 +23,7 @@ map $http_upgrade $connection_upgrade { server { listen 443 ssl; - server_name lpra.minomix.ru; + server_name example.ru; ssl_certificate /etc/letsencrypt/live/REDACTED/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/REDACTED/privkey.pem; # managed by Certbot