bunkerized-nginx/README.md

1333 lines
52 KiB
Markdown
Raw Normal View History

2019-08-20 23:20:48 +02:00
# bunkerized-nginx
2020-09-01 23:33:21 +02:00
<img src="https://github.com/bunkerity/bunkerized-nginx/blob/master/logo.png?raw=true" width="425" />
2020-12-30 17:57:00 +01:00
<img src="https://img.shields.io/badge/bunkerized--nginx-1.2.2-blue" /> <img src="https://img.shields.io/badge/nginx-1.18.0-blue" /> <img src="https://img.shields.io/github/last-commit/bunkerity/bunkerized-nginx" /> <a href="https://matrix.to/#/#bunkerized-nginx:matrix.org"><img src="https://img.shields.io/badge/matrix%20chat-%23bunkerized--nginx%3Amatrix.org-blue" /></a> <img src="https://img.shields.io/github/workflow/status/bunkerity/bunkerized-nginx/Automatic%20test?label=automatic%20test" /> <img src="https://img.shields.io/docker/cloud/build/bunkerity/bunkerized-nginx" />
2020-10-10 16:46:23 +02:00
nginx Docker image secure by default.
Avoid the hassle of following security best practices each time you need a web server or reverse proxy. Bunkerized-nginx provides generic security configs, settings and tools so you don't need to do it yourself.
2020-09-01 23:33:21 +02:00
2020-06-07 10:13:06 +02:00
Non-exhaustive list of features :
2019-08-20 23:50:42 +02:00
- HTTPS support with transparent Let's Encrypt automation
2020-10-30 11:39:01 +01:00
- State-of-the-art web security : HTTP security headers, prevent leaks, TLS hardening, ...
2019-08-20 23:50:42 +02:00
- Integrated ModSecurity WAF with the OWASP Core Rule Set
- Automatic ban of strange behaviors with fail2ban
2020-10-17 17:02:42 +02:00
- Antibot challenge through cookie, javascript, captcha or recaptcha v3
2020-10-04 21:20:57 +02:00
- Block TOR, proxies, bad user-agents, countries, ...
- Block known bad IP with DNSBL and CrowdSec
2020-10-02 12:01:30 +02:00
- Prevent bruteforce attacks with rate limiting
2020-04-13 22:17:17 +02:00
- Detect bad files with ClamAV
2020-12-30 17:57:00 +01:00
- Easy to configure with environment variables or web UI
2020-12-07 21:20:13 +01:00
- Automatic configuration with container labels
2019-08-20 23:50:42 +02:00
2020-10-16 18:08:17 +02:00
Fooling automated tools/scanners :
2020-10-17 17:02:42 +02:00
<img src="https://github.com/bunkerity/bunkerized-nginx/blob/master/demo.gif?raw=true" />
2020-10-16 18:08:17 +02:00
2020-06-07 10:13:06 +02:00
# Table of contents
- [bunkerized-nginx](#bunkerized-nginx)
- [Table of contents](#table-of-contents)
- [Live demo](#live-demo)
- [Quickstart guide](#quickstart-guide)
* [Run HTTP server with default settings](#run-http-server-with-default-settings)
2020-10-10 17:05:44 +02:00
* [In combination with PHP](#in-combination-with-php)
2020-10-22 23:23:30 +02:00
* [Run HTTPS server with automated Let's Encrypt](#run-https-server-with-automated-lets-encrypt)
2020-10-17 17:02:42 +02:00
* [As a reverse proxy](#as-a-reverse-proxy)
2020-11-22 23:39:01 +01:00
* [Behind a reverse proxy](#behind-a-reverse-proxy)
* [Multisite](#multisite)
2020-12-07 21:20:13 +01:00
* [Automatic configuration](#automatic-configuration)
2020-12-30 21:22:18 +01:00
* [Web UI](#web-ui)
2020-10-17 17:02:42 +02:00
* [Antibot challenge](#antibot-challenge)
- [Tutorials and examples](#tutorials-and-examples)
2020-06-07 10:13:06 +02:00
- [List of environment variables](#list-of-environment-variables)
* [nginx](#nginx)
2020-10-10 17:05:44 +02:00
+ [Misc](#misc)
+ [Information leak](#information-leak)
+ [Custom error pages](#custom-error-pages)
+ [HTTP basic authentication](#http-basic-authentication)
2020-10-17 17:02:42 +02:00
+ [Reverse proxy](#reverse-proxy)
2020-11-22 23:39:01 +01:00
+ [Compression](#compression)
+ [Cache](#cache)
2020-06-07 10:13:06 +02:00
* [HTTPS](#https)
2020-11-22 23:39:01 +01:00
+ [Let's Encrypt](#lets-encrypt)
2020-10-10 17:05:44 +02:00
+ [HTTP](#http)
+ [Custom certificate](#custom-certificate)
+ [Self-signed certificate](#self-signed-certificate)
2020-11-23 00:05:22 +01:00
+ [Misc](#misc-1)
2020-06-07 10:13:06 +02:00
* [ModSecurity](#modsecurity)
* [Security headers](#security-headers)
* [Blocking](#blocking)
2020-10-17 17:02:42 +02:00
+ [Antibot](#antibot)
2020-11-22 23:39:01 +01:00
+ [External blacklists](#external-blacklists)
2020-10-10 17:05:44 +02:00
+ [DNSBL](#dnsbl)
+ [CrowdSec](#crowdsec)
2020-10-10 17:05:44 +02:00
+ [Custom whitelisting](#custom-whitelisting)
+ [Custom blacklisting](#custom-blacklisting)
+ [Requests limiting](#requests-limiting)
+ [Countries](#countries)
2020-06-07 10:13:06 +02:00
* [PHP](#php)
* [Fail2ban](#fail2ban)
* [ClamAV](#clamav)
2020-11-23 00:05:22 +01:00
* [Misc](#misc-2)
2020-10-10 17:05:44 +02:00
- [Include custom configurations](#include-custom-configurations)
2020-11-22 23:39:01 +01:00
- [Cache data](#cache-data)
2020-06-07 10:13:06 +02:00
# Live demo
2020-06-02 22:39:17 +02:00
You can find a live demo at https://demo-nginx.bunkerity.com.
2020-06-07 10:13:06 +02:00
# Quickstart guide
2019-11-22 14:21:06 +01:00
2020-06-07 10:13:06 +02:00
## Run HTTP server with default settings
2019-11-22 14:21:06 +01:00
```shell
2020-11-22 23:39:01 +01:00
docker run -p 80:8080 -v /path/to/web/files:/www:ro bunkerity/bunkerized-nginx
2019-11-22 14:21:06 +01:00
```
2020-04-13 22:17:17 +02:00
Web files are stored in the /www directory, the container will serve files from there.
2019-11-22 14:21:06 +01:00
2020-10-10 16:46:23 +02:00
## In combination with PHP
```shell
docker network create mynet
2020-11-22 23:39:01 +01:00
docker run --network mynet \
-p 80:8080 \
2020-11-23 00:05:22 +01:00
-v /path/to/web/files:/www:ro \
2020-11-22 23:39:01 +01:00
-e REMOTE_PHP=myphp \
-e REMOTE_PHP_PATH=/app \
bunkerity/bunkerized-nginx
docker run --network mynet \
2020-12-07 21:20:13 +01:00
--name myphp \
2020-11-22 23:39:01 +01:00
-v /path/to/web/files:/app \
php:fpm
2020-10-10 16:46:23 +02:00
```
The `REMOTE_PHP` environment variable lets you define the address of a remote PHP-FPM instance that will execute the .php files. `REMOTE_PHP_PATH` must be set to the directory where the PHP container will find the files.
2020-06-07 10:13:06 +02:00
## Run HTTPS server with automated Let's Encrypt
2020-11-22 23:39:01 +01:00
2019-11-22 14:21:06 +01:00
```shell
2020-11-22 23:39:01 +01:00
docker run -p 80:8080 \
-p 443:8443 \
-v /path/to/web/files:/www:ro \
-v /where/to/save/certificates:/etc/letsencrypt \
-e SERVER_NAME=www.yourdomain.com \
-e AUTO_LETS_ENCRYPT=yes \
-e REDIRECT_HTTP_TO_HTTPS=yes \
bunkerity/bunkerized-nginx
2019-11-22 14:21:06 +01:00
```
2020-04-13 22:17:17 +02:00
Certificates are stored in the /etc/letsencrypt directory, you should save it on your local drive.
2020-10-17 17:02:42 +02:00
If you don't want your webserver to listen on HTTP add the environment variable `LISTEN_HTTP` with a *no* value. But Let's Encrypt needs the port 80 to be opened so redirecting the port is mandatory.
2020-04-13 22:17:17 +02:00
Here you have three environment variables :
2020-08-01 17:47:06 +02:00
- `SERVER_NAME` : define the FQDN of your webserver, this is mandatory for Let's Encrypt (www.yourdomain.com should point to your IP address)
- `AUTO_LETS_ENCRYPT` : enable automatic Let's Encrypt creation and renewal of certificates
- `REDIRECT_HTTP_TO_HTTPS` : enable HTTP to HTTPS redirection
2020-04-13 22:17:17 +02:00
2020-11-22 23:39:01 +01:00
## As a reverse proxy
```shell
docker run -p 80:8080 \
-e USE_REVERSE_PROXY=yes \
-e REVERSE_PROXY_URL=/ \
-e REVERSE_PROXY_HOST=http://myserver:8080 \
bunkerity/bunkerized-nginx
```
This is a simple reverse proxy to a unique application. If you have more than one application you can add more REVERSE_PROXY_URL/REVERSE_PROXY_HOST by appending a suffix number like this :
```shell
docker run -p 80:8080 \
-e USE_REVERSE_PROXY=yes \
-e REVERSE_PROXY_URL_1=/app1/ \
-e REVERSE_PROXY_HOST_1=http://myapp1:3000/ \
-e REVERSE_PROXY_URL_2=/app2/ \
-e REVERSE_PROXY_HOST_2=http://myapp2:3000/ \
bunkerity/bunkerized-nginx
```
2020-10-17 17:02:42 +02:00
## Behind a reverse proxy
2020-11-22 23:39:01 +01:00
2020-10-17 17:02:42 +02:00
```shell
2020-11-22 23:39:01 +01:00
docker run -p 80:8080 \
-v /path/to/web/files:/www \
-e PROXY_REAL_IP=yes \
bunkerity/bunkerized-nginx
2020-10-17 17:02:42 +02:00
```
The `PROXY_REAL_IP` environment variable, when set to *yes*, activates the [ngx_http_realip_module](https://nginx.org/en/docs/http/ngx_http_realip_module.html) to get the real client IP from the reverse proxy.
See [this section](#reverse-proxy) if you need to tweak some values (trusted ip/network, header, ...).
2020-11-22 23:39:01 +01:00
## Multisite
By default, bunkerized-nginx will only create one server block. When setting the `MULTISITE` environment variable to *yes*, one server block will be created for each host defined in the `SERVER_NAME` environment variable.
You can set/override values for a specific server by prefixing the environment variable with one of the server name previously defined.
2020-04-13 22:17:17 +02:00
```shell
2020-11-22 23:39:01 +01:00
docker run -p 80:8080 \
-p 443:8443 \
-v /where/to/save/certificates:/etc/letsencrypt \
-e SERVER_NAME=app1.domain.com app2.domain.com \
-e MULTISITE=yes \
-e AUTO_LETS_ENCRYPT=yes \
-e REDIRECT_HTTP_TO_HTTPS=yes \
-e USE_REVERSE_PROXY=yes \
2020-12-10 21:25:39 +01:00
-e app1.domain.com_REVERSE_PROXY_URL=/ \
-e app1.domain.com_REVERSE_PROXY_HOST=http://myapp1:8000 \
-e app2.domain.com_REVERSE_PROXY_URL=/ \
-e app2.domain.com_REVERSE_PROXY_HOST=http://myapp2:8000 \
2020-11-22 23:39:01 +01:00
bunkerity/bunkerized-nginx
2020-04-13 22:17:17 +02:00
```
2020-11-22 23:39:01 +01:00
The `USE_REVERSE_PROXY` is a *global* variable that will be applied to each server block. Whereas the `app1.domain.com_*` and `app2.domain.com_*` will only be applied to the app1.domain.com and app2.domain.com server block respectively.
When serving files, the web root directory should contains subdirectories named as the servers defined in the `SERVER_NAME` environment variable. Here is an example :
2020-04-13 22:17:17 +02:00
```shell
2020-11-22 23:39:01 +01:00
docker run -p 80:8080 \
-p 443:8443 \
-v /where/to/save/certificates:/etc/letsencrypt \
-v /where/are/web/files:/www:ro \
-e SERVER_NAME=app1.domain.com app2.domain.com \
-e MULTISITE=yes \
-e AUTO_LETS_ENCRYPT=yes \
-e REDIRECT_HTTP_TO_HTTPS=yes \
-e app1.domain.com_REMOTE_PHP=php1 \
-e app1.domain.com_REMOTE_PHP_PATH=/app \
-e app2.domain.com_REMOTE_PHP=php2 \
-e app2.domain.com_REMOTE_PHP_PATH=/app \
bunkerity/bunkerized-nginx
2020-04-13 22:17:17 +02:00
```
2020-11-22 23:39:01 +01:00
The */where/are/web/files* directory should have a structure like this :
```shell
/where/are/web/files
├── app1.domain.com
│   └── index.php
│   └── ...
└── app2.domain.com
└── index.php
└── ...
```
2019-11-22 14:21:06 +01:00
2020-12-07 21:20:13 +01:00
## Automatic configuration
2020-12-30 17:57:00 +01:00
The downside of using environment variables is that you need to recreate a new container each time you want to add or remove a web service. An alternative is to use the *bunkerized-nginx-autoconf* image which listens for Docker events and "automagically" generates the configuration.
2020-12-07 21:20:13 +01:00
2020-12-30 17:57:00 +01:00
First we need a volume that will store the configurations :
```shell
docker volume create nginx_conf
```
Then we run bunkerized-nginx with the `bunkerized-nginx.AUTOCONF` label, mount the created volume at /etc/nginx and set some default configurations for our services (e.g. : automatic Let's Encrypt and HTTP to HTTPS redirect) :
2020-12-07 21:20:13 +01:00
```shell
docker network create mynet
docker run -p 80:8080 \
-p 443:8443 \
--network mynet \
-v /where/to/save/certificates:/etc/letsencrypt \
-v /where/are/web/files:/www:ro \
2020-12-30 17:57:00 +01:00
-v nginx_conf:/etc/nginx \
2020-12-07 21:20:13 +01:00
-e SERVER_NAME= \
-e MULTISITE=yes \
-e AUTO_LETS_ENCRYPT=yes \
-e REDIRECT_HTTP_TO_HTTPS=yes \
2020-12-30 17:57:00 +01:00
-l bunkerized.nginx.AUTOCONF \
2020-12-07 21:20:13 +01:00
bunkerity/bunkerized-nginx
```
2020-12-30 21:22:18 +01:00
When setting `SERVER_NAME` to nothing bunkerized-nginx won't create any server block (in case we only want automatic configuration).
2020-12-07 21:20:13 +01:00
2020-12-30 21:22:18 +01:00
Once bunkerized-nginx is created, let's setup the autoconf container :
2020-12-30 17:57:00 +01:00
```shell
docker run -v /var/run/docker.sock:/var/run/docker.sock:ro \
-v nginx_conf:/etc/nginx \
bunkerity/bunkerized-nginx-autoconf
```
We can now create a new container and use labels to dynamically configure bunkerized-nginx. Labels for automatic configuration are the same as environment variables but with the "bunkerized-nginx." prefix.
Here is a PHP example :
2020-12-07 21:20:13 +01:00
```shell
docker run --network mynet \
--name myapp \
-v /where/are/web/files/app.domain.com:/app \
-l bunkerized-nginx.SERVER_NAME=app.domain.com \
-l bunkerized-nginx.REMOTE_PHP=myapp \
-l bunkerized-nginx.REMOTE_PHP_PATH=/app \
2020-12-30 17:57:00 +01:00
php:fpm
```
And a reverse proxy example :
```shell
docker run --network mynet \
--name anotherapp \
-l bunkerized-nginx.SERVER_NAME=app2.domain.com \
-l bunkerized-nginx.USE_REVERSE_PROXY=yes \
-l bunkerized-nginx.REVERSE_PROXY_URL=/ \
-l bunkerized-nginx.REVERSE_PROXY_HOST=http://anotherapp
tutum/hello-world
```
## Web UI
**This feature exposes, for now, a security risk because you need to mount the docker socket inside a container exposing a web application. You can test it but you should not use it in servers facing the internet.**
A dedicated image, *bunkerized-nginx-ui*, lets you manage bunkerized-nginx instances and services configurations through a web user interface. This feature is still in beta, feel free to open a new issue if you find a bug and/or you have an idea to improve it.
First we need a volume that will store the configurations :
```shell
docker volume create nginx_conf
```
Then, we can create the bunkerized-nginx instance with the `bunkerized-nginx.UI` label and a reverse proxy configuration for our web UI :
```shell
docker network create mynet
docker run -p 80:8080 \
-p 443:8443 \
--network mynet \
-v nginx_conf:/etc/nginx \
-v /where/are/web/files:/www:ro \
-v /where/to/save/certificates:/etc/letsencrypt \
-e SERVER_NAME=admin.domain.com \
-e MULTISITE=yes \
-e AUTO_LETS_ENCRYPT=yes \
-e REDIRECT_HTTP_TO_HTTPS=yes \
-e DISABLE_DEFAULT_SERVER=yes \
-e admin.domain.com_SERVE_FILES=no \
-e admin.domain.com_USE_AUTH_BASIC=yes \
-e admin.domain.com_AUTH_BASIC_USER=admin \
-e admin.domain.com_AUTH_BASIC_PASSWORD=password \
-e admin.domain.com_USE_REVERSE_PROXY=yes \
-e admin.domain.com_REVERSE_PROXY_URL=/webui/ \
-e admin.domain.com_REVERSE_PROXY_HOST=http://myui:5000/ \
-l bunkerized-nginx.UI \
2020-12-07 21:20:13 +01:00
bunkerity/bunkerized-nginx
```
2020-12-30 17:57:00 +01:00
The `AUTH_BASIC` environment variables let you define a login/password that must be provided before accessing to the web UI. At the moment, there is no authentication mechanism integrated into bunkerized-nginx-ui.
2020-12-30 21:22:18 +01:00
We can now create the bunkerized-nginx-ui container that will host the web UI behind bunkerized-nginx :
2020-12-30 17:57:00 +01:00
```shell
docker run --network mynet \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v nginx_conf:/etc/nginx \
-e ABSOLUTE_URI=https://admin.domain.com/webui/ \
bunkerity/bunkerized-nginx-ui
```
2020-12-07 21:20:13 +01:00
2020-12-30 17:57:00 +01:00
After that, the web UI should be accessible from https://admin.domain.com/webui/.
2020-12-07 21:20:13 +01:00
2020-10-17 17:02:42 +02:00
## Antibot challenge
2020-11-22 23:39:01 +01:00
2020-10-17 17:02:42 +02:00
```shell
2020-10-27 22:05:49 +01:00
docker run -p 80:8080 -v /path/to/web/files:/www -e USE_ANTIBOT=captcha bunkerity/bunkerized-nginx
2020-10-17 17:02:42 +02:00
```
When `USE_ANTIBOT` is set to *captcha*, every users visiting your website must complete a captcha before accessing the pages. Others challenges are also available : *cookie*, *javascript* or *recaptcha* (more info [here](#antibot)).
# Tutorials and examples
2020-12-30 17:57:00 +01:00
You will find some docker-compose.yml examples in the [examples directory](https://github.com/bunkerity/bunkerized-nginx/tree/master/examples).
2020-06-07 10:13:06 +02:00
# List of environment variables
2019-11-22 14:21:06 +01:00
2020-06-07 10:13:06 +02:00
## nginx
2019-11-22 14:21:06 +01:00
2020-10-10 16:46:23 +02:00
### Misc
2020-11-22 23:39:01 +01:00
`MULTISITE`
Values : *yes* | *no*
Default value : *no*
Context : *global*
When set to *no*, only one server block will be generated. Otherwise one server per host defined in the `SERVER_NAME` environment variable will be generated.
Any environment variable tagged as *multisite* context can be used for a specific server block with the following format : *host_VARIABLE=value*. If the variable is used without the host prefix it will be applied to all the server blocks (but still can be overriden).
2020-10-10 16:46:23 +02:00
`SERVER_NAME`
Values : *&lt;first name&gt; &lt;second name&gt; ...*
Default value : *www.bunkerity.com*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-10 16:46:23 +02:00
Sets the host names of the webserver separated with spaces. This must match the Host header sent by clients.
2020-11-22 23:39:01 +01:00
Useful when used with `MULTISITE=yes` and/or `AUTO_LETSENCRYPT=yes` and/or `DISABLE_DEFAULT_SERVER=yes`.
2020-10-10 16:46:23 +02:00
`MAX_CLIENT_SIZE`
Values : *0* | *Xm*
Default value : *10m*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-10 16:46:23 +02:00
Sets the maximum body size before nginx returns a 413 error code.
Setting to 0 means "infinite" body size.
2019-11-22 14:21:06 +01:00
`ALLOWED_METHODS`
Values : *allowed HTTP methods separated with | char*
Default value : *GET|POST|HEAD*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2019-11-22 14:21:06 +01:00
Only the HTTP methods listed here will be accepted by nginx. If not listed, nginx will close the connection.
`DISABLE_DEFAULT_SERVER`
Values : *yes* | *no*
Default value : *no*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
If set to yes, nginx will only respond to HTTP request when the Host header match a FQDN specified in the `SERVER_NAME` environment variable.
2020-04-13 22:17:17 +02:00
For example, it will close the connection if a bot access the site with direct ip.
2019-11-22 14:21:06 +01:00
`SERVE_FILES`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-03 15:31:58 +01:00
If set to yes, nginx will serve files from /www directory within the container.
2020-12-07 21:20:13 +01:00
A use case to not serving files is when you setup bunkerized-nginx as a reverse proxy.
2020-01-03 15:31:58 +01:00
2020-10-18 01:41:29 +02:00
`DNS_RESOLVERS`
Values : *\<two IP addresses separated with a space\>*
2020-12-07 21:20:13 +01:00
Default value : *127.0.0.11*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-18 01:41:29 +02:00
The IP addresses of the DNS resolvers to use when performing DNS lookups.
2020-08-22 00:12:36 +02:00
`ROOT_FOLDER`
Values : *\<any valid path to web files\>
Default value : */www*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-08-30 21:40:13 +02:00
The default folder where nginx will search for web files. Don't change it unless you want to make your own image.
2020-08-22 00:12:36 +02:00
2020-12-07 21:20:13 +01:00
`LOG_FORMAT`
Values : *\<any values accepted by the log_format directive\>*
2020-12-30 21:22:18 +01:00
Default value : *$host $remote_addr - $remote_user \[$time_local\] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"*
2020-12-07 21:20:13 +01:00
Context : *global*
The log format used by nginx to generate logs. More info [here](http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format).
`HTTP_PORT`
Values : *\<any valid port greater than 1024\>*
Default value : *8080*
2020-11-22 23:39:01 +01:00
Context : *global*
The HTTP port number used by nginx and certbot inside the container.
`HTTPS_PORT`
Values : *\<any valid port greater than 1024\>*
Default value : *8443*
2020-11-22 23:39:01 +01:00
Context : *global*
The HTTPS port number used by nginx inside the container.
2020-10-10 16:46:23 +02:00
### Information leak
2020-01-03 15:31:58 +01:00
2020-10-10 16:46:23 +02:00
`SERVER_TOKENS`
Values : *on* | *off*
Default value : *off*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-10 16:46:23 +02:00
If set to on, nginx will display server version in Server header and default error pages.
2020-01-03 15:31:58 +01:00
2020-11-22 23:39:01 +01:00
`REMOVE_HEADERS`
Values : \<*list of headers separated with space*\>
Default value : *Server X-Powered-By X-AspNet-Version X-AspNetMvc-Version*
Context : *global*, *multisite*
List of header to remove when sending responses to clients.
2020-10-10 16:46:23 +02:00
### Custom error pages
`ERROR_XXX`
Values : *\<relative path to the error page\>*
Default value :
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-10 16:46:23 +02:00
Use this kind of environment variable to define custom error page depending on the HTTP error code. Replace XXX with HTTP code.
For example : `ERROR_404=/404.html` means the /404.html page will be displayed when 404 code is generated. The path is relative to the root web folder.
### HTTP basic authentication
2020-04-13 22:17:17 +02:00
2020-06-21 18:21:51 +02:00
`USE_AUTH_BASIC`
Values : *yes* | *no*
Default value : *no*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-06-21 18:21:51 +02:00
If set to yes, enables HTTP basic authentication at the location `AUTH_BASIC_LOCATION` with user `AUTH_BASIC_USER` and password `AUTH_BASIC_PASSWORD`.
`AUTH_BASIC_LOCATION`
2020-09-29 23:37:07 +02:00
Values : *sitewide* | */somedir* | *\<any valid location\>*
Default value : *sitewide*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-09-29 23:37:07 +02:00
The location to restrict when `USE_AUTH_BASIC` is set to *yes*. If the special value *sitewide* is used then auth basic will be set at server level outside any location context.
2020-06-21 18:21:51 +02:00
`AUTH_BASIC_USER`
Values : *\<any valid username\>*
Default value : *changeme*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-06-21 18:21:51 +02:00
The username allowed to access `AUTH_BASIC_LOCATION` when `USE_AUTH_BASIC` is set to yes.
`AUTH_BASIC_PASSWORD`
Values : *\<any valid password\>*
Default value : *changeme*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-06-21 18:21:51 +02:00
The password of `AUTH_BASIC_USER` when `USE_AUTH_BASIC` is set to yes.
`AUTH_BASIC_TEXT`
Values : *\<any valid text\>*
Default value : *Restricted area*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-06-21 18:21:51 +02:00
The text displayed inside the login prompt when `USE_AUTH_BASIC` is set to yes.
2020-10-17 17:02:42 +02:00
### Reverse proxy
2020-08-30 21:40:13 +02:00
2020-11-22 23:39:01 +01:00
`USE_REVERSE_PROXY`
Values : *yes* | *no*
Default value : *no*
Context : *global*, *multisite*
Set this environment variable to *yes* if you want to use bunkerized-nginx as a reverse proxy.
`REVERSE_PROXY_URL`
Values : \<*any valid location path*\>
Default value :
Context : *global*, *multisite*
Only valid when `USE_REVERSE_PROXY` is set to *yes*. Let's you define the location path to match when acting as a reverse proxy.
You can set multiple url/host by adding a suffix number to the variable name like this : `REVERSE_PROXY_URL_1`, `REVERSE_PROXY_URL_2`, `REVERSE_PROXY_URL_3`, ...
`REVERSE_PROXY_HOST`
Values : \<*any valid proxy_pass value*\>
Default value :
Context : *global*, *multisite*
Only valid when `USE_REVERSE_PROXY` is set to *yes*. Let's you define the proxy_pass destination to use when acting as a reverse proxy.
You can set multiple url/host by adding a suffix number to the variable name like this : `REVERSE_PROXY_HOST_1`, `REVERSE_PROXY_HOST_2`, `REVERSE_PROXY_HOST_3`, ...
2020-12-07 21:20:13 +01:00
`REVERSE_PROXY_WS`
Values : *yes* | *no*
Default value : *no*
Context : *global*, *multisite*
Only valid when `USE_REVERSE_PROXY` is set to *yes*. Set it to *yes* when the corresponding `REVERSE_PROXY_HOST` is a WebSocket server.
You can set multiple url/host by adding a suffix number to the variable name like this : `REVERSE_PROXY_WS_1`, `REVERSE_PROXY_WS_2`, `REVERSE_PROXY_WS_3`, ...
`REVERSE_PROXY_HEADERS`
Values : *\<list of custom headers separated with a semicolon\>*
Examples : Access-Control-Allow-Origin 'https://mydomain.dev'; Custom_Api_Header 'test';
Default value : ""
Context : *global*, *multisite*
Only valid when `USE_REVERSE_PROXY` is set to *yes*. Set it to *yes* when the corresponding `REVERSE_PROXY_HOST` is a WebSocket server.
You can set multiple url/host by adding a suffix number to the variable name like this : `REVERSE_PROXY_HEADERS_1`, `REVERSE_PROXY_HEADERS_2`, `REVERSE_PROXY_HEADERS_3`, ...
2020-10-06 21:52:49 +02:00
`PROXY_REAL_IP`
Values : *yes* | *no*
Default value : *no*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-06 21:52:49 +02:00
Set this environment variable to *yes* if you're using bunkerized-nginx behind a reverse proxy. This means you will see the real client address instead of the proxy one inside your logs. Modsecurity, fail2ban and others security tools will also then work correctly.
`PROXY_REAL_IP_FROM`
Values : *\<list of trusted IP addresses and/or networks separated with spaces\>*
Default value : *192.168.0.0/16 172.16.0.0/12 10.0.0.0/8*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-06 21:52:49 +02:00
When `PROXY_REAL_IP` is set to *yes*, lets you define the trusted IPs/networks allowed to send the correct client address.
`PROXY_REAL_IP_HEADER`
Values : *X-Forwarded-For* | *X-Real-IP* | *custom header*
Default value : *X-Forwarded-For*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-06 21:52:49 +02:00
When `PROXY_REAL_IP` is set to *yes*, lets you define the header that contains the real client IP address.
`PROXY_REAL_IP_RECURSIVE`
Values : *on* | *off*
Default value : *on*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-06 21:52:49 +02:00
When `PROXY_REAL_IP` is set to *yes*, setting this to *on* avoid spoofing attacks using the header defined in `PROXY_REAL_IP_HEADER`.
2020-11-22 23:39:01 +01:00
### Compression
`USE_GZIP`
Values : *yes* | *no*
Default value : *no*
Context : *global*, *multisite*
When set to *yes*, nginx will use the gzip algorithm to compress responses sent to clients.
`GZIP_COMP_LEVEL`
Values : \<*any integer between 1 and 9*\>
Default value : *5*
Context : *global*, *multisite*
The gzip compression level to use when `USE_GZIP` is set to *yes*.
`GZIP_MIN_LENGTH`
Values : \<*any positive integer*\>
Default value : *1000*
Context : *global*, *multisite*
The minimum size (in bytes) of a response required to compress when `USE_GZIP` is set to *yes*.
`GZIP_TYPES`
Values : \<*list of mime types separated with space*\>
Default value : *application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml*
Context : *global*, *multisite*
List of response MIME type required to compress when `USE_GZIP` is set to *yes*.
`USE_BROTLI`
Values : *yes* | *no*
Default value : *no*
Context : *global*, *multisite*
When set to *yes*, nginx will use the brotli algorithm to compress responses sent to clients.
`BROTLI_COMP_LEVEL`
Values : \<*any integer between 1 and 9*\>
Default value : *5*
Context : *global*, *multisite*
The brotli compression level to use when `USE_BROTLI` is set to *yes*.
`BROTLI_MIN_LENGTH`
Values : \<*any positive integer*\>
Default value : *1000*
Context : *global*, *multisite*
The minimum size (in bytes) of a response required to compress when `USE_BROTLI` is set to *yes*.
`BROTLI_TYPES`
Values : \<*list of mime types separated with space*\>
Default value : *application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml*
Context : *global*, *multisite*
List of response MIME type required to compress when `USE_BROTLI` is set to *yes*.
### Cache
`USE_CLIENT_CACHE`
Values : *yes* | *no*
Default value : *no*
Context : *global*, *multisite*
When set to *yes*, clients will be told to cache some files locally.
`CLIENT_CACHE_EXTENSIONS`
Values : \<*list of extensions separated with |*\>
Default value : *jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2*
Context : *global*, *multisite*
List of file extensions that clients should cache when `USE_CLIENT_CACHE` is set to *yes*.
`CLIENT_CACHE_CONTROL`
Values : \<*Cache-Control header value*\>
Default value : *public, max-age=15552000*
Context : *global*, *multisite*
Content of the [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) header to send when `USE_CLIENT_CACHE` is set to *yes*.
`CLIENT_CACHE_ETAG`
Values : *on* | *off*
Default value : *on*
Context : *global*, *multisite*
Whether or not nginx will send the [ETag](https://en.wikipedia.org/wiki/HTTP_ETag) header when `USE_CLIENT_CACHE` is set to *yes*.
`USE_OPEN_FILE_CACHE`
Values : *yes* | *no*
Default value : *no*
Context : *global*, *multisite*
When set to *yes*, nginx will cache open fd, existence of directories, ... See [open_file_cache](http://nginx.org/en/docs/http/ngx_http_core_module.html#open_file_cache).
`OPEN_FILE_CACHE`
Values : \<*any valid open_file_cache parameters*\>
Default value : *max=1000 inactive=20s*
Context : *global*, *multisite*
Parameters to use with open_file_cache when `USE_OPEN_FILE_CACHE` is set to *yes*.
`OPEN_FILE_CACHE_ERRORS`
Values : *on* | *off*
Default value : *on*
Context : *global*, *multisite*
Whether or not nginx should cache file lookup errors when `USE_OPEN_FILE_CACHE` is set to *yes*.
`OPEN_FILE_CACHE_MIN_USES`
Values : \<*any valid integer *\>
Default value : *2*
Context : *global*, *multisite*
The minimum number of file accesses required to cache the fd when `USE_OPEN_FILE_CACHE` is set to *yes*.
`OPEN_FILE_CACHE_VALID`
Values : \<*any time value like Xs, Xm, Xh, ...*\>
Default value : *30s*
Context : *global*, *multisite*
The time after which cached elements should be validated when `USE_OPEN_FILE_CACHE` is set to *yes*.
`USE_PROXY_CACHE`
Values : *yes* | *no*
Default value : *no*
Context : *global*, *multisite*
When set to *yes*, nginx will cache responses from proxied applications. See [proxy_cache](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache).
`PROXY_CACHE_PATH_ZONE_SIZE`
Values : \<*any valid size like Xk, Xm, Xg, ...*\>
Default value : *10m*
Context : *global*, *multisite*
Maximum size of cached metadata when `USE_PROXY_CACHE` is set to *yes*.
`PROXY_CACHE_PATH_PARAMS`
Values : \<*any valid parameters to proxy_cache_path directive*\>
Default value : *max_size=100m*
Context : *global*, *multisite*
Parameters to use for [proxy_cache_path](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path) directive when `USE_PROXY_CACHE` is set to *yes*.
`PROXY_CACHE_METHODS`
Values : \<*list of HTTP methods separated with space*\>
Default value : *GET HEAD*
Context : *global*, *multisite*
The HTTP methods that should trigger a cache operation when `USE_PROXY_CACHE` is set to *yes*.
`PROXY_CACHE_MIN_USES`
Values : \<*any positive integer*\>
Default value : *2*
Context : *global*, *multisite*
The minimum number of requests before the response is cached when `USE_PROXY_CACHE` is set to *yes*.
`PROXY_CACHE_KEY`
Values : \<*list of variables*\>
Default value : *$scheme$host$request_uri*
Context : *global*, *multisite*
The key used to uniquely identify a cached response when `USE_PROXY_CACHE` is set to *yes*.
`PROXY_CACHE_VALID`
Values : \<*status=time list separated with space*\>
2020-12-07 21:20:13 +01:00
Default value : *200=10m 301=10m 302=1h*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
Define the caching time depending on the HTTP status code (list of status=time separated with space) when `USE_PROXY_CACHE` is set to *yes*.
`PROXY_NO_CACHE`
Values : \<*list of variables*\>
Default value : *$http_authorization*
Context : *global*, *multisite*
Conditions that must be met to disable caching of the response when `USE_PROXY_CACHE` is set to *yes*.
`PROXY_CACHE_BYPASS`
Values : \<*list of variables*\>
Default value : *$http_authorization*
Context : *global*, *multisite*
Conditions that must be met to bypass the cache when `USE_PROXY_CACHE` is set to *yes*.
2020-06-21 18:24:23 +02:00
## HTTPS
2020-10-10 16:46:23 +02:00
### Let's Encrypt
2020-06-21 18:24:23 +02:00
`AUTO_LETS_ENCRYPT`
Values : *yes* | *no*
Default value : *no*
2020-12-07 21:20:13 +01:00
Context : *global*, *multisite*
2020-06-21 18:24:23 +02:00
If set to yes, automatic certificate generation and renewal will be setup through Let's Encrypt. This will enable HTTPS on your website for free.
2020-11-22 23:39:01 +01:00
You will need to redirect the 80 port to 8080 port inside container and also set the `SERVER_NAME` environment variable.
2020-06-21 18:24:23 +02:00
`AUTO_LETS_ENCRYPT_CRON`
Values : *\<cron expression\>*
Default value : 0 2 * * *
Context : *global*
Cron expression of how often lets encrypt is asking for being renewed.
`EMAIL_LETS_ENCRYPT`
Values : *contact@yourdomain.com*
Default value : *contact@yourdomain.com*
2020-12-07 17:09:31 +01:00
Context : *global*, *multisite*
Define the contact email address declare in the certificate.
2020-10-10 16:46:23 +02:00
### HTTP
2020-06-21 18:24:23 +02:00
`LISTEN_HTTP`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-06-21 18:24:23 +02:00
If set to no, nginx will not in listen on HTTP (port 80).
Useful if you only want HTTPS access to your website.
`REDIRECT_HTTP_TO_HTTPS`
Values : *yes* | *no*
Default value : *no*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-06-21 18:24:23 +02:00
If set to yes, nginx will redirect all HTTP requests to HTTPS.
2020-10-10 16:46:23 +02:00
### Custom certificate
2020-10-06 21:52:49 +02:00
`USE_CUSTOM_HTTPS`
Values : *yes* | *no*
Default value : *no*
2020-11-22 23:39:01 +01:00
Context : *global*
If set to yes, HTTPS will be enabled with certificate/key of your choice.
`CUSTOM_HTTPS_CERT`
Values : *\<any valid path inside the container\>*
Default value :
2020-11-22 23:39:01 +01:00
Context : *global*
Full path of the certificate file to use when `USE_CUSTOM_HTTPS` is set to yes.
`CUSTOM_HTTPS_KEY`
Values : *\<any valid path inside the container\>*
Default value :
2020-11-22 23:39:01 +01:00
Context : *global*
Full path of the key file to use when `USE_CUSTOM_HTTPS` is set to yes.
2020-06-21 18:24:23 +02:00
2020-10-10 17:05:44 +02:00
### Self-signed certificate
2020-10-10 16:46:23 +02:00
2020-10-06 21:52:49 +02:00
`GENERATE_SELF_SIGNED_SSL`
Values : *yes* | *no*
Default value : *no*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-06 21:52:49 +02:00
If set to yes, HTTPS will be enabled with a container generated self-signed certificate.
2020-10-06 21:52:49 +02:00
`SELF_SIGNED_SSL_EXPIRY`
Values : *integer*
Default value : *365* (1 year)
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-06 21:52:49 +02:00
Needs `GENERATE_SELF_SIGNED_SSL` to work.
Sets the expiry date for the self generated certificate.
2020-10-06 21:52:49 +02:00
`SELF_SIGNED_SSL_COUNTRY`
Values : *text*
Default value : *Switzerland*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-06 21:52:49 +02:00
Needs `GENERATE_SELF_SIGNED_SSL` to work.
Sets the country for the self generated certificate.
2020-10-06 21:52:49 +02:00
`SELF_SIGNED_SSL_STATE`
Values : *text*
Default value : *Switzerland*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-06 21:52:49 +02:00
Needs `GENERATE_SELF_SIGNED_SSL` to work.
Sets the state for the self generated certificate.
2020-10-06 21:52:49 +02:00
`SELF_SIGNED_SSL_CITY`
Values : *text*
Default value : *Bern*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-06 21:52:49 +02:00
Needs `GENERATE_SELF_SIGNED_SSL` to work.
Sets the city for the self generated certificate.
2020-10-06 21:52:49 +02:00
`SELF_SIGNED_SSL_ORG`
Values : *text*
Default value : *AcmeInc*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-06 21:52:49 +02:00
Needs `GENERATE_SELF_SIGNED_SSL` to work.
Sets the organisation name for the self generated certificate.
2020-10-06 21:52:49 +02:00
`SELF_SIGNED_SSL_OU`
Values : *text*
Default value : *IT*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-06 21:52:49 +02:00
Needs `GENERATE_SELF_SIGNED_SSL` to work.
Sets the organisitional unit for the self generated certificate.
2020-10-06 21:52:49 +02:00
`SELF_SIGNED_SSL_CN`
Values : *text*
Default value : *bunkerity-nginx*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-06 21:52:49 +02:00
Needs `GENERATE_SELF_SIGNED_SSL` to work.
Sets the CN server name for the self generated certificate.
2020-10-10 16:46:23 +02:00
### Misc
`HTTP2`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-10 16:46:23 +02:00
If set to yes, nginx will use HTTP2 protocol when HTTPS is enabled.
`HTTPS_PROTOCOLS`
Values : *TLSv1.2* | *TLSv1.3* | *TLSv1.2 TLSv1.3*
Default value : *TLSv1.2 TLSv1.3*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-30 11:39:01 +01:00
The supported version of TLS. We recommend the default value *TLSv1.2 TLSv1.3* for compatibility reasons.
2020-06-07 10:13:06 +02:00
## ModSecurity
2020-10-10 16:46:23 +02:00
`USE_MODSECURITY`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
If set to yes, the ModSecurity WAF will be enabled.
You can include custom rules by adding .conf files into the /modsec-confs/ directory inside the container (i.e : through a volume).
`USE_MODSECURITY_CRS`
2020-11-01 22:52:55 +01:00
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
If set to yes, the [OWASP ModSecurity Core Rule Set](https://coreruleset.org/) will be used. It provides generic rules to detect common web attacks.
You can customize the CRS (i.e. : add WordPress exclusions) by adding custom .conf files into the /modsec-crs-confs/ directory inside the container (i.e : through a volume). Files inside this directory are included before the CRS rules. If you need to tweak (i.e. : SecRuleUpdateTargetById) put .conf files inside the /modsec-confs/ which is included after the CRS rules.
2020-01-03 15:31:58 +01:00
2020-06-07 10:13:06 +02:00
## Security headers
2020-10-10 16:46:23 +02:00
`X_FRAME_OPTIONS`
Values : *DENY* | *SAMEORIGIN* | *ALLOW-FROM https://www.website.net*
Default value : *DENY*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-02 17:31:13 +01:00
Policy to be used when the site is displayed through iframe. Can be used to mitigate clickjacking attacks.
2019-11-22 14:21:06 +01:00
More info [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options).
`X_XSS_PROTECTION`
Values : *0* | *1* | *1; mode=block*
Default value : *1; mode=block*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-02 17:31:13 +01:00
Policy to be used when XSS is detected by the browser. Only works with Internet Explorer.
More info [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection).
2019-11-22 14:21:06 +01:00
`X_CONTENT_TYPE_OPTIONS`
Values : *nosniff*
Default value : *nosniff*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-02 17:31:13 +01:00
Tells the browser to be strict about MIME type.
2019-11-22 14:21:06 +01:00
More info [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options).
`REFERRER_POLICY`
2020-06-07 10:13:06 +02:00
Values : *no-referrer* | *no-referrer-when-downgrade* | *origin* | *origin-when-cross-origin* | *same-origin* | *strict-origin* | *strict-origin-when-cross-origin* | *unsafe-url*
Default value : *no-referrer*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-02 17:31:13 +01:00
Policy to be used for the Referer header.
More info [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy).
`FEATURE_POLICY`
2020-06-02 22:39:17 +02:00
Values : *&lt;directive&gt; &lt;allow list&gt;*
Default value : *accelerometer 'none'; ambient-light-sensor 'none'; autoplay 'none'; camera 'none'; display-capture 'none'; document-domain 'none'; encrypted-media 'none'; fullscreen 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; midi 'none'; payment 'none'; picture-in-picture 'none'; speaker 'none'; sync-xhr 'none'; usb 'none'; vibrate 'none'; vr 'none'*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-02 17:31:13 +01:00
Tells the browser which features can be used on the website.
More info [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy).
2020-11-22 23:39:01 +01:00
`PERMISSIONS_POLICY`
Values : *feature=(allow list)*
Default value : accelerometer=(), ambient-light-sensor=(), autoplay=(), camera=(), display-capture=(), document-domain=(), encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), speaker=(), sync-xhr=(), usb=(), vibrate=(), vr=()
Context : *global*, *multisite*
Tells the browser which features can be used on the website.
More info [here](https://www.w3.org/TR/permissions-policy-1/).
`COOKIE_FLAGS`
2020-10-27 22:05:49 +01:00
Values : *\* HttpOnly* | *MyCookie secure SameSite=Lax* | *...*
Default value : *\* HttpOnly SameSite=Lax*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-02 17:31:13 +01:00
Adds some security to the cookies set by the server.
Accepted value can be found [here](https://github.com/AirisX/nginx_cookie_flag_module).
2019-11-22 14:21:06 +01:00
2020-10-27 22:05:49 +01:00
`COOKIE_AUTO_SECURE_FLAG`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-27 22:05:49 +01:00
When set to *yes*, the *secure* will be automatically added to cookies when using HTTPS.
2020-12-04 16:38:48 +01:00
`STRICT_TRANSPORT_SECURITY`
2020-06-02 22:39:17 +02:00
Values : *max-age=expireTime [; includeSubDomains] [; preload]*
Default value : *max-age=31536000*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-03 15:31:58 +01:00
Tells the browser to use exclusively HTTPS instead of HTTP when communicating with the server.
More info [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security).
`CONTENT_SECURITY_POLICY`
2020-06-02 22:39:17 +02:00
Values : *\<directive 1\>; \<directive 2\>; ...*
2020-12-30 17:57:00 +01:00
Default value : *object-src 'none'; frame-ancestors 'self'; form-action 'self'; block-all-mixed-content; sandbox allow-forms allow-same-origin allow-scripts allow-popups; base-uri 'self';*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-03 15:31:58 +01:00
Policy to be used when loading resources (scripts, forms, frames, ...).
More info [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy).
2020-06-07 10:13:06 +02:00
## Blocking
2020-10-10 16:46:23 +02:00
2020-10-17 17:02:42 +02:00
### Antibot
`USE_ANTIBOT`
Values : *no* | *cookie* | *javascript* | *captcha* | *recaptcha*
Default value : *no*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-17 17:02:42 +02:00
If set to another allowed value than *no*, users must complete a "challenge" before accessing the pages on your website :
- *cookie* : asks the users to set a cookie
- *javascript* : users must execute a javascript code
- *captcha* : a text captcha must be resolved by the users
- *recaptcha* : use [Google reCAPTCHA v3](https://developers.google.com/recaptcha/intro) score to allow/deny users
`ANTIBOT_URI`
Values : *\<any valid uri\>*
Default value : */challenge*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-17 17:02:42 +02:00
A valid and unused URI to redirect users when `USE_ANTIBOT` is used. Be sure that it doesn't exist on your website.
`ANTIBOT_SESSION_SECRET`
Values : *random* | *\<32 chars of your choice\>*
Default value : *random*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-23 14:11:46 +02:00
A secret used to generate sessions when `USE_ANTIBOT` is set. Using the special *random* value will generate a random one. Be sure to use the same value when you are in a multi-server environment (so sessions are valid in all the servers).
2020-10-17 17:02:42 +02:00
`ANTIBOT_RECAPTCHA_SCORE`
Values : *\<0.0 to 1.0\>*
Default value : *0.7*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-17 17:02:42 +02:00
The minimum score required when `USE_ANTIBOT` is set to *recaptcha*.
`ANTIBOT_RECAPTCHA_SITEKEY`
Values : *\<public key given by Google\>*
Default value :
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-17 17:02:42 +02:00
The sitekey given by Google when `USE_ANTIBOT` is set to *recaptcha*.
`ANTIBOT_RECAPTCHA_SECRET`
Values : *\<private key given by Google\>*
Default value :
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-17 17:02:42 +02:00
The secret given by Google when `USE_ANTIBOT` is set to *recaptcha*.
2020-11-22 23:39:01 +01:00
### External blacklists
2020-01-03 15:31:58 +01:00
`BLOCK_USER_AGENT`
2020-06-02 22:39:17 +02:00
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-01-03 15:31:58 +01:00
If set to yes, block clients with "bad" user agent.
2020-12-07 21:20:13 +01:00
Blacklist can be found [here](https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/_generator_lists/bad-user-agents.list) and [here](https://raw.githubusercontent.com/JayBizzle/Crawler-Detect/master/raw/Crawlers.txt).
2020-01-03 15:31:58 +01:00
`BLOCK_USER_AGENT_CRON`
Values : *\<cron expression\>*
Default value : 5 0 * * * *
Context : *global*
Cron expression of how often blocklist user agent is updated.
`BLOCK_TOR_EXIT_NODE`
Values : *yes* | *no*
2020-10-04 21:20:57 +02:00
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-04 21:20:57 +02:00
Is set to yes, will block known TOR exit nodes.
Blacklist can be found [here](https://iplists.firehol.org/?ipset=tor_exits).
`BLOCK_TOR_EXIT_NODE_CRON`
Values : *\<cron expression\>*
Default value : 15 0 * * * *
Context : *global*
Cron expression of how often blocklist tor exit node is updated.
2020-10-04 21:20:57 +02:00
`BLOCK_PROXIES`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-04 21:20:57 +02:00
Is set to yes, will block known proxies.
Blacklist can be found [here](https://iplists.firehol.org/?ipset=firehol_proxies).
`BLOCK_PROXIES_CRON`
Values : *\<cron expression\>*
Default value : 20 0 * * * *
Context : *global*
Cron expression of how often blocklist proxies is updated.
2020-10-04 21:20:57 +02:00
`BLOCK_ABUSERS`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-04 21:20:57 +02:00
Is set to yes, will block known abusers.
Blacklist can be found [here](https://iplists.firehol.org/?ipset=firehol_abusers_30d).
2020-01-03 15:31:58 +01:00
`BLOCK_ABUSERS_CRON`
Values : *\<cron expression\>*
Default value : 30 0 * * * *
Context : *global*
Cron expression of how often blocklist abusers is updated.
2020-12-07 21:20:13 +01:00
`BLOCK_REFERRER`
Values : *yes* | *no*
Default value : *yes*
Context : *global*, *multisite*
Is set to yes, will block known bad referrer header.
Blacklist can be found [here](https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/_generator_lists/bad-referrers.list).
`BLOCK_REFERRER_CRON`
Values : *\<cron expression\>*
Default value : 10 0 * * * *
Context : *global*
Cron expression of how often blocklist referrer is updated.
2020-10-10 16:46:23 +02:00
### DNSBL
2020-09-29 23:01:26 +02:00
`USE_DNSBL`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-10 16:46:23 +02:00
If set to *yes*, DNSBL checks will be performed to the servers specified in the `DNSBL_LIST` environment variable.
2020-09-29 23:01:26 +02:00
`DNSBL_LIST`
Values : *\<list of DNS zones separated with spaces\>*
Default value : *bl.blocklist.de problems.dnsbl.sorbs.net sbl.spamhaus.org xbl.spamhaus.org*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-09-29 23:01:26 +02:00
The list of DNSBL zones to query when `USE_DNSBL` is set to *yes*.
### CrowdSec
`USE_CROWDSEC`
Values : *yes* | *no*
Default value : *no*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-12-30 21:22:18 +01:00
If set to *yes*, [CrowdSec](https://github.com/crowdsecurity/crowdsec) will be enabled. Please note that you need a CrowdSec instance running see example [here](https://github.com/bunkerity/bunkerized-nginx/tree/master/examples/crowdsec).
`CROWDSEC_HOST`
Values : *\<full URL to the CrowdSec instance API\>*
Default value :
Context : *global*
The full URL to the CrowdSec API.
`CROWDSEC_KEY`
Values : *\<CrowdSec bouncer key\>*
Default value :
Context : *global*
The CrowdSec key given by *cscli bouncer add BouncerName*.
2020-10-10 16:46:23 +02:00
### Custom whitelisting
2020-09-29 23:01:26 +02:00
2020-10-10 16:46:23 +02:00
`USE_WHITELIST_IP`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-10 16:46:23 +02:00
If set to *yes*, lets you define custom IP addresses to be whitelisted through the `WHITELIST_IP_LIST` environment variable.
`WHITELIST_IP_LIST`
Values : *\<list of IP addresses separated with spaces\>*
Default value : *23.21.227.69 40.88.21.235 50.16.241.113 50.16.241.114 50.16.241.117 50.16.247.234 52.204.97.54 52.5.190.19 54.197.234.188 54.208.100.253 54.208.102.37 107.21.1.8*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-10 16:46:23 +02:00
The list of IP addresses to whitelist when `USE_WHITELIST_IP` is set to *yes*. The default list contains IP addresses of the [DuckDuckGo crawler](https://help.duckduckgo.com/duckduckgo-help-pages/results/duckduckbot/).
`USE_WHITELIST_REVERSE`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-10 16:46:23 +02:00
If set to *yes*, lets you define custom reverse DNS suffixes to be whitelisted through the `WHITELIST_REVERSE_LIST` environment variable.
`WHITELIST_REVERSE_LIST`
Values : *\<list of reverse DNS suffixes separated with spaces\>*
Default value : *.googlebot.com .google.com .search.msn.com .crawl.yahoot.net .crawl.baidu.jp .crawl.baidu.com .yandex.com .yandex.ru .yandex.net*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-10 16:46:23 +02:00
The list of reverse DNS suffixes to whitelist when `USE_WHITELIST_REVERSE` is set to *yes*. The default list contains suffixes of major search engines.
2021-03-17 17:55:56 +01:00
`WHITELIST_USER_AGENT`
Values : *\<list of regexes separated with spaces\>*
Default value :
Context : *global*, *multisite*
2021-03-17 17:55:56 +01:00
Whitelist user agent from being blocked by `BLOCK_USER_AGENT`.
2020-10-10 16:46:23 +02:00
### Custom blacklisting
`USE_BLACKLIST_IP`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-10 16:46:23 +02:00
If set to *yes*, lets you define custom IP addresses to be blacklisted through the `BLACKLIST_IP_LIST` environment variable.
`BLACKLIST_IP_LIST`
Values : *\<list of IP addresses separated with spaces\>*
Default value :
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-10 16:46:23 +02:00
The list of IP addresses to blacklist when `USE_BLACKLIST_IP` is set to *yes*.
`USE_BLACKLIST_REVERSE`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-10 16:46:23 +02:00
If set to *yes*, lets you define custom reverse DNS suffixes to be blacklisted through the `BLACKLIST_REVERSE_LIST` environment variable.
`BLACKLIST_REVERSE_LIST`
Values : *\<list of reverse DNS suffixes separated with spaces\>*
Default value : *.shodan.io*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-10 16:46:23 +02:00
The list of reverse DNS suffixes to blacklist when `USE_BLACKLIST_REVERSE` is set to *yes*.
### Requests limiting
2020-09-29 23:01:26 +02:00
2020-10-16 09:16:16 +02:00
`USE_LIMIT_REQ`
2020-10-02 12:01:30 +02:00
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-02 12:01:30 +02:00
If set to yes, the amount of HTTP requests made by a user will be limited during a period of time.
More info rate limiting [here](https://www.nginx.com/blog/rate-limiting-nginx/).
2020-10-15 19:50:35 +02:00
`LIMIT_REQ_RATE`
2020-10-02 12:01:30 +02:00
Values : *Xr/s* | *Xr/m*
2020-10-02 14:13:24 +02:00
Default value : *20r/s*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-16 09:16:16 +02:00
The rate limit to apply when `USE_LIMIT_REQ` is set to *yes*. Default is 10 requests per second.
2020-10-02 12:01:30 +02:00
2020-10-15 19:50:35 +02:00
`LIMIT_REQ_BURST`
2020-10-02 12:01:30 +02:00
Values : *<any valid integer\>*
2020-10-02 14:13:24 +02:00
Default value : *40*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
The number of requests to put in queue before rejecting requests.
2020-10-02 12:01:30 +02:00
2020-10-15 19:50:35 +02:00
`LIMIT_REQ_CACHE`
2020-10-02 12:01:30 +02:00
Values : *Xm* | *Xk*
Default value : *10m*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-10-02 12:01:30 +02:00
The size of the cache to store information about request limiting.
### Connections limiting
`USE_LIMIT_CONN`
Values : *yes* | *no*
Default value : *yes*
Context : *global*, *multisite*
If set to yes, the number of connections made by an ip will be limited during a period of time. (ie. Very small/weak ddos protection)
More info connections limiting [here](http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html).
`LIMIT_CONN_MAX`
Values : *<any valid integer\>*
Default value : *40*
Context : *global*, *multisite*
The maximum number of connections per ip to put in queue before rejecting requests.
`LIMIT_CONN_CACHE`
Values : *Xm* | *Xk*
Default value : *10m*
Context : *global*
The size of the cache to store information about connection limiting.
2020-10-10 16:46:23 +02:00
### Countries
2020-11-22 23:39:01 +01:00
`BLACKLIST_COUNTRY`
2020-10-10 16:46:23 +02:00
Values : *\<country code 1\> \<country code 2\> ...*
Default value :
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-10-10 16:46:23 +02:00
Block some countries from accessing your website. Use 2 letters country code separated with space.
2020-11-22 23:39:01 +01:00
`WHITELIST_COUNTRY`
Values : *\<country code 1\> \<country code 2\> ...*
Default value :
Context : *global*, *multisite*
Only allow specific countries accessing your website. Use 2 letters country code separated with space.
`GEOIP_CRON`
Values : *\<cron expression\>*
Default value : 30 2 2 * *
Context : *global*
Cron expression of how often geoip will update its database.
2020-06-07 10:13:06 +02:00
## PHP
2020-10-10 16:46:23 +02:00
2020-09-18 22:50:56 +02:00
`REMOTE_PHP`
Values : *\<any valid IP/hostname\>*
Default value :
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-09-18 22:50:56 +02:00
Set the IP/hostname address of a remote PHP-FPM to execute .php files. See `USE_PHP` if you want to run a PHP-FPM instance on the same container as bunkerized-nginx.
2020-09-29 23:37:07 +02:00
`REMOTE_PHP_PATH`
Values : *\<any valid absolute path\>*
Default value : */app*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
2020-09-29 23:37:07 +02:00
The path where the PHP files are located inside the server specified in `REMOTE_PHP`.
2020-06-07 10:13:06 +02:00
## Fail2ban
2020-10-10 16:46:23 +02:00
2020-06-02 22:39:17 +02:00
`USE_FAIL2BAN`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
If set to yes, fail2ban will be used to block users getting too much "strange" HTTP codes in a period of time.
Instead of using iptables which is not possible inside a container, fail2ban will dynamically update nginx to ban/unban IP addresses.
If a number (`FAIL2BAN_MAXRETRY`) of "strange" HTTP codes (`FAIL2BAN_STATUS_CODES`) is found between a time interval (`FAIL2BAN_FINDTIME`) then the originating IP address will be ban for a specific period of time (`FAIL2BAN_BANTIME`).
2020-06-02 22:39:17 +02:00
`FAIL2BAN_STATUS_CODES`
Values : *\<HTTP status codes separated with | char\>*
Default value : *400|401|403|404|405|444*
2020-11-22 23:39:01 +01:00
Context : *global*
List of "strange" error codes that fail2ban will search for.
2020-08-23 22:59:24 +02:00
`FAIL2BAN_BANTIME`
Values : *<number of seconds>*
Default value : *3600*
2020-11-22 23:39:01 +01:00
Context : *global*
The duration time, in seconds, of a ban.
`FAIL2BAN_FINDTIME`
Values : *<number of seconds>*
Default : value : *60*
2020-11-22 23:39:01 +01:00
Context : *global*
The time interval, in seconds, to search for "strange" HTTP status codes.
`FAIL2BAN_MAXRETRY`
2020-06-02 22:39:17 +02:00
Values : *\<any positive integer\>*
2020-10-10 16:46:23 +02:00
Default : value : *15*
2020-11-22 23:39:01 +01:00
Context : *global*
2020-06-02 22:42:17 +02:00
The number of "strange" HTTP status codes to find between the time interval.
`FAIL2BAN_IGNOREIP`
2020-12-30 14:31:16 +01:00
Values : *\<list of IP addresses or subnet separated with spaces\>*
Default value : 127.0.0.1/8 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8
Context : *global*
IPs or subnet which should never be ban by fail2ban.
2020-06-07 10:13:06 +02:00
## ClamAV
2020-10-10 16:46:23 +02:00
`USE_CLAMAV_UPLOAD`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*, *multisite*
If set to yes, ClamAV will scan every file uploads and block the upload if the file is detected.
`USE_CLAMAV_SCAN`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*
If set to yes, ClamAV will scan all the files inside the container every day.
`USE_CLAMAV_SCAN_CRON`
Values : *\<cron expression\>*
Default value : 40 */1 * * *
Context : *global*
Cron expression of how often ClamAV will scan all the files inside the container.
`CLAMAV_SCAN_REMOVE`
Values : *yes* | *no*
Default value : *yes*
2020-11-22 23:39:01 +01:00
Context : *global*
If set to yes, ClamAV will automatically remove the detected files.
2020-01-03 15:31:58 +01:00
`CLAMAV_UPDATE_CRON`
Values : *\<cron expression\>*
Default value : 0 3 * * *
Context : *global*
Cron expression of how often ClamAV will update its database.
2020-08-01 17:47:06 +02:00
## Misc
2020-10-10 16:46:23 +02:00
2020-08-23 22:59:24 +02:00
`ADDITIONAL_MODULES`
2020-08-01 17:47:06 +02:00
Values : *\<list of packages separated with space\>*
Default value :
2020-11-22 23:39:01 +01:00
Context : *global*
2020-08-01 17:47:06 +02:00
You can specify additional modules to install. All [alpine packages](https://pkgs.alpinelinux.org/packages) are valid.
2020-08-30 21:40:13 +02:00
`LOGROTATE_MINSIZE`
Values : *x* | *xk* | *xM* | *xG*
Default value : 10M
2020-11-22 23:39:01 +01:00
Context : *global*
2020-08-30 21:40:13 +02:00
The minimum size of a log file before being rotated (no letter = bytes, k = kilobytes, M = megabytes, G = gigabytes).
`LOGROTATE_MAXAGE`
Values : *\<any integer\>*
Default value : 7
2020-11-22 23:39:01 +01:00
Context : *global*
2020-08-30 21:40:13 +02:00
The number of days before rotated files are deleted.
`LOGROTATE_CRON`
Values : *\<cron expression\>*
Default value : 0 4 * * *
Context : *global*
Cron expression of how often Logrotate will rotate files.
2020-08-01 17:47:06 +02:00
# Include custom configurations
Custom configurations files (ending with .conf suffix) can be added in some directory inside the container :
- /http-confs : http context
- /server-confs : server context
2021-03-08 11:53:11 +01:00
- /pre-server-confs : before server context (add map or upstream config for example)
2020-08-01 17:47:06 +02:00
You just need to use a volume like this :
2020-11-22 23:39:01 +01:00
```shell
docker run ... -v /path/to/http/confs:/http-confs:ro ... -v /path/to/server/confs:/server-confs:ro ... bunkerity/bunkerized-nginx
2020-08-01 17:47:06 +02:00
```
2020-11-22 23:39:01 +01:00
When `MULTISITE` is set to *yes*, .conf files inside the /server-confs directory are loaded by all the server blocks. You can also set custom configuration for a specific server block by adding files in a subdirectory named as the host defined in the `SERVER_NAME` environment variable. Here is an example :
```shell
docker run ... -v /path/to/server/confs:/server-confs:ro ... -e MULTISITE=yes -e "SERVER_NAME=app1.domain.com app2.domain.com" ... bunkerity/bunkerized-nginx
```
The */path/to/server/confs* directory should have a structure like this :
```
/path/to/server/confs
├── app1.domain.com
│   └── custom.conf
│   └── ...
└── app2.domain.com
└── custom.conf
└── ...
```
# Cache data
You can store cached data (blacklists, geoip DB, ...) to avoid downloading them again after a container deletion by mounting a volume on the /cache directory :
```shell
docker run ... -v /path/to/cache:/cache ... bunkerity/bunkerized-nginx
2020-08-01 17:47:06 +02:00
```