Minimales nginx WebSocket Reverse-Proxy-Beispiel

English Deutsch

Wenn Sie eine nginx-Konfigurationsklausel wie

location_example.conf
location /app/ {
    proxy_pass http://app-server;
}

haben, können Sie leicht auch WebSocket-Verbindungen als Reverse-Proxy weiterleiten, indem Sie diese Klauseln innerhalb von location { ... } hinzufügen:

nginx_websocket_snippet.conf
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";

Vollständiges Beispiel:

nginx_websocket_example.conf
location /app/ {
    proxy_pass http://app-server;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
}

Check out similar posts by category: Nginx