Skip to content

Commit 1f56287

Browse files
committed
add security headers
time spent: 0.5h
1 parent b61005b commit 1f56287

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ and it can't be just copied to usual nginx. However, you can use it with docker.
2323
Also I don't agree with nginx microcache for every site, see known traps.
2424

2525
Time track:
26-
- [Filipp Frizzy](https://github.com/Friz-zy/) 35.34h
26+
- [Filipp Frizzy](https://github.com/Friz-zy/) 35.84h
2727

2828
### Configs
2929

3030
#### Main configs
3131
Almost all sections moved from main `nginx.conf` into `conf.d` directory:
3232

3333
* `basic.conf`
34-
Basic settings, security, mime types, charset, index, timeouts, open file cache, etc...
34+
Basic settings, mime types, charset, index, timeouts, open file cache, etc...
3535
* `cache.conf`
3636
Fastcgi, Proxy and Uwsgi cache setup, see known traps before using ;)
3737
* `gzip.conf`
@@ -42,29 +42,31 @@ Extended log formats
4242
Allow X-Forwarded-For header from local networks and [cloudflare](https://www.cloudflare.com/)
4343
* `request_id.conf`
4444
Add X-Request-ID header into each request for tracing and debugging
45+
* `security.conf`
46+
Security settings and headers
4547
* `ssl.conf`
4648
SSL best practice from [mozilla](https://ssl-config.mozilla.org/#server=nginx&version=1.17.7&config=intermediate&openssl=1.1.1d&guideline=5.4)
4749

4850
#### Snippets
4951
Templates and includes. You can also use [config generator](https://www.digitalocean.com/community/tools/nginx) from digitalocean :)
5052

51-
* corps.conf.j2
53+
* `corps.conf.j2`
5254
Template of corps politic for multiple subdomains setup
53-
* default.conf
55+
* `default.conf`
5456
Example of default config with nginx_status, let's encrypt check and redirect to https
55-
* fastcgi.conf
57+
* `fastcgi.conf`
5658
Include for php locations: fastcgi parameters, timeouts and cache example
57-
* headers.conf
59+
* `headers.conf`
5860
Include with all headers, see known traps
59-
* protected_locations.conf
61+
* `protected_locations.conf`
6062
Include with protected locations with 'deny all'
61-
* proxy.conf
63+
* `proxy.conf`
6264
Include for proxy locations: proxy headers, parameters, timeouts and cache example
63-
* referer.conf.j2
65+
* `referer.conf.j2`
6466
Template of referer protection for cases when you concurents use your fail2ban protection against you, see known traps
65-
* site.conf.j2
67+
* `site.conf.j2`
6668
Template of common site configuration
67-
* static_location.conf
69+
* `static_location.conf`
6870
Include with location for static files
6971

7072
#### Docker-compose

conf.d/basic.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
sendfile on; # default is off
55
tcp_nopush on; # default is off
66
tcp_nodelay on;
7-
server_tokens off; # default is on
87

98
include /etc/nginx/mime.types;
109
default_type application/octet-stream; # default is text/plain

conf.d/security.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
server_tokens off; # default is on
2+
3+
# source: https://www.digitalocean.com/community/tools/nginx
4+
# you can check result here: https://securityheaders.com
5+
6+
# disable or modify if your site should work in iframes
7+
add_header X-Frame-Options "SAMEORIGIN" always;
8+
9+
add_header X-XSS-Protection "1; mode=block" always;
10+
11+
add_header X-Content-Type-Options "nosniff" always;
12+
13+
add_header Referrer-Policy "no-referrer-when-downgrade" always;
14+
15+
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
16+
17+
# disable if some of your pages should work through http also
18+
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

snippets/headers.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
add_header X-Request-ID $requestid always;
22
# add_header X-Cache-Status $upstream_cache_status always;
33
# add_header "Access-Control-Allow-Origin" "$corps_origin";
4+
5+
6+
7+
# Security headers
8+
# source: https://www.digitalocean.com/community/tools/nginx
9+
# you can check result here: https://securityheaders.com
10+
11+
# disable or modify if your site should work in iframes
12+
add_header X-Frame-Options "SAMEORIGIN" always;
13+
14+
add_header X-XSS-Protection "1; mode=block" always;
15+
16+
add_header X-Content-Type-Options "nosniff" always;
17+
18+
add_header Referrer-Policy "no-referrer-when-downgrade" always;
19+
20+
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
21+
22+
# disable if some of your pages should work through http also
23+
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
24+

0 commit comments

Comments
 (0)