Grafana Nginx 403 Origin not allowed 及 ws websocket連線錯誤解決

我超怕的發表於2024-10-29

Grafana Nginx 403 Origin not allowed 及 ws websocket錯誤解決 ---我超怕的
https://www.cnblogs.com/iAmSoScArEd/p/18514291

注意,這裡日誌並不全,僅貼了關鍵解決問題的部分,請勿直接複製貼上用於生產環境。


http {

    # 解決websocket錯誤 https://nginx.org/en/docs/http/websocket.html
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

  server {
        listen       80;
        listen       443 ssl;
        server_name  grafana.xxx.com;

        proxy_pass_request_headers on;
        location / {

            proxy_pass  http://grafana_ip:3000;
            proxy_set_header X-Real-Ip $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

           # 解決websocket錯誤
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            # 解決403 Origin not allowed
            proxy_set_header Host $http_host;
        }
    }
}

注意,這裡日誌並不全,僅貼了關鍵解決問題的部分,請勿直接複製貼上用於生產環境。

相關文章