关于 Nginx 配置 WebSocket 400 问题

今天把项目升级了 asp.net core 到 2.1 的版本,使用了 signalr  的功能,由于阿里云不支持 websocket 协议,所以使用了 nginx 代理方式来解决,后续就报了一个登陆的 404 错误。

POST http://xxx.xxx.xxx.xxx/account/login HTTP/1.1
Host: xxx.xxx.xxx.xxx
Connection: keep-alive
Content-Length: 217
Cache-Control: max-age=0
Origin: http://xxx.xx.xxx.xx
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://xxx.xx.xxx.xx/account/login
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: .AspNetCore.Antiforgery.7cgpZYq1ZXs=CfDJ8KJwTda_rr5JqCpgr4JkvXPer9JtjzFiA6KXhxp_8m9gZOJgqfDqP-AhE7u-AgDz3PCB1Ij7YCwQKP6qevtpPPMZcWfGlk4-6v_v6TqFe8yPcQ-_wPmB5OqgxSpALzp9mP13S7HQVhSg6T8Hxm7Q1tI

__RequestVerificationToken=CfDJ8KJwTda_rr5JqCpgr4JkvXOlA8q_Wj9j8_hKa5BXlVTLeL65qofkijsny-O8pTxOIc7j5Vqrkw9SrKV-xOoChhghUf60qv9Juqm_epLjs-qKXOkG5SEhETtnrWDmLM8nlhEpMkOyuY2p5GnGNtZ7m4k&userName=irving&pwd=xxx


HTTP/1.1 400 Bad Request
Server: nginx/1.10.3 (Ubuntu)
Date: Fri, 01 Jun 2018 14:52:04 GMT
Content-Length: 0
Connection: keep-alive
   server {
         listen 80;
         location / {
            proxy_pass http://localhost:5000;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         }
       location ~ ^/(.*)/ws${
        proxy_pass http://localhost:5000;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Host $http_host;
            proxy_read_timeout 36000s;
        }
       }

https://www.orgleaf.com/2280.html

http://nginx.org/en/docs/http/websocket.html

http://dbaplus.cn/news-21-1129-1.html

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04

你可能感兴趣的:(关于 Nginx 配置 WebSocket 400 问题)