Py学习  »  NGINX

使用nginx时socket.io出现CORS错误

Swati Mavani • 4 年前 • 208 次点击  

在Ubuntu中,使用nginx代理的cors会出现套接字连接错误,而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;
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38035
 
208 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Ricky Sterling
Reply   •   1 楼
Ricky Sterling    5 年前
server{
        listen 7000;
        server_name www.whatever.com;
        location / {
                add_header 'Access-Control-Allow-Origin' 'http://localhost:7000' always;
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
                add_header 'Access-Control-Allow-Headers' 'X-Requested-With,Accept,Content-Type, Origin,x-auth' always;
                default_type application/json;
                proxy_pass //node;
                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;





    }


}

可能这有助于用适当的地址替换地址。