'Set up nginx for websocket basic auth
I want to set up nginx with basic auth for a WebSocket server of mine, Specifically, I want to connect to the server using new WebSocket('ws://user:[email protected]').
My current configuration of nginx is:
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 8000;
multi_accept on;
use epoll;
}
http {
server {
listen 80;
server_name _;
location / {
auth_basic 'Restricted';
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://eth;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffering off;
}
}
upstream eth {
server eth:8545;
}
}
I based my conf on this:https://nginx.org/en/docs/http/websocket.html?_ga=2.247615047.1361983693.1651659402-1500014759.1651659402
However, whenever I try to connect to my server from the client application I get: WebSocket: bad handshake (HTTP status 200 OK).
Any help would be appreciated, thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
