亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Nginx:WebSocket 通配符位置

Nginx:WebSocket 通配符位置

Go
慕勒3428872 2021-12-13 18:37:51
我在 Go 服務前使用了一個 nginx 實例。我想將端口 80 上的任何內容重定向到 https。[完畢]/* 處的所有(非 websocket)https 請求都應轉到https://localhost:8443/ * [完成]/ws/* 的所有 websocket https 請求都應該轉到https://localhost:8443/ws/ * [missing]我目前的配置:ssl_certificate                 ...ssl_certificate_key             ...ssl_ciphers                     ...ssl_prefer_server_ciphers       on;server {        listen         80;        location / {                return 301 https://$host$request_uri;        }}server {        listen          443 ssl;        server_name     www.mydomain.com mydomain.com;        add_header Strict-Transport-Security "max-age=31536000";        location /ws {   <--- This only works for /ws but not /ws/app1            proxy_pass http://localhost:8443/ws;            proxy_http_version 1.1;            proxy_set_header Host $http_host;            proxy_set_header Upgrade $http_upgrade;            proxy_set_header Connection "upgrade";        }        location / {    <--- Catches anything, even without wildcard ?!                proxy_pass http://localhost:8443;        }}server {        listen 443 ssl;        server_name *.mydomain.com;        return 444;}為什么這是必要的?好吧,據我所知,您必須明確設置升級標頭,所以我想您必須指定另一個位置。理想情況下,我只使用一個位置,但隨后 websockets 被阻止(因為升級標頭永遠不會進入 Go 服務......)我不是 nginx 專家,所以請耐心等待 =)。
查看完整描述

1 回答

?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms查看文章

您沒有使用 any location_match,因此匹配是前綴匹配。

使用~作為位置匹配修飾符把它解釋為一個正則表達式。

該行location /ws應該匹配每個以 開頭的查詢/ws。


查看完整回答
反對 回復 2021-12-13
  • 1 回答
  • 0 關注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號