2016-01-23 14:45:07 +01:00
|
|
|
# Configuration File - Nginx Server Configs
|
2018-11-25 22:07:01 +01:00
|
|
|
# https://nginx.org/en/docs/
|
2013-03-29 22:49:16 +01:00
|
|
|
|
2016-01-23 14:45:07 +01:00
|
|
|
# Run as a unique, less privileged user for security reasons.
|
2017-05-06 18:30:09 +02:00
|
|
|
# Default: nobody nobody
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/ngx_core_module.html#user
|
2019-02-04 14:09:06 +01:00
|
|
|
# https://en.wikipedia.org/wiki/Principle_of_least_privilege
|
|
|
|
user www-data;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
# Sets the worker threads to the number of CPU cores available in the system for
|
|
|
|
# best performance. Should be > the number of CPU cores.
|
2016-01-23 14:45:07 +01:00
|
|
|
# Maximum number of connections = worker_processes * worker_connections
|
2017-05-06 18:30:09 +02:00
|
|
|
# Default: 1
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/ngx_core_module.html#worker_processes
|
2015-08-30 03:05:56 +02:00
|
|
|
worker_processes auto;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2016-01-23 14:45:07 +01:00
|
|
|
# Maximum number of open files per worker process.
|
|
|
|
# Should be > worker_connections.
|
2017-05-06 18:30:09 +02:00
|
|
|
# Default: no limit
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile
|
2010-12-15 06:12:17 +01:00
|
|
|
worker_rlimit_nofile 8192;
|
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
# Provides the configuration file context in which the directives that affect
|
|
|
|
# connection processing are specified.
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/ngx_core_module.html#events
|
2010-12-15 06:12:17 +01:00
|
|
|
events {
|
2018-11-23 17:14:15 +01:00
|
|
|
|
2016-01-23 14:45:07 +01:00
|
|
|
# If you need more connections than this, you start optimizing your OS.
|
2019-05-15 18:38:05 +02:00
|
|
|
# That's probably the point at which you hire people who are smarter than you
|
|
|
|
# as this is *a lot* of requests.
|
2016-01-23 14:45:07 +01:00
|
|
|
# Should be < worker_rlimit_nofile.
|
2017-05-06 18:30:09 +02:00
|
|
|
# Default: 512
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/ngx_core_module.html#worker_connections
|
2013-01-12 21:16:02 +01:00
|
|
|
worker_connections 8000;
|
2018-11-23 17:14:15 +01:00
|
|
|
|
2010-12-15 06:12:17 +01:00
|
|
|
}
|
|
|
|
|
2016-01-23 14:45:07 +01:00
|
|
|
# Log errors and warnings to this file
|
2019-05-15 18:38:05 +02:00
|
|
|
# This is only used when you don't override it on a `server` level
|
2017-05-06 18:30:09 +02:00
|
|
|
# Default: logs/error.log error
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/ngx_core_module.html#error_log
|
2019-02-04 14:09:06 +01:00
|
|
|
error_log /var/log/nginx/error.log warn;
|
2016-01-23 14:45:07 +01:00
|
|
|
|
|
|
|
# The file storing the process ID of the main process
|
2018-11-23 17:14:15 +01:00
|
|
|
# Default: logs/nginx.pid
|
|
|
|
# https://nginx.org/en/docs/ngx_core_module.html#pid
|
|
|
|
pid /var/run/nginx.pid;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2021-09-15 00:00:42 +02:00
|
|
|
# Include files in the custom.d folder.
|
|
|
|
# Custom configuration and value files should be placed in the custom.d
|
|
|
|
# folder.
|
|
|
|
# The configurations should be disabled by prefixing files with a dot.
|
|
|
|
include custom.d/*.conf;
|
|
|
|
|
2010-12-15 06:12:17 +01:00
|
|
|
http {
|
2013-03-29 22:49:16 +01:00
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
# Hide Nginx version information.
|
2018-11-23 17:14:15 +01:00
|
|
|
include h5bp/security/server_software_information.conf;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
# Specify media (MIME) types for files.
|
2019-02-10 20:40:50 +01:00
|
|
|
include h5bp/media_types/media_types.conf;
|
2017-05-06 18:30:09 +02:00
|
|
|
|
2019-02-10 20:40:50 +01:00
|
|
|
# Set character encodings.
|
|
|
|
include h5bp/media_types/character_encodings.conf;
|
2014-01-16 10:09:05 +01:00
|
|
|
|
2016-01-23 14:45:07 +01:00
|
|
|
# Include $http_x_forwarded_for within default format used in log files
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
|
2013-02-24 21:44:12 +01:00
|
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
|
|
'$status $body_bytes_sent "$http_referer" '
|
|
|
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2016-01-23 14:45:07 +01:00
|
|
|
# Log access to this file
|
2019-05-15 18:38:05 +02:00
|
|
|
# This is only used when you don't override it on a `server` level
|
2017-05-06 18:30:09 +02:00
|
|
|
# Default: logs/access.log combined
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
|
2019-02-04 14:09:06 +01:00
|
|
|
access_log /var/log/nginx/access.log main;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2016-01-23 14:45:07 +01:00
|
|
|
# How long to allow each connection to stay idle.
|
|
|
|
# Longer values are better for each individual client, particularly for SSL,
|
|
|
|
# but means that worker connections are tied up longer.
|
2017-05-06 18:30:09 +02:00
|
|
|
# Default: 75s
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout
|
2016-01-23 14:59:22 +01:00
|
|
|
keepalive_timeout 20s;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
# Speed up file transfers by using `sendfile()` to copy directly between
|
|
|
|
# descriptors rather than using `read()`/`write()``.
|
|
|
|
# For performance reasons, on FreeBSD systems w/ ZFS this option should be
|
|
|
|
# disabled as ZFS's ARC caches frequently used files in RAM by default.
|
2017-05-06 18:30:09 +02:00
|
|
|
# Default: off
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/http/ngx_http_core_module.html#sendfile
|
|
|
|
sendfile on;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
# Don't send out partial frames; this increases throughput since TCP frames
|
|
|
|
# are filled up before being sent out.
|
2017-05-06 18:30:09 +02:00
|
|
|
# Default: off
|
2018-11-23 17:14:15 +01:00
|
|
|
# https://nginx.org/en/docs/http/ngx_http_core_module.html#tcp_nopush
|
|
|
|
tcp_nopush on;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2016-01-23 14:45:07 +01:00
|
|
|
# Enable gzip compression.
|
2018-11-23 17:14:15 +01:00
|
|
|
include h5bp/web_performance/compression.conf;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2019-02-10 20:46:58 +01:00
|
|
|
# Specify file cache expiration.
|
|
|
|
include h5bp/web_performance/cache_expiration.conf;
|
|
|
|
|
2022-11-03 23:50:13 +01:00
|
|
|
# Add Cache-Control.
|
|
|
|
# h5bp/web_performance/cache-control.conf
|
|
|
|
map $sent_http_content_type $cache_control {
|
|
|
|
default "public, immutable, stale-while-revalidate";
|
|
|
|
|
|
|
|
# No content
|
|
|
|
"" "no-store";
|
|
|
|
|
|
|
|
# Manifest files
|
|
|
|
~*application/manifest\+json "public";
|
|
|
|
~*text/cache-manifest ""; # `no-cache` set by `expire`
|
|
|
|
|
|
|
|
# Assets
|
|
|
|
~*image/svg\+xml "public, immutable, stale-while-revalidate";
|
|
|
|
|
|
|
|
# Data interchange
|
|
|
|
~*application/(atom|rdf|rss)\+xml "public, stale-while-revalidate";
|
|
|
|
|
|
|
|
# Documents
|
|
|
|
~*text/html "private, must-revalidate";
|
|
|
|
~*text/markdown "private, must-revalidate";
|
|
|
|
~*text/calendar "private, must-revalidate";
|
|
|
|
|
|
|
|
# Data
|
|
|
|
~*json ""; # `no-cache` set by `expire`
|
|
|
|
~*xml ""; # `no-cache` set by `expire`
|
|
|
|
}
|
|
|
|
|
2019-02-10 20:46:58 +01:00
|
|
|
# Add X-Frame-Options for HTML documents.
|
|
|
|
# h5bp/security/x-frame-options.conf
|
|
|
|
map $sent_http_content_type $x_frame_options {
|
2019-03-09 02:44:10 +01:00
|
|
|
~*text/html DENY;
|
2019-02-10 20:46:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add Content-Security-Policy for HTML documents.
|
|
|
|
# h5bp/security/content-security-policy.conf
|
|
|
|
map $sent_http_content_type $content_security_policy {
|
2021-06-28 14:28:44 +02:00
|
|
|
~*text/(html|javascript)|application/pdf|xml "default-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'; object-src 'none'; upgrade-insecure-requests";
|
2019-02-10 20:46:58 +01:00
|
|
|
}
|
|
|
|
|
2021-06-28 14:29:20 +02:00
|
|
|
# Add Permissions-Policy for HTML documents.
|
|
|
|
# h5bp/security/permissions-policy.conf
|
|
|
|
map $sent_http_content_type $permissions_policy {
|
|
|
|
~*text/(html|javascript)|application/pdf|xml "accelerometer=(),autoplay=(),camera=(),display-capture=(),document-domain=(),encrypted-media=(),fullscreen=(),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),midi=(),payment=(),picture-in-picture=(),publickey-credentials-get=(),screen-wake-lock=(),sync-xhr=(self),usb=(),web-share=(),xr-spatial-tracking=()";
|
|
|
|
}
|
|
|
|
|
2019-02-13 14:31:53 +01:00
|
|
|
# Add Referrer-Policy for HTML documents.
|
2021-06-28 14:29:20 +02:00
|
|
|
# h5bp/security/referrer-policy.conf
|
2019-02-13 14:31:53 +01:00
|
|
|
map $sent_http_content_type $referrer_policy {
|
2020-04-12 23:29:41 +02:00
|
|
|
~*text/(css|html|javascript)|application\/pdf|xml "strict-origin-when-cross-origin";
|
2019-02-13 14:31:53 +01:00
|
|
|
}
|
|
|
|
|
2021-06-28 14:46:32 +02:00
|
|
|
# Add Cross-Origin-Policies for HTML documents.
|
|
|
|
# h5bp/security/cross-origin-policy.conf
|
|
|
|
# Cross-Origin-Embedder-Policy
|
|
|
|
map $sent_http_content_type $coep_policy {
|
2021-06-29 00:43:34 +02:00
|
|
|
~*text/(html|javascript)|application/pdf|xml "require-corp";
|
2021-06-28 14:46:32 +02:00
|
|
|
}
|
|
|
|
# Cross-Origin-Opener-Policy
|
|
|
|
map $sent_http_content_type $coop_policy {
|
2021-06-29 00:43:34 +02:00
|
|
|
~*text/(html|javascript)|application/pdf|xml "same-origin";
|
2021-06-28 14:46:32 +02:00
|
|
|
}
|
|
|
|
# Cross-Origin-Resource-Policy
|
|
|
|
map $sent_http_content_type $corp_policy {
|
2021-06-29 00:43:34 +02:00
|
|
|
~*text/(html|javascript)|application/pdf|xml "same-origin";
|
2021-06-28 14:46:32 +02:00
|
|
|
}
|
|
|
|
|
2019-02-10 20:46:58 +01:00
|
|
|
# Add Access-Control-Allow-Origin.
|
|
|
|
# h5bp/cross-origin/requests.conf
|
|
|
|
map $sent_http_content_type $cors {
|
|
|
|
# Images
|
2022-12-05 14:21:28 +01:00
|
|
|
~*image/ "*";
|
2019-02-10 20:46:58 +01:00
|
|
|
|
|
|
|
# Web fonts
|
2019-03-09 02:44:10 +01:00
|
|
|
~*font/ "*";
|
|
|
|
~*application/vnd.ms-fontobject "*";
|
|
|
|
~*application/x-font-ttf "*";
|
|
|
|
~*application/font-woff "*";
|
|
|
|
~*application/x-font-woff "*";
|
|
|
|
~*application/font-woff2 "*";
|
2019-02-10 20:46:58 +01:00
|
|
|
}
|
|
|
|
|
2019-02-01 13:04:01 +01:00
|
|
|
# Include files in the conf.d folder.
|
2019-05-15 18:38:05 +02:00
|
|
|
# `server` configuration files should be placed in the conf.d folder.
|
2019-02-01 13:04:01 +01:00
|
|
|
# The configurations should be disabled by prefixing files with a dot.
|
|
|
|
include conf.d/*.conf;
|
2018-11-23 17:14:15 +01:00
|
|
|
|
2010-12-15 06:12:17 +01:00
|
|
|
}
|