NGINX Security Hardening
NGINX security hardening reduces the ways a public web server or reverse proxy can be abused. You protect each boundary: the software and host, encrypted connections, accepted requests, upstream trust, browser responses, and operational evidence.
itWeb servers, proxies, and traffic management | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic: NGINX Security Hardening
NGINX is the traffic desk between an untrusted client and an application. It can accept an encrypted connection, choose a virtual server, select a location, serve a file, enforce an access rule, or send the request upstream. This is a very useful place to have a policy. It is also a very efficient place to make one mistake apply to everything.
The useful mental model is six verbs: patch, minimize, encrypt, bound, authorize, observe. Patching deals with vulnerable code, not the politeness of its configuration. Minimizing removes listeners, modules, files, and routes that have no job. Encryption protects the client-to-NGINX hop and, when NGINX proxies onward, the NGINX-to-upstream hop too. The other verbs keep a request from becoming unlimited work, give the right party access, and leave enough evidence to discover that the policy had other ideas.
The surprise is that the configuration is not a list of decorations. Virtual server selection chooses a `server` block from the listener and request name. Location selection chooses the rule set for the path. A splendid access rule in the wrong place protects precisely nothing, which is one of computing's less comforting forms of accuracy. An intentional default server is therefore part of the security design, not an administrative afterthought.
TLS termination means NGINX decrypts the client connection. If it then talks HTTPS to an upstream, encryption alone is not enough: NGINX must verify the upstream certificate and use the right server name. Similarly, a per-address rate limit only helps when the address represents the client. Behind a proxy, a forwarded address becomes trustworthy only after NGINX trusts the exact proxy that supplied it.
The controls have opinions about normal traffic. A body-size limit can break uploads. A timeout can interrupt slow work or hold resources too long. HSTS changes later browser behavior and its subdomain scope is hard to retract. Security headers can disappear on an error path when lower-level configuration changes inheritance. The policy must therefore be tested where requests actually go, including unexpected host names, errors, bursts, and slow clients.
Start with the Intro when the boundary itself is unfamiliar. Use Slides for the path from listener to upstream. Keep the Cheatsheet nearby when comparing directives, inheritance, and test signals. The Quiz checks the decisions that look similar until they fail differently. Field Notes is for the operational costs that turn a correct directive into an incorrect deployment.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://nginx.org/en/docs/
Supports
- Official NGINX documentation structure
- NGINX roles as HTTP server, proxy, and load balancer
- https://nginx.org/en/docs/http/request_processing.html
Supports
- Listener and virtual-server selection
- Default-server behavior
- Host-based request routing
- https://nginx.org/en/docs/http/server_names.html
Supports
- Exact, wildcard, and regular-expression server names
- Configuration phases that use default-server values
- TLS protocol selection before request-based virtual-server selection
- https://nginx.org/en/docs/http/ngx_http_core_module.html
Supports
- Location selection and precedence
- Client header and body limits and timeouts
- Keep-alive controls
- Method restrictions through limit_except
- Version disclosure through server_tokens
- Internal-only locations and symbolic-link controls
- https://nginx.org/en/docs/http/ngx_http_rewrite_module.html
Supports
- Returning a chosen HTTP status from server and location contexts
- Redirect behavior and status codes
- https://nginx.org/en/docs/http/configuring_https_servers.html
Supports
- TLS listener, certificate, and private-key configuration
- Restricted private-key file access
- TLS protocol and cipher controls
- Session cache and session reuse
- Name-based HTTPS and Server Name Indication
- https://nginx.org/en/docs/http/ngx_http_ssl_module.html
Supports
- TLS module and directive semantics
- Client-certificate verification
- Trusted certificates and Online Certificate Status Protocol response verification
- https://nginx.org/en/docs/http/ngx_http_proxy_module.html
Supports
- Reverse proxy behavior and upstream headers
- Upstream timeouts and buffering
- Upstream Transport Layer Security protocols and Server Name Indication
- Upstream certificate verification disabled by default
- Trusted certificate authorities for upstream verification
- Proxy cookie flags
- https://nginx.org/en/docs/http/ngx_http_realip_module.html
Supports
- Replacement of client address from a configured field
- Trusted proxy sources through set_real_ip_from
- Recursive address selection
- Original peer address variable
- https://nginx.org/en/docs/http/ngx_http_limit_req_module.html
Supports
- Leaky-bucket request processing limits
- Shared-memory keys, rates, bursts, and delay behavior
- Dry-run accounting
- Logging and rejection status
- https://nginx.org/en/docs/http/ngx_http_limit_conn_module.html
Supports
- Connection limit keys and shared-memory zones
- Definition of a counted connection
- HTTP version concurrency behavior
- Dry-run accounting
- https://nginx.org/en/docs/http/ngx_http_access_module.html
Supports
- Address allow and deny rules
- First-match evaluation order
- Inheritance behavior
- https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html
Supports
- Basic Authentication access control
- Password-file format and supported hashes
- Warning against unsalted SHA one for new passwords
- https://nginx.org/en/docs/http/ngx_http_auth_request_module.html
Supports
- Authorization through subrequest results
- Combining authorization with other access modules
- https://nginx.org/en/docs/http/ngx_http_headers_module.html
Supports
- Arbitrary response headers
- Status-specific add_header behavior
- The always parameter
- Standard inheritance and newer inheritance controls
- https://nginx.org/en/docs/http/ngx_http_log_module.html
Supports
- Request logging and configurable formats
- JSON escaping
- Request time, status, bytes, and other log variables
- Buffered logs and syslog destination
- https://nginx.org/en/docs/switches.html
Supports
- Version and build inspection with capital V
- Syntax and referenced-file checks with lowercase t
- Complete configuration dump with capital T
- Reload signal behavior
- https://nginx.org/en/docs/control.html
Supports
- Configuration reload sequence
- Rollback when applying a new configuration fails
- Graceful transition from old to new workers
- https://nginx.org/en/security_advisories.html
Supports
- Official vulnerable and fixed version ranges
- Severity and affected-module information
- Need for software maintenance beyond configuration
- https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Security_Cheat_Sheet.html
Supports
- Confidentiality, integrity, and server authentication from Transport Layer Security
- Current protocol guidance
- Certificate and private-key protection
- Full-site encrypted transport and HSTS
- Client-certificate tradeoffs
- Server configuration testing
- https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html
Supports
- Browser security response headers
- Content Security Policy
- Strict Transport Security
- Content type, framing, and referrer policies
- https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Strict_Transport_Security_Cheat_Sheet.html
Supports
- Browser HSTS behavior
- Subdomain and preload scope
- Deployment and recovery considerations
- https://github.com/mozilla/ssl-config-generator
Supports
- Generation of server configurations from Mozilla server-side Transport Layer Security guidelines
- NGINX support
- Need to match configuration with deployed software versions
- https://github.com/sindresorhus/awesome
Supports
- Discovery of the curated NGINX resource list
- Curation principle for high-signal awesome entries
- https://github.com/fcambus/nginx-resources
Supports
- Discovery of Gixy-Next as a configuration analyzer
- Discovery of BunkerWeb as an NGINX-based web application firewall
- Discovery of NGINXConfig as a configuration generator
- https://gixy.io/
Supports
- Static analysis of NGINX configuration
- Security, hardening, and performance checks
- Command-line, container, browser, and machine-readable usage
- https://docs.bunkerweb.io/latest/quickstart-guide/
Supports
- NGINX-based reverse proxy and web application firewall role
- Protection of an existing HTTP service
- Deployment options and operational prerequisites
- https://www.digitalocean.com/community/tools/nginx
Supports
- Browser-based structured NGINX configuration generation
- Generated configuration as a starting point requiring environment-specific review
- https://blog.nginx.org/blog/celebrating-20-years-of-nginx
Supports
- NGINX development beginning in 2002
- First public release in 2004
- NGINX 1.0 in 2011
- NGINX Plus in 2013
- HTTP/2 support in 2015
- NGINX Ingress Controller in 2016
- https://nginx.org/en/CHANGES
Supports
- HTTP/2 module in nginx 1.9.5
- Dynamic modules in nginx 1.9.11
- Experimental HTTP/3 support in nginx 1.25.0
- https://blog.nginx.org/blog/nginx-1-9-5
Supports
- NGINX Open Source 1.9.5 HTTP/2 support
- https://blog.nginx.org/blog/nginx-dynamic-modules-how-they-work
Supports
- Dynamic modules changed the module loading model
- Module inventory remains part of the deployed attack surface
- https://blog.nginx.org/blog/mitigating-ddos-attacks-with-nginx-and-nginx-plus
Supports
- Rate and connection limits must reflect legitimate traffic
- Rate limiting is one component of layered denial-of-service mitigation
- https://www.f5.com/products/nginx/nginx-plus
Supports
- NGINX Plus product role
- https://www.haproxy.org/
Supports
- HAProxy product role
- https://httpd.apache.org/
Supports
- Apache HTTP Server product role
- https://caddyserver.com/
Supports
- Caddy product role
- https://traefik.io/traefik/
Supports
- Traefik product role
- https://www.envoyproxy.io/
Supports
- Envoy product role
- https://konghq.com/products/kong-gateway
Supports
- Kong Gateway product role
