bunkerized-nginx/README.md

688 lines
27 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-10-10 16:46:23 +02:00
<img src="https://img.shields.io/badge/nginx-1.18.0-blue" /> <img src="https://img.shields.io/docker/cloud/build/bunkerity/bunkerized-nginx" /> <img src="https://img.shields.io/github/last-commit/bunkerity/bunkerized-nginx" />
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-04-13 22:17:17 +02:00
- State-of-the-art web security : HTTP security headers, php.ini hardening, prevent leaks, ...
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-04 21:20:57 +02:00
- Block TOR, proxies, bad user-agents, countries, ...
2020-10-02 12:01:30 +02:00
- Perform automatic DNSBL checks to block known bad IP
- Prevent bruteforce attacks with rate limiting
2020-04-13 22:17:17 +02:00
- Detect bad files with ClamAV
2019-08-20 23:50:42 +02:00
- Easy to configure with environment variables
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-06-07 10:13:06 +02:00
* [Run HTTPS server with automated Let's Encrypt](#run-https-server-with-automated-let-s-encrypt)
* [Reverse proxy](#reverse-proxy)
- [Tutorials](#tutorials)
- [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)
+ [Behind a reverse proxy](#behind-a-reverse-proxy)
2020-06-07 10:13:06 +02:00
* [HTTPS](#https)
2020-10-10 17:05:44 +02:00
+ [Let's Encrypt](#let-s-encrypt)
+ [HTTP](#http)
+ [Custom certificate](#custom-certificate)
+ [Self-signed certificate](#self-signed-certificate)
+ [Misc](#misc-1)
2020-06-07 10:13:06 +02:00
* [ModSecurity](#modsecurity)
* [Security headers](#security-headers)
* [Blocking](#blocking)
2020-10-10 17:05:44 +02:00
+ [External blacklist](#external-blacklist)
+ [DNSBL](#dnsbl)
+ [Custom whitelisting](#custom-whitelisting)
+ [Custom blacklisting](#custom-blacklisting)
+ [Requests limiting](#requests-limiting)
+ [Countries](#countries)
+ [Misc](#misc-2)
2020-06-07 10:13:06 +02:00
* [PHP](#php)
2020-10-10 17:05:44 +02:00
+ [Remote PHP](#remote-php)
+ [Local PHP (will be removed)](#local-php--will-be-removed-)
2020-06-07 10:13:06 +02:00
* [Fail2ban](#fail2ban)
* [ClamAV](#clamav)
2020-10-10 17:05:44 +02:00
* [Misc](#misc-3)
2020-06-07 10:13:06 +02:00
- [Create your own image](#create-your-own-image)
2020-10-10 17:05:44 +02:00
- [Include custom configurations](#include-custom-configurations)
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
docker run -p 80:80 -v /path/to/web/files:/www bunkerity/bunkerized-nginx
```
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
docker run --network mynet -p 80:80 -v /path/to/web/files:/www -e REMOTE_PHP=myphp -e REMOTE_PHP_PATH=/app bunkerity/bunkerized-nginx
docker run --network mynet --name=myphp -v /path/to/web/files:/app php:fpm
```
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
2019-11-22 14:21:06 +01:00
```shell
2020-04-13 22:17:17 +02:00
docker run -p 80:80 -p 443:443 -v /path/to/web/files:/www -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-08-01 17:47:06 +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-06-07 10:13:06 +02:00
## Reverse proxy
2020-06-02 22:39:17 +02:00
You can setup a reverse proxy by adding your own custom configurations at server context.
2020-04-13 22:17:17 +02:00
For example, this is a dummy reverse proxy configuration :
```shell
2020-06-02 22:39:17 +02:00
location / {
if ($host = www.website1.com) {
proxy_pass http://192.168.42.10$request_uri;
}
if ($host = www.website2.com) {
proxy_pass http://192.168.42.11$request_uri;
}
2020-04-13 22:17:17 +02:00
}
```
2020-06-02 22:39:17 +02:00
All files (ending with .conf) in /server-confs inside the container will be included at server context. You can simply mount a volume where your config files are located :
2020-04-13 22:17:17 +02:00
```shell
2020-06-02 22:39:17 +02:00
docker run -p 80:80 -e SERVER_NAME="www.website1.com www.website2.com" -e SERVE_FILES=no -e DISABLE_DEFAULT_SERVER=yes -v /path/to/server/conf:/server-confs bunkerity/bunkerized-nginx
2020-04-13 22:17:17 +02:00
```
Here you have three environment variables :
2020-08-01 17:47:06 +02:00
- `SERVER_NAME` : list of valid Host headers sent by clients
- `SERVE_FILES` : nginx will not serve files from the /www directory
- `DISABLE_DEFAULT_SERVER` : nginx will not respond to requests if Host header is not in the SERVER_NAME list
2019-11-22 14:21:06 +01:00
2020-06-07 10:13:06 +02:00
# Tutorials
2020-08-01 17:47:06 +02:00
You will find some tutorials about bunkerized-nginx in our [blog](https://www.bunkerity.com/category/bunkerized-nginx/).
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
`SERVER_NAME`
Values : *&lt;first name&gt; &lt;second name&gt; ...*
Default value : *www.bunkerity.com*
Sets the host names of the webserver separated with spaces. This must match the Host header sent by clients.
Useful when used with `AUTO_LETSENCRYPT=yes` and/or `DISABLE_DEFAULT_SERVER=yes`.
`MAX_CLIENT_SIZE`
Values : *0* | *Xm*
Default value : *10m*
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*
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*
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-01-03 15:31:58 +01:00
If set to yes, nginx will serve files from /www directory within the container.
A use case to not serving files is when you setup bunkerized-nginx as a reverse proxy via a custom configuration.
2020-10-10 16:46:23 +02:00
`WRITE_ACCESS`
Values : *yes* | *no*
Default value : *no*
If set to yes, nginx will be granted write access to the /www directory.
Set it to yes if your website uses file upload or creates dynamic files for example.
2020-08-22 00:12:36 +02:00
`ROOT_FOLDER`
Values : *\<any valid path to web files\>
Default value : */www*
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-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*
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-10-10 16:46:23 +02:00
`HEADER_SERVER`
2020-08-01 17:47:06 +02:00
Values : *yes* | *no*
Default value : *no*
2020-10-10 16:46:23 +02:00
If set to no, nginx will remove the Server header in HTTP responses.
### Custom error pages
`ERROR_XXX`
Values : *\<relative path to the error page\>*
Default value :
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*
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*
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*
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*
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*
The text displayed inside the login prompt when `USE_AUTH_BASIC` is set to yes.
2020-10-10 16:46:23 +02:00
### Behind a reverse proxy
2020-08-30 21:40:13 +02:00
2020-10-06 21:52:49 +02:00
`PROXY_REAL_IP`
Values : *yes* | *no*
Default value : *no*
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*
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*
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*
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-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*
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.
You will need to redirect both 80 and 443 port to your container and also set the `SERVER_NAME` environment variable.
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*
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*
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*
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 :
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 :
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*
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)
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*
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*
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*
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*
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*
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*
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*
If set to yes, nginx will use HTTP2 protocol when HTTPS is enabled.
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*
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`
Values: *yes* | *no*
Default value : *yes*
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`
2020-06-07 10:13:06 +02:00
Values : *DENY* | *SAMEORIGIN* | *ALLOW-FROM https://www.website.net* | *ALLOWALL*
Default value : *DENY*
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-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-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-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-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).
`COOKIE_FLAGS`
2020-06-02 22:39:17 +02:00
Values : *\* HttpOnly* | *MyCookie secure SameSite* | *...*
Default value : *\* HttpOnly*
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
`STRICT_TRANSPORT_POLICY`
2020-06-02 22:39:17 +02:00
Values : *max-age=expireTime [; includeSubDomains] [; preload]*
Default value : *max-age=31536000*
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-08-18 16:48:14 +02:00
Default value : *default-src 'self'; frame-ancestors 'self'; form-action 'self'; block-all-mixed-content; sandbox allow-forms allow-same-origin allow-scripts; reflected-xss block; base-uri 'self'; referrer no-referrer*
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
### External blacklist
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-01-03 15:31:58 +01:00
If set to yes, block clients with "bad" user agent.
Blacklist can be found [here](https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/_generator_lists/bad-user-agents.list).
`BLOCK_TOR_EXIT_NODE`
Values : *yes* | *no*
2020-10-04 21:20:57 +02:00
Default value : *yes*
Is set to yes, will block known TOR exit nodes.
Blacklist can be found [here](https://iplists.firehol.org/?ipset=tor_exits).
`BLOCK_PROXIES`
Values : *yes* | *no*
Default value : *yes*
Is set to yes, will block known proxies.
Blacklist can be found [here](https://iplists.firehol.org/?ipset=firehol_proxies).
`BLOCK_ABUSERS`
Values : *yes* | *no*
Default value : *yes*
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
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-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*
The list of DNSBL zones to query when `USE_DNSBL` is set to *yes*.
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*
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*
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*
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*
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.
### Custom blacklisting
`USE_BLACKLIST_IP`
Values : *yes* | *no*
Default value : *yes*
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 :
The list of IP addresses to blacklist when `USE_BLACKLIST_IP` is set to *yes*.
`USE_BLACKLIST_REVERSE`
Values : *yes* | *no*
Default value : *yes*
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*
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*
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-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-10-02 12:01:30 +02:00
The number of of requests to put in queue before rejecting requests.
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*
The size of the cache to store information about request limiting.
2020-10-10 16:46:23 +02:00
### Countries
`BLOCK_COUNTRY`
Values : *\<country code 1\> \<country code 2\> ...*
Default value :
Block some countries from accessing your website. Use 2 letters country code separated with space.
### Misc
`DNS_RESOLVERS`
Values : *\<two IP addresses separated with a space\>*
Default value : *8.8.8.8 8.8.4.4*
The IP addresses of the DNS resolvers to use when performing reverse DNS lookups.
2020-06-07 10:13:06 +02:00
## PHP
2020-10-10 16:46:23 +02:00
### Remote PHP
2020-09-18 22:50:56 +02:00
`REMOTE_PHP`
Values : *\<any valid IP/hostname\>*
Default value :
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*
The path where the PHP files are located inside the server specified in `REMOTE_PHP`.
2020-10-10 16:46:23 +02:00
### Local PHP (will be removed)
`USE_PHP`
Values : *yes* | *no*
2020-10-10 16:46:23 +02:00
Default value : *no*
2020-09-18 22:50:56 +02:00
If set to yes, a local PHP-FPM instance will be run inside the container to execute PHP files.
2020-01-03 15:31:58 +01:00
`PHP_DISPLAY_ERRORS`
Values : *yes* | *no*
Default value : *no*
2020-09-18 22:50:56 +02:00
If set to yes, PHP errors will be shown to clients. Only meaningful if `USE_PHP` is set to *yes*.
2020-01-03 15:31:58 +01:00
`PHP_EXPOSE`
Values : *yes* | *no*
Default value : *no*
2020-09-18 22:50:56 +02:00
If set to yes, the PHP version will be sent within the X-Powered-By header. Only meaningful if `USE_PHP` is set to *yes*.
2020-01-03 15:31:58 +01:00
`PHP_OPEN_BASEDIR`
2020-08-01 17:47:06 +02:00
Values : *\<directories separated with : char\>*
Default value : */www/:/tmp/*
2020-09-18 22:50:56 +02:00
Limits access to files within the given directories. For example include() or fopen() calls outside the directory will fail. Only meaningful if `USE_PHP` is set to *yes*.
2020-01-03 15:31:58 +01:00
`PHP_ALLOW_URL_FOPEN`
2020-06-02 22:39:17 +02:00
Values : *yes* | *no*
Default value : *no*
2020-09-18 22:50:56 +02:00
If set to yes, allows using url in fopen() calls (i.e. : ftp://, http://, ...). Only meaningful if `USE_PHP` is set to *yes*.
2020-01-03 15:31:58 +01:00
`PHP_ALLOW_URL_INCLUDE`
2020-06-02 22:39:17 +02:00
Values : *yes* | *no*
Default value : *no*
2020-09-18 22:50:56 +02:00
If set to yes, allows using url in include() calls (i.e. : ftp://, http://, ...). Only meaningful if `USE_PHP` is set to *yes*.
2020-01-03 15:31:58 +01:00
`PHP_FILE_UPLOADS`
2020-06-02 22:39:17 +02:00
Values : *yes* | *no*
Default value : *yes*
2020-09-18 22:50:56 +02:00
If set to yes, allows clients to upload files. Only meaningful if `USE_PHP` is set to *yes*.
2020-01-03 15:31:58 +01:00
`PHP_UPLOAD_MAX_FILESIZE`
Values : *\<size in bytes\>* | *XM*
Default value : *10M*
2020-09-18 22:50:56 +02:00
Sets the maximum file size allowed when uploading files. Only meaningful if `USE_PHP` is set to *yes*.
2020-01-03 15:31:58 +01:00
2020-08-01 17:47:06 +02:00
`PHP_POST_MAX_SIZE`
Values : *\<size in bytes\>* | *XM*
Default value : *10M*
2020-09-18 22:50:56 +02:00
Sets the maximum POST size allowed for clients. Only meaningful if `USE_PHP` is set to *yes*.
2020-08-01 17:47:06 +02:00
`PHP_DISABLE_FUNCTIONS`
2020-06-02 22:39:17 +02:00
Values : *\<function 1\>, \<function 2\> ...*
Default value : *system, exec, shell_exec, passthru, phpinfo, show_source, highlight_file, popen, proc_open, fopen_with_path, dbmopen, dbase_open, putenv, filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo*
2020-09-18 22:50:56 +02:00
List of PHP functions blacklisted separated with commas. They can't be used anywhere in PHP code. Only meaningful if `USE_PHP` is set to *yes*.
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*
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*
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*
The duration time, in seconds, of a ban.
`FAIL2BAN_FINDTIME`
Values : *<number of seconds>*
Default : value : *60*
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-06-02 22:42:17 +02:00
The number of "strange" HTTP status codes to find between the time interval.
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*
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*
If set to yes, ClamAV will scan all the files inside the container every day.
`CLAMAV_SCAN_REMOVE`
Values : *yes* | *no*
Default value : *yes*
If set to yes, ClamAV will automatically remove the detected files.
2020-01-03 15:31:58 +01:00
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 :
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
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
The number of days before rotated files are deleted.
2020-06-07 10:13:06 +02:00
# Create your own image
You can use bunkerity/bunkerized-nginx as a base image for your web application.
Here is a Dockerfile example :
```
FROM bunkerity/bunkerized-nginx
2020-08-22 00:12:36 +02:00
# Copy your web files to a folder
COPY ./web-files/ /opt/web-files
2020-06-07 10:13:06 +02:00
# Optional : add your own script to be executed on startup
2020-08-22 00:12:36 +02:00
COPY ./my-entrypoint.sh /entrypoint.d/my-entrypoint.sh
RUN chmod +x /entrypoint.d/my-entrypoint.sh
# Mandatory variables to make things working
ENV ROOT_FOLDER /opt/web-files
ENV PHP_OPEN_BASEDIR /opt/web-files/:/tmp/
2020-06-07 10:13:06 +02:00
2020-08-22 00:12:36 +02:00
# Optional variables
2020-06-07 10:13:06 +02:00
ENV MAX_CLIENT_SIZE 100m
ENV PHP_UPLOAD_MAX_FILESIZE 100M
ENV WRITE_ACCESS yes
2020-08-22 00:12:36 +02:00
ENV ADDITIONAL_MODULES php7-mysqli php7-json php7-session
2020-06-07 10:13:06 +02:00
```
2020-10-10 16:46:23 +02:00
You can have a look at [bunkerized-phpmyadmin](https://github.com/bunkerity/bunkerized-phpmyadmin) which is a secure phpMyAdmin Docker image based on bunkerized-nginx.
2020-08-30 21:40:13 +02:00
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
You just need to use a volume like this :
```
docker run ... -v /path/to/http/confs:/http-confs ... bunkerity/bunkerized-nginx
```