How to forward web-socket request to microservice using nginx

Multi tool use


How to forward web-socket request to microservice using nginx
I wanted to forward the web-socket request to microservice using nginx.
I am hitting https://some-host/download-zip-service/downloadFile
https://some-host/download-zip-service/downloadFile
By this, the calls are landing on download-zip-service and downloadFile API get the 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/');
var socket = io('https://some-host/download-zip-service/');
the calls are directly landing onwss://some-host/socket.io/?EIO=3&transport=websocket&sid=12345678
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
https://some-host/download-zip-service/socket.io/?EIO=3&transport=websocket&sid=12345678
as a reason, I explicitly 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;
}
}
}
I want to remove the root /
path for download-zip-service.
and it should work with /download-zip-service/
Please let me know where I am doing mistake
/
/download-zip-service/
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.