4

I have a flask-socketio server running on ubuntu with nginx. I have a client calling the server. When I try to call the server I receive the following error:

has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values '*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *', but only one is allowed.

This is my initialization with flask:

socketio = SocketIO(app, cors_allowed_origins='*', async_mode='eventlet')

...

if __name__ == '__main__':
    socketio.run(app, host="0.0.0.0", port='80', debug=False)

This is my current config in nginx:

server {
    listen 80;
    server_name server-address;

    location / {
    include proxy_params;
    proxy_pass http://server-address;
    include uwsgi_params;
    uwsgi_pass unix:/home/user/project/project.sock;
    }

    location /socket.io{
    include proxy_params;
    add_header "Access-Control-Allow-Origin" "*" always;
    proxy_http_version 1.1;
    proxy_buffering off;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_pass http://server-address/socket.io;
    }
}

And the request to the server from the client looks like this:

http://server-address/socket.io/?EIO=3&transport=polling&t=1617406124248-38

I have tried:

-Adding the allow CORS to location / only, and both. -Removing/adding allow CORS origin in the flask app.

Can anyone help?

Itai Elidan
  • 272
  • 9
  • 27

1 Answers1

0

please add in your Nginx conf

proxy_hide_header Access-Control-Allow-Origin

and then reload the Nginx and try .