簡體   English   中英

使用 nginx 驗證 websocket 請求

[英]Authenticating websocket requests with nginx

有一個我無法修改的WebSocket服務器,我不希望每個人都向這個發送請求。 我想向 WebSocket 添加類似 HTTP 基本身份驗證的內容,以便它不允許每個請求都傳遞到實際服務器。 我正在使用 Nginx 並想堅持使用它,但如果有任何其他程序可以實現這一點,我也可以接受。

感謝勞倫斯,我查看了子請求的文檔,現在可以使用 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;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM