0

I wanted to forward web-socket request to microservice using nginx.

I am hitting https://some-host/download-zip-service/downloadFile

By this the calls are landing on download-zip-service and downloadFile api get call.

but when I tried to call socket api in download-zip-service I do something like var socket = io('https://some-host/download-zip-service/'); the call's are directly landing on

wss://some-host/socket.io/?EIO=3&transport=websocket&sid=12345678 instead of https://some-host/download-zip-service/socket.io/?EIO=3&transport=websocket&sid=12345678

as a reason I explisitly added the root / path for download-zip-service.

Below is my NGINX.conf file

worker_processes 4;

events { worker_connections 1024; }

http {
    sendfile on;

    upstream download-zip-service {
        server xx.xx.xx.xx:9012;

    }


server {
        listen 8765;
        #Changed for implementing WEB Socket
        location / {
            proxy_pass         http://download-zip-service/;
            proxy_redirect     off;
            # proxy_set_header   Host $host;
            # proxy_set_header   X-Real-IP $remote_addr;
            # proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            # proxy_set_header   X-Forwarded-Host $server_name;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            #new property added
            proxy_request_buffering off;
            proxy_buffering off;
        }

        location /download-zip-service/ {
            proxy_pass         http://download-zip-service/;
            proxy_redirect     off;
            # proxy_set_header   Host $host;
            # proxy_set_header   X-Real-IP $remote_addr;
            # proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            # proxy_set_header   X-Forwarded-Host $server_name;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            #socket timeout setting added
            fastcgi_read_timeout 7200s; 
            send_timeout 7200s;
            proxy_connect_timeout 7200s;
            proxy_send_timeout 7200s;
            proxy_read_timeout 7200s;
            #new property added
            proxy_request_buffering off;
            proxy_buffering off; 
        }

    }

}

Please let me know where I am doing mistake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.