We have a server application running behind nginx, and the client side will keep getting and writing data to it through HTTP request but should return really fast.
After running sometime, client side start receiving HTTP 502 Bad Gateway
error, and then the following attempt will drop within a short period.
I investigate the niginx error log and saw this message
connect() to 127.0.0.1:8889 failed (99: Cannot assign requested address) while connecting to upstream
I search online and seems like the issue is because local ip/port has limit and cannot free them fast enough.
I am wondering in this case, increate the range is the best solution? Since I also see some article suggest to turn on keep alive or increase buffer size.
This is our Nginx config:
server {
server_name foo;
...
location /bar/ {
proxy_pass http://localhost:8889;
}
}
Client side will keep sending HTTP GET/POST to foo/bar/xxxxx and the HTTP request will keep getting 502 but not all the time.