【发布时间】:2019-02-02 22:09:32
【问题描述】:
在 Ubuntu 中出现 CORS 与 nginx 代理的套接字连接错误,而 Http 请求可以正常工作。
这是我的 Nginx 配置文件。此配置适用于 Windows 和 Mac,但不适用于 Ubuntu。
server
{
listen 7000 default_server;
listen [::]:7000 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://nodes;
}
}
upstream nodes {
# enable sticky session based on IP
ip_hash;
server localhost:3000;
server localhost:3001;
server localhost:3003;
}
【问题讨论】:
-
你可以通过给
io.origins('*:*');来检查它是否工作
标签: node.js nginx socket.io cors