2016-09-10 11:45:34 +02:00
|
|
|
# Basic configuration
|
|
|
|
user nginx;
|
2016-02-20 21:11:59 +02:00
|
|
|
worker_processes 1;
|
2016-02-24 08:44:49 +02:00
|
|
|
error_log /dev/stderr info;
|
2016-02-21 20:48:40 +02:00
|
|
|
pid /var/run/nginx.pid;
|
2017-06-05 13:13:06 +02:00
|
|
|
include /etc/nginx/modules/devel_kit.conf;
|
|
|
|
include /etc/nginx/modules/http_lua.conf;
|
2016-02-20 21:11:59 +02:00
|
|
|
|
|
|
|
events {
|
|
|
|
worker_connections 1024;
|
|
|
|
}
|
|
|
|
|
2016-09-10 11:45:34 +02:00
|
|
|
# Environment variables used in the configuration
|
|
|
|
env WEBMAIL;
|
2016-11-30 15:02:36 +02:00
|
|
|
env WEBDAV;
|
2016-09-10 12:07:32 +02:00
|
|
|
env EXPOSE_ADMIN;
|
2016-09-10 11:45:34 +02:00
|
|
|
|
2016-02-20 21:11:59 +02:00
|
|
|
http {
|
2016-09-10 11:45:34 +02:00
|
|
|
# Standard HTTP configuration with slight hardening
|
2016-02-21 20:48:40 +02:00
|
|
|
include /etc/nginx/mime.types;
|
|
|
|
default_type application/octet-stream;
|
2016-02-24 08:44:49 +02:00
|
|
|
access_log /dev/stdout;
|
2016-02-20 21:11:59 +02:00
|
|
|
sendfile on;
|
|
|
|
keepalive_timeout 65;
|
|
|
|
server_tokens off;
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 80;
|
2016-02-20 22:55:22 +02:00
|
|
|
listen 443 ssl;
|
2017-06-05 12:17:06 +02:00
|
|
|
listen [::]:80;
|
|
|
|
listen [::]:443 ssl;
|
2016-02-20 22:55:22 +02:00
|
|
|
|
2016-08-19 15:07:16 +02:00
|
|
|
# TLS configuration hardened according to:
|
|
|
|
# https://bettercrypto.org/static/applied-crypto-hardening.pdf
|
2016-02-20 22:55:22 +02:00
|
|
|
ssl_protocols TLSv1.1 TLSv1.2;
|
2016-08-19 15:07:16 +02:00
|
|
|
ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA';
|
2016-02-20 22:55:22 +02:00
|
|
|
ssl_prefer_server_ciphers on;
|
|
|
|
ssl_session_timeout 5m;
|
|
|
|
ssl_session_cache shared:SSL:50m;
|
2016-02-24 08:44:49 +02:00
|
|
|
ssl_certificate /certs/cert.pem;
|
|
|
|
ssl_certificate_key /certs/key.pem;
|
2017-02-25 10:53:53 +02:00
|
|
|
ssl_dhparam /etc/nginx/dhparam.pem;
|
2016-02-20 22:55:22 +02:00
|
|
|
|
2016-08-19 15:07:16 +02:00
|
|
|
add_header Strict-Transport-Security max-age=15768000;
|
|
|
|
|
2016-02-20 22:55:22 +02:00
|
|
|
if ($scheme = http) {
|
|
|
|
return 301 https://$host$request_uri;
|
|
|
|
}
|
|
|
|
|
2016-09-10 11:45:34 +02:00
|
|
|
# Load Lua variables
|
|
|
|
set_by_lua $webmail 'return os.getenv("WEBMAIL")';
|
2016-11-30 15:02:36 +02:00
|
|
|
set_by_lua $webdav 'return os.getenv("WEBDAV")';
|
2016-09-10 12:07:32 +02:00
|
|
|
set_by_lua $expose_admin 'return os.getenv("EXPOSE_ADMIN")';
|
2016-09-10 11:45:34 +02:00
|
|
|
|
|
|
|
# Actual logic
|
|
|
|
|
2016-02-24 08:44:49 +02:00
|
|
|
location / {
|
2016-10-30 12:33:29 +02:00
|
|
|
if ($webmail != none) {
|
|
|
|
return 301 $scheme://$host/webmail/;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($webmail = none) {
|
|
|
|
return 403;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
location /webmail {
|
2016-09-10 11:45:34 +02:00
|
|
|
if ($webmail != none) {
|
|
|
|
proxy_pass http://webmail;
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:07:32 +02:00
|
|
|
if ($webmail = none) {
|
|
|
|
return 403;
|
|
|
|
}
|
2016-02-20 22:55:22 +02:00
|
|
|
}
|
2016-02-20 21:11:59 +02:00
|
|
|
|
|
|
|
location /admin {
|
2016-09-10 12:07:32 +02:00
|
|
|
if ($expose_admin = yes) {
|
|
|
|
proxy_pass http://admin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($expose_admin != yes) {
|
|
|
|
return 403;
|
|
|
|
}
|
2016-02-20 21:11:59 +02:00
|
|
|
}
|
2016-11-09 17:18:16 +02:00
|
|
|
|
2016-11-30 15:02:36 +02:00
|
|
|
location /webdav {
|
|
|
|
if ($webdav != none) {
|
|
|
|
proxy_pass http://webdav:5232;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($webdav = none) {
|
|
|
|
return 403;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 17:18:16 +02:00
|
|
|
location /.well-known/acme-challenge {
|
|
|
|
proxy_pass http://admin:8081;
|
|
|
|
}
|
2016-02-20 21:11:59 +02:00
|
|
|
}
|
|
|
|
}
|