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
Intro
NGINX Security Hardening
NGINX often sits where untrusted clients meet trusted applications. It may terminate TLS, select a virtual server, serve files, enforce an access rule, or forward a request upstream. That position makes NGINX a useful control point. It also makes every enabled listener, module, route, header rule, and trust decision part of your attack surface.
Hardening means reducing that attack surface while keeping the service useful. You do not collect isolated directives and call the job finished. You define what traffic should reach each boundary, reject what falls outside that policy, and preserve enough evidence to detect mistakes and abuse.
A practical mental model has six layers:
- Keep the NGINX build and its dependencies supported and patched.
- Expose only the listeners, modules, files, and routes the service needs.
- protect client and upstream traffic with verified TLS.
- Bound request cost with size, time, rate, connection, and method controls.
- Make identity and trust explicit for client addresses, protected locations, and upstream systems.
- Test changes, reload safely, and watch logs for rejected or unusual traffic.
Each layer covers a different failure mode. Hiding the version does not patch a vulnerable binary. TLS does not authorize a request. A rate limit does not repair an application flaw. A web application firewall does not make an unsafe origin safe. Defense in depth works because the layers overlap without being mistaken for one another.
Start with inventory, not a template
You need to know what NGINX actually runs before you can reduce it. Record the installed version, build options, loaded dynamic modules, included configuration files, listening sockets, certificate files, document roots, log destinations, and upstream endpoints.
The NGINX command-line interface supports two useful checks. nginx -V prints the version and build parameters. nginx -T tests the configuration and also dumps the complete configuration, including included files. This effective configuration is more useful than reviewing one short top-level file in isolation.
Compare the deployed build with the official NGINX security-advisory page and the security notices from your operating-system or package vendor. Patch status is a control of its own. Configuration cannot compensate for a known memory-safety or protocol flaw in an exposed module.
Remove unused listeners and modules where your packaging and deployment model permit it. Restrict access to configuration files, certificate keys, password files, logs, caches, and temporary directories. The HTTPS guide states that a private key should have restricted file access while remaining readable by the NGINX master process.
server_tokens off; removes the NGINX version from generated error pages and from the Server response header value. This reduces casual disclosure. It does not hide that the server behaves like NGINX, and it does not change the installed code.
Continue the course
This section is part of the paid course.
See pricing to subscribe, or log in if you already have access.
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
