I am learning using nginx to connect server and app in the docker compose. In the app, I am trying to post data to the database and it sends 5 requests a time
. The nginx seems not happy with it, and then I got 502
error: POST http://localhost/api/somerequest 502 (Bad Gateway)
. If I used a lower frequency at 1 request a time
and it will work.
The question is whether it possible to improve the nginx performance to allow it to handle multiple large number of requests, e.g. at 5 request frequency
. Is there any settings in the configuration I can start with?
The current config file:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
include conf.d/events.conf;
include conf.d/http.conf;
events {
worker_connections 1024;
}
http {
upstream server {
server ${SERVER_HOST}:${SERVER_PORT}; # env variable from container
keepalive 15;
}
upstream client {
server ${CLIENT_HOST}:${CLIENT_PORT}; # env variable from container
keepalive 15;
}
server {
listen 80;
server_name myservice; # my service container name in docker-compose.yml
error_log /var/log/nginx/myservice.error.log;
access_log /var/log/nginx/myservice.access.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
proxy_pass http://client;
}
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
proxy_pass http://server/api;
}
}
}
Note: there is one core in the nginx container. I have tried to increase the connection workers to 4000
, but it still does not work.
Thank you in advance.