CIS Nginx Benchmark

Secure configuration guidelines for Nginx web server and reverse proxy

v2.1.0 June 2024

Overview

▶

This CIS Benchmark provides prescriptive guidance for establishing a secure configuration posture for Nginx. Recommendations cover installation hardening, TLS configuration, security headers, request filtering, and information disclosure prevention.

~60Recommendations
6Sections
2Profile Levels
SectionAreaFocus
1Initial SetupInstallation source, version management
2Basic ConfigurationProcess user, permissions, timeouts
3LoggingAccess logs, error logs, log format
4TLS / SSLCertificates, protocols, ciphers, HSTS
5Request Filtering & HeadersRate limiting, buffer sizes, security headers
6Information DisclosureServer tokens, version hiding

Profile Definitions

▶
ProfileDescriptionIntended Use
L1Level 1 — Web ServerEssential hardening for all Nginx deployments.
L2Level 2 — Web ServerDefense-in-depth. May require application and client testing.

1 — Initial Setup

▶

1.1 Installation

▶
1.1.1 Ensure Nginx Is Installed from Official Source (Manual)
L1 Manual
Description

This recommendation verifies that Nginx Is Installed from Official Source on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to nginx Is Installed from Official Source may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
nginx -v
# Verify installation source:
rpm -qi nginx 2>/dev/null || dpkg -s nginx 2>/dev/null
Remediation

Install from the official nginx.org repository or OS vendor packages. Avoid unverified third-party builds.

1.1.2 Ensure Only Required Modules Are Compiled (Manual)
L2 Manual
Description

This recommendation verifies that Only Required Modules Are Compiled on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to only Required Modules Are Compiled may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
nginx -V 2>&1 | grep --color=auto -o -- '--with-[a-z_]*'
# Review compiled modules for business need
Remediation

Compile Nginx from source with only required modules. Disable unnecessary modules like --without-http_autoindex_module.

1.2 Software Updates

▶
1.2.1 Ensure Nginx Is the Latest Stable Version (Manual)
L1 Manual
Description

This recommendation verifies that Nginx Is the Latest Stable Version on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to nginx Is the Latest Stable Version may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
nginx -v
# Compare against https://nginx.org/en/download.html
Remediation
# Update via package manager:
dnf update nginx
# or
apt upgrade nginx

2 — Basic Configuration

▶

2.1 Process & Permissions

▶
2.1.1 Ensure Nginx Runs as Non-Root User (Automated)
L1 Auto
Description

This recommendation verifies that Nginx Runs as Non-Root User on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to nginx Runs as Non-Root User may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep 'user ' /etc/nginx/nginx.conf
# Should be: user nginx; (or www-data)
ps -ef | grep nginx | grep -v grep
Remediation
# /etc/nginx/nginx.conf:
user nginx;
2.1.2 Ensure Nginx Configuration Files Are Owned by Root (Automated)
L1 Auto
Description

The ownership of Nginx Configuration Files Are should be set to Root. Correct file and directory ownership prevents unauthorized modification and maintains the integrity of the NGINX web server configuration.

Rationale

Incorrect ownership of Nginx Configuration Files Are may allow unauthorized users to modify critical configuration or executable files. Ensuring correct ownership is essential for maintaining the integrity of the NGINX web server.

Audit
stat -c '%U:%G' /etc/nginx/nginx.conf /etc/nginx/conf.d/*.conf
# Should be root:root
Remediation
chown root:root /etc/nginx/nginx.conf
chmod 644 /etc/nginx/nginx.conf
2.1.3 Ensure the Nginx PID File Is Secured (Automated)
L1 Auto
Description

This recommendation verifies that the Nginx PID File Is Secured on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to the Nginx PID File Is Secured may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
ls -la /run/nginx.pid
# Should be owned by root with restrictive permissions
Remediation
# /etc/nginx/nginx.conf:
pid /run/nginx.pid;
2.1.4 Ensure autoindex Is Disabled (Automated)
L1 Auto
Description

This setting controls whether autoindex is disabled on the NGINX web server. Disabling this feature reduces the attack surface by removing unnecessary functionality that could be exploited by an attacker.

Rationale

Leaving autoindex enabled when it is not required unnecessarily expands the attack surface. An attacker could leverage this feature to gain unauthorized access or escalate privileges on the NGINX web server.

Audit
grep -r 'autoindex on' /etc/nginx/
# Should return empty
Remediation
# Remove or set in all locations:
autoindex off;

2.2 Timeouts & Limits

▶
2.2.1 Ensure Keepalive Timeout Is Set (Automated)
L1 Auto
Description

This recommendation configures the timeout for Keepalive on the NGINX web server. Appropriate timeout values limit the window of opportunity for attacks and ensure resources are released in a timely manner.

Rationale

Failure to keepalive Timeout Is Set may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep keepalive_timeout /etc/nginx/nginx.conf
# Should be reasonable (e.g., 10-65)
Remediation
# /etc/nginx/nginx.conf (http block):
keepalive_timeout 65;
2.2.2 Ensure send_timeout Is Set (Automated)
L1 Auto
Description

This recommendation verifies that send_timeout Is Set on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to send_timeout Is Set may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep send_timeout /etc/nginx/nginx.conf
Remediation
send_timeout 10;
2.2.3 Ensure worker_connections Is Configured Appropriately (Automated)
L1 Auto
Description

This recommendation verifies that worker_connections Is Configured Appropriately on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to worker_connections Is Configured Appropriately may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep worker_connections /etc/nginx/nginx.conf
Remediation
# /etc/nginx/nginx.conf (events block):
events {
    worker_connections 1024;
}

3 — Logging

▶

3.1 Access & Error Logs

▶
3.1.1 Ensure access_log Is Enabled (Automated)
L1 Auto
Description

This setting controls whether access_log is enabled on the NGINX web server. Enabling this feature strengthens the security posture by enforcing the recommended configuration via nginx.conf or site configuration files.

Rationale

Without access_log enabled, the NGINX web server may lack critical protections against known attack vectors. Enabling this control mitigates risk and aligns the deployment with industry-accepted security baselines.

Audit
grep -r 'access_log' /etc/nginx/ | grep -v '#'
# Should NOT have "access_log off;" in production
Remediation
# /etc/nginx/nginx.conf (http block):
access_log /var/log/nginx/access.log main;
3.1.2 Ensure error_log Is Configured with Appropriate Level (Automated)
L1 Auto
Description

This recommendation verifies that error_log Is Configured with Appropriate Level on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to error_log Is Configured with Appropriate Level may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep 'error_log' /etc/nginx/nginx.conf
# Should be at least 'warn' level
Remediation
error_log /var/log/nginx/error.log warn;
3.1.3 Ensure Log Files Have Proper Permissions (Automated)
L1 Auto
Description

This recommendation verifies that Log Files Have Proper Permissions on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to log Files Have Proper Permissions may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
ls -la /var/log/nginx/
# Files should be 640 or more restrictive, owned by root or nginx
Remediation
chmod 640 /var/log/nginx/*.log
chown root:adm /var/log/nginx/*.log

3.2 Log Format

▶
3.2.1 Ensure Custom Log Format Includes Required Fields (Manual)
L2 Manual
Description

This recommendation verifies that Custom Log Format Includes Required Fields on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to custom Log Format Includes Required Fields may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep log_format /etc/nginx/nginx.conf
Remediation
log_format main '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $body_bytes_sent '
                '"$http_referer" "$http_user_agent" '
                '"$http_x_forwarded_for" $request_time';

4 — TLS / SSL Configuration

▶

4.1 Certificate & Protocol

▶
4.1.1 Ensure HTTPS Is Enabled and HTTP Redirects to HTTPS (Automated)
L1 Auto
Description

This recommendation verifies that HTTPS Is Enabled and HTTP Redirects to HTTPS on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to hTTPS Is Enabled and HTTP Redirects to HTTPS may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep -r 'ssl_certificate' /etc/nginx/
# Verify HTTP→HTTPS redirect exists:
grep -r 'return 301' /etc/nginx/ | grep https
Remediation
server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}
4.1.2 Ensure Only TLS 1.2 and 1.3 Are Enabled (Automated)
L1 Auto
Description

This setting controls whether Only TLS 1.2 and 1.3 is enabled on the NGINX web server. Enabling this feature strengthens the security posture by enforcing the recommended configuration via nginx.conf or site configuration files.

Rationale

Without Only TLS 1.2 and 1.3 enabled, the NGINX web server may lack critical protections against known attack vectors. Enabling this control mitigates risk and aligns the deployment with industry-accepted security baselines.

Audit
grep ssl_protocols /etc/nginx/nginx.conf /etc/nginx/conf.d/*.conf
# Should be: TLSv1.2 TLSv1.3
Remediation
ssl_protocols TLSv1.2 TLSv1.3;
4.1.3 Ensure SSL Certificate Key Has Proper Permissions (Automated)
L1 Auto
Description

This recommendation verifies that SSL Certificate Key Has Proper Permissions on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to sSL Certificate Key Has Proper Permissions may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
# Find key path:
grep ssl_certificate_key /etc/nginx/conf.d/*.conf
# Check permissions:
stat -c '%a %U %G' /etc/ssl/private/server.key
# Should be 600 root root
Remediation
chmod 600 /etc/ssl/private/server.key
chown root:root /etc/ssl/private/server.key

4.2 Ciphers & HSTS

▶
4.2.1 Ensure Only Strong SSL Ciphers Are Used (Automated)
L1 Auto
Description

This recommendation verifies that Only Strong SSL Ciphers Are Used on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to only Strong SSL Ciphers Are Used may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep ssl_ciphers /etc/nginx/nginx.conf /etc/nginx/conf.d/*.conf
grep ssl_prefer_server_ciphers /etc/nginx/nginx.conf
Remediation
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:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
4.2.2 Ensure Diffie-Hellman Parameters Are 2048 Bits or More (Automated)
L1 Auto
Description

This recommendation verifies that Diffie-Hellman Parameters Are 2048 Bits or More on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to diffie-Hellman Parameters Are 2048 Bits or More may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep ssl_dhparam /etc/nginx/nginx.conf
openssl dhparam -inform PEM -in /etc/nginx/dhparam.pem -text 2>/dev/null | head -1
Remediation
# Generate 2048-bit DH parameters:
openssl dhparam -out /etc/nginx/dhparam.pem 2048

# nginx.conf:
ssl_dhparam /etc/nginx/dhparam.pem;
4.2.3 Ensure HSTS Is Enabled (Automated)
L1 Auto
Description

This setting controls whether HSTS is enabled on the NGINX web server. Enabling this feature strengthens the security posture by enforcing the recommended configuration via nginx.conf or site configuration files.

Rationale

Without HSTS enabled, the NGINX web server may lack critical protections against known attack vectors. Enabling this control mitigates risk and aligns the deployment with industry-accepted security baselines.

Audit
grep -r 'Strict-Transport-Security' /etc/nginx/
Remediation
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
4.2.4 Ensure OCSP Stapling Is Enabled (Automated)
L2 Auto
Description

This setting controls whether OCSP Stapling is enabled on the NGINX web server. Enabling this feature strengthens the security posture by enforcing the recommended configuration via nginx.conf or site configuration files.

Rationale

Without OCSP Stapling enabled, the NGINX web server may lack critical protections against known attack vectors. Enabling this control mitigates risk and aligns the deployment with industry-accepted security baselines.

Audit
grep ssl_stapling /etc/nginx/nginx.conf
Remediation
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;

5 — Request Filtering & Security Headers

▶

5.1 Request Limits

▶
5.1.1 Ensure client_max_body_size Is Configured (Automated)
L1 Auto
Description

This recommendation addresses the proper configuration of client_max_body_size on the NGINX web server. Proper configuration ensures the component operates securely and in accordance with organizational security policies.

Rationale

Misconfiguration of client_max_body_size can lead to security gaps that may be exploited by attackers. A properly configured NGINX web server reduces exposure to both known vulnerabilities and configuration drift.

Audit
grep client_max_body_size /etc/nginx/nginx.conf
Remediation
client_max_body_size 10m;
5.1.2 Ensure Buffer Overflow Attacks Are Mitigated (Automated)
L1 Auto
Description

This recommendation verifies that Buffer Overflow Attacks Are Mitigated on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to buffer Overflow Attacks Are Mitigated may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep -E 'client_body_buffer_size|client_header_buffer_size|large_client_header_buffers' /etc/nginx/nginx.conf
Remediation
client_body_buffer_size 1k;
client_header_buffer_size 1k;
large_client_header_buffers 4 8k;
5.1.3 Ensure Rate Limiting Is Configured (Automated)
L2 Auto
Description

This recommendation addresses the proper configuration of Rate Limiting on the NGINX web server. Proper configuration ensures the component operates securely and in accordance with organizational security policies.

Rationale

Misconfiguration of Rate Limiting can lead to security gaps that may be exploited by attackers. A properly configured NGINX web server reduces exposure to both known vulnerabilities and configuration drift.

Audit
grep -r limit_req /etc/nginx/
Remediation
# In http block:
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;

# In server/location block:
limit_req zone=one burst=20 nodelay;
5.1.4 Ensure Allowed HTTP Methods Are Restricted (Automated)
L2 Auto
Description

This setting ensures that Allowed HTTP Methods is restricted on the NGINX web server. Restricting this capability limits potential abuse and enforces the principle of least privilege across the environment.

Rationale

Unrestricted Allowed HTTP Methods could allow unauthorized users or processes to perform actions beyond their intended scope. Applying least-privilege principles to the NGINX web server is essential for defense in depth.

Audit
grep -r 'limit_except\|if.*request_method' /etc/nginx/
Remediation
# In location blocks:
if ($request_method !~ ^(GET|HEAD|POST)$) {
    return 405;
}

5.2 Security Headers

▶
5.2.1 Ensure X-Frame-Options Header Is Set (Automated)
L1 Auto
Description

This recommendation verifies that X-Frame-Options Header Is Set on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to x-Frame-Options Header Is Set may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep -r 'X-Frame-Options' /etc/nginx/
Remediation
add_header X-Frame-Options "SAMEORIGIN" always;
5.2.2 Ensure X-Content-Type-Options Header Is Set (Automated)
L1 Auto
Description

This recommendation verifies that X-Content-Type-Options Header Is Set on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to x-Content-Type-Options Header Is Set may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep -r 'X-Content-Type-Options' /etc/nginx/
Remediation
add_header X-Content-Type-Options "nosniff" always;
5.2.3 Ensure Content-Security-Policy Header Is Set (Manual)
L2 Manual
Description

This recommendation verifies that Content-Security-Policy Header Is Set on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to content-Security-Policy Header Is Set may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep -r 'Content-Security-Policy' /etc/nginx/
Remediation
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'" always;
5.2.4 Ensure Referrer-Policy Header Is Set (Automated)
L1 Auto
Description

This recommendation verifies that Referrer-Policy Header Is Set on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to referrer-Policy Header Is Set may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep -r 'Referrer-Policy' /etc/nginx/
Remediation
add_header Referrer-Policy "strict-origin-when-cross-origin" always;

6 — Information Disclosure

▶

6.1 Server Identity

▶
6.1.1 Ensure server_tokens Is Disabled (Automated)
L1 Auto
Description

This setting controls whether server_tokens is disabled on the NGINX web server. Disabling this feature reduces the attack surface by removing unnecessary functionality that could be exploited by an attacker.

Rationale

Leaving server_tokens enabled when it is not required unnecessarily expands the attack surface. An attacker could leverage this feature to gain unauthorized access or escalate privileges on the NGINX web server.

Audit
grep server_tokens /etc/nginx/nginx.conf
# Should be: server_tokens off;
curl -sI http://localhost | grep Server
Remediation
# /etc/nginx/nginx.conf (http block):
server_tokens off;
6.1.2 Ensure Default Error and Index Pages Are Customized (Manual)
L1 Manual
Description

This recommendation verifies that Default Error and Index Pages Are Customized on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to default Error and Index Pages Are Customized may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
# Check for custom error pages:
grep error_page /etc/nginx/nginx.conf /etc/nginx/conf.d/*.conf
Remediation
# In server block:
error_page 404 /custom_404.html;
error_page 500 502 503 504 /custom_50x.html;

location = /custom_404.html {
    root /usr/share/nginx/html;
    internal;
}
6.1.3 Ensure Hidden Files Are Not Served (Automated)
L1 Auto
Description

This recommendation verifies that Hidden Files Are Not Served on the NGINX web server. Implementing this control strengthens the overall security configuration and reduces exposure to potential threats.

Rationale

Failure to hidden Files Are Not Served may leave the NGINX web server vulnerable to attack or non-compliant with organizational security policies. This control helps establish a consistent, hardened configuration baseline.

Audit
grep -r 'location.*\.' /etc/nginx/ | grep deny
Remediation
# In server block:
location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
}