Final Configuration

Here is the detailed configuration of nginx with best practices , optimization and security concerns.

We have divided the configuration in multiple files, that are -

  1. nginx.conf - main configuration file for nginx

  2. app.conf - App specific file that need to be served.

  3. ssl_params.conf - Common file for SSL headers

  4. security_headers.conf - Reusable file for security related headers

  5. proxy_params.conf - Reusable file for proxy params.

  6. common-denied.conf - Reusable file for common file like 404 or 505 or access denied.

We need to create config folder manually . other wise change the path while including.

ssl_params.conf

To use this file we must need to configure ssl certificate first for the domain name.

# /config/ssl_params.conf
ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols       TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers         ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
ssl_session_tickets off;

proxy_params.conf

Common params and headers used in reverse proxy

common-denied.conf

File that contains 404 , or redirect or access denied that we can reuse in multiple blocks

security_headers.conf

common security headers that can be used in multiple blocks-

nginx.conf

The main configuration file -

app.conf

Configuration file for app specific that we are deploying. This file is having two server blocks one is for normal backend url and another is when we are using dns address like AWS load balancer.

Always check configuration nginx -t before running .

Last updated