关于 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
, ASP.NET Core
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述