Skip to content

Commit ef6d9af

Browse files
committed
add latest h5bp settings
1 parent fb979de commit ef6d9af

13 files changed

+212
-0
lines changed

basic.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Basic h5bp rules
2+
3+
include /etc/nginx/directive-only/x-ua-compatible.conf;
4+
include /etc/nginx/location/expires.conf;
5+
include /etc/nginx/location/cross-domain-fonts.conf;
6+
include /etc/nginx/location/protect-system-files.conf;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This tells Nginx to cache open file handles, "not found" errors, metadata about files and their permissions, etc.
2+
#
3+
# The upside of this is that Nginx can immediately begin sending data when a popular file is requested,
4+
# and will also know to immediately send a 404 if a file is missing on disk, and so on.
5+
#
6+
# However, it also means that the server won't react immediately to changes on disk, which may be undesirable.
7+
#
8+
# In the below configuration, inactive files are released from the cache after 20 seconds, whereas
9+
# active (recently requested) files are re-validated every 30 seconds.
10+
#
11+
# Descriptors will not be cached unless they are used at least 2 times within 20 seconds (the inactive time).
12+
#
13+
# A maximum of the 1000 most recently used file descriptors can be cached at any time.
14+
#
15+
# Production servers with stable file collections will definitely want to enable the cache.
16+
open_file_cache max=1000 inactive=20s;
17+
open_file_cache_valid 30s;
18+
open_file_cache_min_uses 2;
19+
open_file_cache_errors on;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Cross domain AJAX requests
2+
3+
# http://www.w3.org/TR/cors/#access-control-allow-origin-response-header
4+
5+
# **Security Warning**
6+
# Do not use this without understanding the consequences.
7+
# This will permit access from any other website.
8+
#
9+
add_header "Access-Control-Allow-Origin" "*";
10+
11+
# Instead of using this file, consider using a specific rule such as:
12+
#
13+
# Allow access based on [sub]domain:
14+
# add_header "Access-Control-Allow-Origin" "subdomain.example.com";

directive-only/extra-security.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The X-Frame-Options header indicates whether a browser should be allowed
2+
# to render a page within a frame or iframe.
3+
add_header X-Frame-Options SAMEORIGIN;
4+
5+
# MIME type sniffing security protection
6+
# There are very few edge cases where you wouldn't want this enabled.
7+
add_header X-Content-Type-Options nosniff;
8+
9+
# The X-XSS-Protection header is used by Internet Explorer version 8+
10+
# The header instructs IE to enable its inbuilt anti-cross-site scripting filter.
11+
add_header X-XSS-Protection "1; mode=block";
12+
13+
# with Content Security Policy (CSP) enabled (and a browser that supports it (http://caniuse.com/#feat=contentsecuritypolicy),
14+
# you can tell the browser that it can only download content from the domains you explicitly allow
15+
# CSP can be quite difficult to configure, and cause real issues if you get it wrong
16+
# There is website that helps you generate a policy here http://cspisawesome.com/
17+
# add_header Content-Security-Policy "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' https://www.google-analytics.com;";

directive-only/no-transform.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Prevent mobile network providers from modifying your site
2+
#
3+
# (!) If you are using `ngx_pagespeed`, please note that setting
4+
# the `Cache-Control: no-transform` response header will prevent
5+
# `PageSpeed` from rewriting `HTML` files, and, if
6+
# `pagespeed DisableRewriteOnNoTransform off` is not used, also
7+
# from rewriting other resources.
8+
#
9+
# https://developers.google.com/speed/pagespeed/module/configuration#notransform
10+
11+
add_header "Cache-Control" "no-transform";

directive-only/spdy.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Nginx's spdy module is compiled by default from 1.6
2+
# SPDY only works on HTTPS connections
3+
4+
# Inform browser of SPDY availability
5+
add_header Alternate-Protocol 443:npn-spdy/3;
6+
7+
# Adjust connection keepalive for SPDY clients:
8+
spdy_keepalive_timeout 300s; # up from 180 secs default
9+
10+
# enable SPDY header compression
11+
spdy_headers_comp 6;

directive-only/ssl-stapling.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# OCSP stapling...
2+
ssl_stapling on;
3+
ssl_stapling_verify on;
4+
5+
#trusted cert must be made up of your intermediate certificate followed by root certificate
6+
#ssl_trusted_certificate /path/to/ca.crt;
7+
8+
resolver 8.8.8.8 8.8.4.4 216.146.35.35 216.146.36.36 valid=60s;
9+
resolver_timeout 2s;

directive-only/ssl.conf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Protect against the BEAST and POODLE attacks by not using SSLv3 at all. If you need to support older browsers (IE6) you may need to add
2+
# SSLv3 to the list of protocols below.
3+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
4+
5+
# Ciphers set to best allow protection from Beast, while providing forwarding secrecy, as defined by Mozilla (Intermediate Set) - https://wiki.mozilla.org/Security/Server_Side_TLS#Nginx
6+
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
7+
ssl_prefer_server_ciphers on;
8+
9+
# Optimize SSL by caching session parameters for 10 minutes. This cuts down on the number of expensive SSL handshakes.
10+
# The handshake is the most CPU-intensive operation, and by default it is re-negotiated on every new/parallel connection.
11+
# By enabling a cache (of type "shared between all Nginx workers"), we tell the client to re-use the already negotiated state.
12+
# Further optimization can be achieved by raising keepalive_timeout, but that shouldn't be done unless you serve primarily HTTPS.
13+
ssl_session_cache shared:SSL:10m; # a 1mb cache can hold about 4000 sessions, so we can hold 40000 sessions
14+
ssl_session_timeout 24h;
15+
16+
# SSL buffer size was added in 1.5.9
17+
#ssl_buffer_size 1400; # 1400 bytes to fit in one MTU
18+
19+
# Session tickets appeared in version 1.5.9
20+
#
21+
# nginx does not auto-rotate session ticket keys: only a HUP / restart will do so and
22+
# when a restart is performed the previous key is lost, which resets all previous
23+
# sessions. The fix for this is to setup a manual rotation mechanism:
24+
# http://trac.nginx.org/nginx/changeset/1356a3b9692441e163b4e78be4e9f5a46c7479e9/nginx
25+
#
26+
# Note that you'll have to define and rotate the keys securely by yourself. In absence
27+
# of such infrastructure, consider turning off session tickets:
28+
#ssl_session_tickets off;
29+
30+
# Use a higher keepalive timeout to reduce the need for repeated handshakes
31+
keepalive_timeout 300s; # up from 75 secs default
32+
33+
# HSTS (HTTP Strict Transport Security)
34+
# This header tells browsers to cache the certificate for a year and to connect exclusively via HTTPS.
35+
#add_header Strict-Transport-Security "max-age=31536000;";
36+
# This version tells browsers to treat all subdomains the same as this site and to load exclusively over HTTPS
37+
#add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
38+
39+
# This default SSL certificate will be served whenever the client lacks support for SNI (Server Name Indication).
40+
# Make it a symlink to the most important certificate you have, so that users of IE 8 and below on WinXP can see your main site without SSL errors.
41+
#ssl_certificate /etc/nginx/default_ssl.crt;
42+
#ssl_certificate_key /etc/nginx/default_ssl.key;
43+
44+
# Consider using OCSP Stapling as shown in ssl-stapling.conf

directive-only/x-ua-compatible.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Force the latest IE version
2+
add_header "X-UA-Compatible" "IE=Edge";

location/cache-busting.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Built-in filename-based cache busting
2+
3+
# https://github.com/h5bp/html5-boilerplate/blob/5370479476dceae7cc3ea105946536d6bc0ee468/.htaccess#L403
4+
# This will route all requests for /css/style.20120716.css to /css/style.css
5+
# Read also this: github.com/h5bp/html5-boilerplate/wiki/cachebusting
6+
# This is not included by default, because it'd be better if you use the build
7+
# script to manage the file names.
8+
location ~* (.+)\.(?:\d+)\.(js|css|png|jpg|jpeg|gif)$ {
9+
try_files $uri $1.$2;
10+
}

location/cross-domain-fonts.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Cross domain webfont access
2+
location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
3+
include /etc/nginx/directive-only/cross-domain-insecure.conf;
4+
5+
# Also, set cache rules for webfonts.
6+
#
7+
# See http://wiki.nginx.org/HttpCoreModule#location
8+
# And https://github.com/h5bp/server-configs/issues/85
9+
# And https://github.com/h5bp/server-configs/issues/86
10+
expires 1M;
11+
access_log off;
12+
add_header Cache-Control "public";
13+
}

location/expires.conf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Expire rules for static content
2+
3+
# No default expire rule. This config mirrors that of apache as outlined in the
4+
# html5-boilerplate .htaccess file. However, nginx applies rules by location,
5+
# the apache rules are defined by type. A consequence of this difference is that
6+
# if you use no file extension in the url and serve html, with apache you get an
7+
# expire time of 0s, with nginx you'd get an expire header of one month in the
8+
# future (if the default expire rule is 1 month). Therefore, do not use a
9+
# default expire rule with nginx unless your site is completely static
10+
11+
# cache.appcache, your document html and data
12+
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
13+
expires -1;
14+
access_log /var/log/nginx/static.log;
15+
}
16+
17+
# Feed
18+
location ~* \.(?:rss|atom)$ {
19+
expires 1h;
20+
add_header Cache-Control "public";
21+
}
22+
23+
# Media: images, icons, video, audio, HTC
24+
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
25+
expires 1M;
26+
access_log off;
27+
add_header Cache-Control "public";
28+
}
29+
30+
# CSS and Javascript
31+
location ~* \.(?:css|js)$ {
32+
expires 1y;
33+
access_log off;
34+
add_header Cache-Control "public";
35+
}
36+
37+
# WebFonts
38+
# If you are NOT using cross-domain-fonts.conf, uncomment the following directive
39+
# location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
40+
# expires 1M;
41+
# access_log off;
42+
# add_header Cache-Control "public";
43+
# }

location/protect-system-files.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Prevent clients from accessing hidden files (starting with a dot)
2+
# This is particularly important if you store .htpasswd files in the site hierarchy
3+
# Access to `/.well-known/` is allowed.
4+
# https://www.mnot.net/blog/2010/04/07/well-known
5+
# https://tools.ietf.org/html/rfc5785
6+
location ~* /\.(?!well-known\/) {
7+
deny all;
8+
}
9+
10+
# Prevent clients from accessing to backup/config/source files
11+
location ~* (?:\.(?:bak|conf|dist|fla|in[ci]|log|psd|sh|sql|sw[op])|~)$ {
12+
deny all;
13+
}

0 commit comments

Comments
 (0)