2017-09-24 13:09:12 +02:00
|
|
|
# Basic configuration
|
|
|
|
user nginx;
|
2017-11-13 00:21:00 +02:00
|
|
|
worker_processes auto;
|
2017-09-24 13:09:12 +02:00
|
|
|
error_log /dev/stderr info;
|
|
|
|
pid /var/run/nginx.pid;
|
|
|
|
load_module "modules/ngx_mail_module.so";
|
|
|
|
|
|
|
|
events {
|
|
|
|
worker_connections 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
http {
|
|
|
|
# Standard HTTP configuration with slight hardening
|
|
|
|
include /etc/nginx/mime.types;
|
|
|
|
default_type application/octet-stream;
|
|
|
|
access_log /dev/stdout;
|
|
|
|
sendfile on;
|
|
|
|
keepalive_timeout 65;
|
|
|
|
server_tokens off;
|
2017-09-24 22:43:16 +02:00
|
|
|
absolute_redirect off;
|
2017-11-13 22:38:04 +02:00
|
|
|
resolver {{ RESOLVER }} valid=30s;
|
2017-09-24 13:09:12 +02:00
|
|
|
|
2017-10-22 15:01:04 +02:00
|
|
|
# Main HTTP server
|
2017-09-24 13:09:12 +02:00
|
|
|
server {
|
2017-11-13 22:38:04 +02:00
|
|
|
# Variables for proxifying
|
|
|
|
set $admin admin;
|
|
|
|
set $antispam antispam:11334;
|
|
|
|
set $webmail webmail;
|
|
|
|
set $webdav webdav:5232;
|
|
|
|
|
2017-10-22 11:31:32 +02:00
|
|
|
# Always listen over HTTP
|
2017-09-24 13:09:12 +02:00
|
|
|
listen 80;
|
2017-10-21 19:50:49 +02:00
|
|
|
listen [::]:80;
|
2017-09-24 13:09:12 +02:00
|
|
|
|
2017-10-22 11:31:32 +02:00
|
|
|
# Only enable HTTPS if TLS is enabled with no error
|
2017-09-24 17:50:10 +02:00
|
|
|
{% if TLS and not TLS_ERROR %}
|
2017-09-24 14:01:03 +02:00
|
|
|
listen 443 ssl;
|
2017-10-21 19:50:49 +02:00
|
|
|
listen [::]:443 ssl;
|
2017-10-22 11:31:32 +02:00
|
|
|
|
2017-09-24 18:43:14 +02:00
|
|
|
include /etc/nginx/tls.conf;
|
|
|
|
ssl_session_cache shared:SSLHTTP:50m;
|
2017-09-24 14:01:03 +02:00
|
|
|
add_header Strict-Transport-Security max-age=15768000;
|
|
|
|
|
2017-11-07 17:16:41 +02:00
|
|
|
{% if not TLS_FLAVOR == "mail" %}
|
2017-09-24 14:01:03 +02:00
|
|
|
if ($scheme = http) {
|
|
|
|
return 301 https://$host$request_uri;
|
|
|
|
}
|
|
|
|
{% endif %}
|
2017-11-07 17:16:41 +02:00
|
|
|
{% endif %}
|
2017-09-24 14:01:03 +02:00
|
|
|
|
2017-10-22 11:31:32 +02:00
|
|
|
# In any case, enable the proxy for certbot if the flavor is letsencrypt
|
2017-09-24 17:50:10 +02:00
|
|
|
{% if TLS_FLAVOR == 'letsencrypt' %}
|
|
|
|
location ^~ /.well-known/acme-challenge/ {
|
2017-11-13 22:38:04 +02:00
|
|
|
proxy_pass http://127.0.0.1:8008;
|
2017-09-24 17:50:10 +02:00
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
2017-10-22 11:31:32 +02:00
|
|
|
# If TLS is failing, prevent access to anything except certbot
|
2017-09-24 17:50:10 +02:00
|
|
|
{% if TLS_ERROR %}
|
|
|
|
location / {
|
2017-10-21 15:54:09 +02:00
|
|
|
return 403;
|
2017-09-24 17:50:10 +02:00
|
|
|
}
|
|
|
|
{% else %}
|
2017-10-22 11:31:32 +02:00
|
|
|
|
|
|
|
# Actual logic
|
2017-09-24 14:01:03 +02:00
|
|
|
{% if WEBMAIL != 'none' %}
|
2017-09-24 13:09:12 +02:00
|
|
|
location / {
|
|
|
|
return 301 $scheme://$host/webmail/;
|
|
|
|
}
|
|
|
|
|
2017-09-24 18:16:36 +02:00
|
|
|
location {{ WEB_WEBMAIL }} {
|
2017-11-10 17:04:40 +02:00
|
|
|
rewrite ^({{ WEB_WEBMAIL }})$ $1/ permanent;
|
2017-09-24 18:16:36 +02:00
|
|
|
rewrite ^{{ WEB_WEBMAIL }}/(.*) /$1 break;
|
2017-11-13 22:38:04 +02:00
|
|
|
proxy_set_header Host $host;
|
|
|
|
proxy_pass http://$webmail;
|
2017-09-24 13:09:12 +02:00
|
|
|
}
|
2017-09-24 14:01:03 +02:00
|
|
|
{% endif %}
|
2017-09-24 13:09:12 +02:00
|
|
|
|
2017-09-24 14:01:03 +02:00
|
|
|
{% if ADMIN == 'true' %}
|
2017-09-24 18:16:36 +02:00
|
|
|
location {{ WEB_ADMIN }} {
|
2017-09-24 22:43:16 +02:00
|
|
|
return 301 {{ WEB_ADMIN }}/ui;
|
2017-09-24 17:50:10 +02:00
|
|
|
}
|
2017-11-10 15:49:36 +02:00
|
|
|
|
2017-09-24 18:16:36 +02:00
|
|
|
location ~ {{ WEB_ADMIN }}/(ui|static) {
|
|
|
|
rewrite ^{{ WEB_ADMIN }}/(.*) /$1 break;
|
|
|
|
proxy_set_header X-Forwarded-Prefix {{ WEB_ADMIN }};
|
2017-11-13 22:38:04 +02:00
|
|
|
proxy_set_header Host $host;
|
|
|
|
proxy_pass http://$admin;
|
2017-09-24 13:09:12 +02:00
|
|
|
}
|
2017-11-10 15:49:36 +02:00
|
|
|
|
|
|
|
location {{ WEB_ADMIN }}/antispam {
|
|
|
|
rewrite ^{{ WEB_ADMIN }}/antispam/(.*) /$1 break;
|
|
|
|
auth_request /internal/auth/admin;
|
|
|
|
proxy_set_header X-Real-IP "";
|
|
|
|
proxy_set_header X-Forwarded-For "";
|
2017-11-13 22:38:04 +02:00
|
|
|
proxy_pass http://$antispam;
|
2017-11-10 15:49:36 +02:00
|
|
|
}
|
2017-09-24 14:01:03 +02:00
|
|
|
{% endif %}
|
2017-09-24 13:09:12 +02:00
|
|
|
|
2017-09-24 14:01:03 +02:00
|
|
|
{% if WEBDAV != 'none' %}
|
2017-09-24 13:09:12 +02:00
|
|
|
location /webdav {
|
2017-09-24 15:43:46 +02:00
|
|
|
rewrite ^/webdav/(.*) /$1 break;
|
2017-11-13 22:38:04 +02:00
|
|
|
proxy_pass http://$webdav;
|
2017-09-24 13:09:12 +02:00
|
|
|
}
|
2017-09-24 14:01:03 +02:00
|
|
|
{% endif %}
|
2017-09-24 17:50:10 +02:00
|
|
|
{% endif %}
|
2017-11-10 15:49:36 +02:00
|
|
|
|
|
|
|
location /internal {
|
|
|
|
internal;
|
|
|
|
|
2017-11-13 22:38:04 +02:00
|
|
|
proxy_pass http://$admin;
|
2017-11-10 15:49:36 +02:00
|
|
|
proxy_pass_request_body off;
|
|
|
|
proxy_set_header Content-Length "";
|
|
|
|
}
|
2017-09-24 13:09:12 +02:00
|
|
|
}
|
2017-10-22 15:01:04 +02:00
|
|
|
|
|
|
|
# Forwarding authentication server
|
|
|
|
server {
|
2017-11-18 16:22:03 +02:00
|
|
|
# Variables for proxifying
|
|
|
|
set $admin admin;
|
|
|
|
|
2017-10-22 15:01:04 +02:00
|
|
|
listen 127.0.0.1:8000;
|
|
|
|
|
2017-10-22 16:43:06 +02:00
|
|
|
location / {
|
2017-11-18 17:40:01 +02:00
|
|
|
proxy_pass http://$admin/internal$request_uri;
|
2017-10-22 15:01:04 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-24 13:09:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mail {
|
2017-09-24 17:50:10 +02:00
|
|
|
server_name {{ HOSTNAMES.split(",")[0] }};
|
2017-10-22 16:43:06 +02:00
|
|
|
auth_http http://127.0.0.1:8000/auth/email;
|
2017-09-24 13:09:12 +02:00
|
|
|
proxy_pass_error_message on;
|
|
|
|
|
2017-09-24 18:43:14 +02:00
|
|
|
{% if TLS and not TLS_ERROR %}
|
|
|
|
include /etc/nginx/tls.conf;
|
|
|
|
ssl_session_cache shared:SSLMAIL:50m;
|
|
|
|
{% endif %}
|
|
|
|
|
2017-10-22 11:31:32 +02:00
|
|
|
# Default SMTP server for the webmail (no encryption, but authentication)
|
|
|
|
server {
|
|
|
|
listen 10025;
|
|
|
|
protocol smtp;
|
|
|
|
smtp_auth plain;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Default IMAP server for the webmail (no encryption, but authentication)
|
|
|
|
server {
|
|
|
|
listen 10143;
|
|
|
|
protocol imap;
|
|
|
|
smtp_auth plain;
|
|
|
|
}
|
|
|
|
|
|
|
|
# SMTP is always enabled, to avoid losing emails when TLS is failing
|
2017-09-24 13:09:12 +02:00
|
|
|
server {
|
|
|
|
listen 25;
|
2017-10-21 19:50:49 +02:00
|
|
|
listen [::]:25;
|
2017-10-21 18:58:18 +02:00
|
|
|
{% if TLS and not TLS_ERROR %}
|
2017-11-03 21:37:10 +02:00
|
|
|
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
|
|
|
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
|
2017-09-24 18:43:14 +02:00
|
|
|
starttls on;
|
|
|
|
{% endif %}
|
2017-09-24 13:09:12 +02:00
|
|
|
protocol smtp;
|
2017-09-24 18:43:14 +02:00
|
|
|
smtp_auth none;
|
2017-09-24 13:09:12 +02:00
|
|
|
}
|
|
|
|
|
2017-10-22 11:31:32 +02:00
|
|
|
# All other protocols are disabled if TLS is failing
|
2017-09-24 18:43:14 +02:00
|
|
|
{% if not TLS_ERROR %}
|
2017-09-24 13:09:12 +02:00
|
|
|
server {
|
|
|
|
listen 143;
|
2017-10-21 19:50:49 +02:00
|
|
|
listen [::]:143;
|
2017-09-24 18:43:14 +02:00
|
|
|
{% if TLS %}
|
|
|
|
starttls only;
|
|
|
|
{% endif %}
|
|
|
|
protocol imap;
|
|
|
|
imap_auth plain;
|
|
|
|
}
|
|
|
|
|
2017-11-10 11:14:58 +02:00
|
|
|
server {
|
|
|
|
listen 110;
|
|
|
|
listen [::]:110;
|
|
|
|
{% if TLS %}
|
|
|
|
starttls only;
|
|
|
|
{% endif %}
|
|
|
|
protocol pop3;
|
|
|
|
pop3_auth plain;
|
|
|
|
}
|
|
|
|
|
2017-09-24 18:43:14 +02:00
|
|
|
server {
|
2017-10-22 15:01:04 +02:00
|
|
|
listen 587;
|
|
|
|
listen [::]:587;
|
|
|
|
{% if TLS %}
|
|
|
|
starttls only;
|
|
|
|
{% endif %}
|
2017-09-24 18:43:14 +02:00
|
|
|
protocol smtp;
|
|
|
|
smtp_auth plain;
|
|
|
|
}
|
|
|
|
|
2017-10-22 15:01:04 +02:00
|
|
|
{% if TLS %}
|
2017-09-24 18:43:14 +02:00
|
|
|
server {
|
2017-10-22 15:01:04 +02:00
|
|
|
listen 465 ssl;
|
|
|
|
listen [::]:465 ssl;
|
2017-09-24 18:43:14 +02:00
|
|
|
protocol smtp;
|
|
|
|
smtp_auth plain;
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 993 ssl;
|
2017-10-21 19:50:49 +02:00
|
|
|
listen [::]:993 ssl;
|
2017-09-24 13:09:12 +02:00
|
|
|
protocol imap;
|
|
|
|
imap_auth plain;
|
|
|
|
}
|
2017-11-10 11:14:58 +02:00
|
|
|
|
|
|
|
server {
|
|
|
|
listen 995 ssl;
|
|
|
|
listen [::]:995 ssl;
|
|
|
|
protocol pop3;
|
|
|
|
pop3_auth plain;
|
|
|
|
}
|
2017-09-24 18:43:14 +02:00
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
2017-09-24 13:09:12 +02:00
|
|
|
}
|