There is a WebSocket server that I can't modify, and I don't want everyone to send requests to this. I want to add something like HTTP basic auth to the WebSocket so that it doesn't allow every request to pass through to the actual server. I am using Nginx and want to stick to it, but if there is any other program that accomplishes this, I am ok with that too.
Thanks to Lawrence, I checked out the docs for subrequest and this works now, after writing an auth server with node.js
server {
location /ws {
auth_request /auth;
auth_request_set $auth_status $upstream_status;
proxy_pass http://localhost:1234;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /auth {
internal;
proxy_pass http://localhost:3003;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Original-Remote-Addr $remote_addr;
proxy_set_header X-Original-Host $host;
}
}