11# ngx_security_headers
22
3- This NGINX module adds security headers and removes insecure headers easily .
3+ This NGINX module adds security headers and removes insecure headers, * the right way * (c) .
44
55## Synopsis
66
@@ -11,29 +11,33 @@ http {
1111}
1212```
1313
14- Running ` curl -IL http ://example.com/ ` will yield additional headers:
14+ Running ` curl -IL https ://example.com/ ` will yield additional headers:
1515
16- ```
16+ < pre >
1717HTTP/1.1 200 OK
1818Server: nginx
1919Date: Tue, 21 May 2019 16:15:46 GMT
2020Content-Type: text/html; charset=UTF-8
2121Vary: Accept-Encoding
2222Accept-Ranges: bytes
2323Connection: keep-alive
24- X-Frame-Options: SAMEORIGIN <-----------
25- X-XSS-Protection: 1; mode=block <-----------
26- Referrer-Policy: no-referrer-when-downgrade <-----------
27- ```
24+ <b >X-Frame-Options: SAMEORIGIN
25+ X-XSS-Protection: 1; mode=block
26+ Referrer-Policy: strict-origin-when-cross-origin
27+ Strict-Transport-Security: max-age=63072000; includeSubDomains; preload</b >
28+ </pre >
2829
29- Running ` curl -IL http ://example.com/some.css ` (or ` some.js ` ) will yield * additional* security header:
30+ Running ` curl -IL https ://example.com/some.css ` (or ` some.js ` ) will yield * additional* security header:
3031
31- ```
32+ < pre >
3233HTTP/1.1 200 OK
3334...
34- X-Content-Type-Options: nosniff <-----------
35- ```
35+ < b > X-Content-Type-Options: nosniff</ b >
36+ </ pre >
3637
38+ In general, the module features sending security HTTP headers in a way that better conforms to the standards.
39+ For instance, ` Strict-Transport-Security ` header should * not* be sent for plain HTTP requests.
40+ The module follows this recommendation.
3741
3842## Key Features
3943
@@ -132,27 +136,37 @@ Defines MIME types, for which `X-Content-Type-Options: nosniff` is sent.
132136
133137It's easy to install the module in your stable nginx instance dynamically:
134138
135- sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm
136- sudo yum install nginx-module-security-headers
139+ ``` bash
140+ sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm
141+ sudo yum install nginx-module-security-headers
142+ ```
137143
138144Then add it at the top of your ` nginx.conf ` :
139145
140- load_module modules/ngx_http_security_headers_module.so;
146+ ```
147+ load_module modules/ngx_http_security_headers_module.so;
148+ ```
141149
142150In case you use ModSecurity NGINX module, make sure it's loaded last, like so:
143151
144- load_module modules/ngx_http_security_headers_module.so;
145- load_module modules/ngx_http_modsecurity_module.so;
152+ ```
153+ load_module modules/ngx_http_security_headers_module.so;
154+ load_module modules/ngx_http_modsecurity_module.so;
155+ ```
146156
147157### Other platforms
148158
149159To compile the module into NGINX, run:
150160
151- ./configure --add-module=../ngx_security_headers
152- make
153- make install
161+ ``` bash
162+ ./configure --add-module=../ngx_security_headers
163+ make
164+ make install
165+ ```
154166
155167Or you can compile it as dynamic module. In that case, use ` --add-dynamic-module ` instead, and load the module after
156168compilation by adding to ` nginx.conf ` :
157169
158- load_module /path/to/ngx_http_security_headers_module.so;
170+ ```
171+ load_module /path/to/ngx_http_security_headers_module.so;
172+ ```
0 commit comments