Use the information below as general guidance for tuning Nginx.
In the Setup Reverse Proxy and API Gateway section of the Learn how to deploy Nginx learning path, a bare minimum Reverse Proxy and API Gateway configuration was discussed. In this section, you will look at a tuned configuration.
The same top level config used in Tune a static file server is suggested.
A tuned configuration (/etc/nginx/conf.d/loadbalancer.conf) is shown below. Only performance relevant directives that were not discussed in the
file server section
are explained here.
    
        
        
# Upstreams for https
upstream ssl_file_server_com {
  server <fileserver_1_ip_or_dns>:443;
  server <fileserver_2_ip_or_dns>:443;
  keepalive 1024;
}
# HTTPS reverse proxy and API Gateway
server {
  listen 443 ssl reuseport backlog=65535;
  root /usr/share/nginx/html;
  index index.html index.htm;
  server_name $hostname;
  ssl_certificate /etc/nginx/ssl/ecdsa.crt;
  ssl_certificate_key /etc/nginx/ssl/ecdsa.key;
  ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384;
  # API Gateway Path
  location ~ ^/api_old/.*$ {
    limit_except GET {
      deny all;
    }
    rewrite ^/api_old/(.*)$ /api_new/$1 last;
  }
  location /api_new {
    internal;
    proxy_pass https://ssl_file_server_com;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
  }
  # Reverse Proxy Path
  location / {
    limit_except GET {
      deny all;
    }
    proxy_pass https://ssl_file_server_com;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
  }
}
    
keepalive
:upstream block.proxy_http_version should be set to 1.1 and proxy_set_header connection header should be cleared for upstream keep alive to work properly.proxy_cache_path
proxy_cache_lock and proxy_cache_valid should be considered as additional optimizations.