Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
Authenticating websocket requests with nginx

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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;
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!