javascript - 带有 NGINX 的 Socket.io。无法为套接字工作进行配置
问题描述
我有socket.io的后端,我想用nginx配置socket.io。在 nginx 进行以下配置之后,我可以使除套接字以外的其他路由正常工作,但我的套接字不工作。
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://localhost:5000; #whatever port your app runs on
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;
}
我需要在(sudo nano /etc/nginx/sites-available/default)文件中进行哪些配置才能使套接字工作。
解决方案
您是否尝试添加
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
到您的位置配置?
见https://www.nginx.com/blog/nginx-nodejs-websockets-socketio
推荐阅读
- office-js - Outlook Web 加载项:displayDialogAsync() 不起作用
- python - 我收到一个错误列表,指出此字段是必需的
- java - 从 Java 中的数组中加起来价格?
- android - 如何通过 google、Facebook 和 twitter 注册获取特定用户信息?
- vue.js - Vuetify 国际化
- ssms-2017 - SSMS 17.9.1 在“连接”时崩溃
- java - 带有 AND 运算符的 Java 复选框
- html - Display flex 在项目调整大小时提供不一致的滚动行为
- mysql - 使用联合表时如何选择不同的行
- c - 结构体和动态数组