viabtc / viabtc_exchange_server

A trading engine with high-speed performance and real-time notification
MIT License
2.67k stars 1.49k forks source link

Cross domain configuration of websocket #261

Open wh0am111 opened 3 years ago

wh0am111 commented 3 years ago

That's my configuration

upstream websocket {
     server 192.168.0.51:8008;
} 

server {
    listen       80;
    server_name  alpha3.www.exchange.com;

    root   /usr/share/nginx/html/dist/;
    index  index.html index.htm;

    error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    location /ws {
        add_header 'Access-Control-Allow-Origin' alpha3.www.exchange.com';
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        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 / {
             try_files $uri $uri/ @router;
             index index.html;
         }

    location @router {
            rewrite ^.*$ /index.html last;
        }

    location /api/ {
        add_header 'Access-Control-Allow-Origin' '*.niceex.com';
        proxy_pass http://alpha3.api.exchange.com/;
    }
    error_log   /tmp/vue-error.log;
    access_log  /tmp/vue-access.log mylog;
}

It's not work, It's also can be access from outside

Anyone know how to solve it?

wh0am111 commented 3 years ago

@haipome

djpnewton commented 3 years ago

This does not look like a problem specific to viabtc exchange? It looks like you are having trouble with your nginx configuration

wh0am111 commented 3 years ago

This does not look like a problem specific to viabtc exchange? It looks like you are having trouble with your nginx configuration

yes

wh0am111 commented 3 years ago

This does not look like a problem specific to viabtc exchange? It looks like you are having trouble with your nginx configuration

But i think , maybe need viabtc backend config Cross domain ?

djpnewton commented 3 years ago

the websocket server accessws does not care where the incoming connection comes from