2017-09-24 13:09:12 +02:00
|
|
|
# Basic configuration
|
|
|
|
user nginx;
|
2017-09-24 14:01:03 +02:00
|
|
|
worker_processes 4;
|
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-09-24 13:09:12 +02:00
|
|
|
|
|
|
|
server {
|
|
|
|
listen 80;
|
|
|
|
|
2017-09-24 17:50:10 +02:00
|
|
|
# TLS configuration
|
|
|
|
{% if TLS and not TLS_ERROR %}
|
2017-09-24 14:01:03 +02:00
|
|
|
listen 443 ssl;
|
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;
|
|
|
|
|
|
|
|
if ($scheme = http) {
|
|
|
|
return 301 https://$host$request_uri;
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
2017-09-24 17:50:10 +02:00
|
|
|
{% if TLS_FLAVOR == 'letsencrypt' %}
|
|
|
|
location ^~ /.well-known/acme-challenge/ {
|
|
|
|
proxy_pass http://localhost:8000;
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
2017-09-24 13:09:12 +02:00
|
|
|
# Actual logic
|
2017-09-24 17:50:10 +02:00
|
|
|
{% if TLS_ERROR %}
|
|
|
|
location / {
|
|
|
|
return 403
|
|
|
|
}
|
|
|
|
{% else %}
|
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 }} {
|
|
|
|
rewrite ^{{ WEB_WEBMAIL }}/(.*) /$1 break;
|
2017-09-24 13:09:12 +02:00
|
|
|
proxy_pass http://webmail;
|
|
|
|
}
|
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-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-09-24 13:09:12 +02:00
|
|
|
proxy_pass http://admin;
|
|
|
|
}
|
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-09-24 13:09:12 +02:00
|
|
|
proxy_pass http://webdav:5232;
|
|
|
|
}
|
2017-09-24 14:01:03 +02:00
|
|
|
{% endif %}
|
2017-09-24 17:50:10 +02:00
|
|
|
{% endif %}
|
2017-09-24 13:09:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mail {
|
2017-09-24 17:50:10 +02:00
|
|
|
server_name {{ HOSTNAMES.split(",")[0] }};
|
2017-09-24 15:43:46 +02:00
|
|
|
auth_http http://{{ ADMIN_ADDRESS }}/internal/nginx;
|
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-09-24 13:09:12 +02:00
|
|
|
server {
|
|
|
|
listen 25;
|
2017-09-24 18:43:14 +02:00
|
|
|
{% if TLS_FLAVOR != 'notls' %}
|
|
|
|
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-09-24 18:43:14 +02:00
|
|
|
{% if not TLS_ERROR %}
|
2017-09-24 13:09:12 +02:00
|
|
|
server {
|
|
|
|
listen 143;
|
2017-09-24 18:43:14 +02:00
|
|
|
{% if TLS %}
|
|
|
|
starttls only;
|
|
|
|
{% endif %}
|
|
|
|
protocol imap;
|
|
|
|
imap_auth plain;
|
|
|
|
}
|
|
|
|
|
|
|
|
{% if TLS %}
|
|
|
|
server {
|
|
|
|
listen 465 ssl;
|
|
|
|
protocol smtp;
|
|
|
|
smtp_auth plain;
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 597;
|
|
|
|
starttls only;
|
|
|
|
protocol smtp;
|
|
|
|
smtp_auth plain;
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 993 ssl;
|
2017-09-24 13:09:12 +02:00
|
|
|
protocol imap;
|
|
|
|
imap_auth plain;
|
|
|
|
}
|
2017-09-24 18:43:14 +02:00
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
2017-09-24 13:09:12 +02:00
|
|
|
}
|