|
|
|
# Basic configuration
|
|
|
|
user nginx;
|
|
|
|
worker_processes 4;
|
|
|
|
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;
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 80;
|
|
|
|
|
|
|
|
# TLS configuration
|
|
|
|
{% if TLS and not TLS_ERROR %}
|
|
|
|
listen 443 ssl;
|
|
|
|
|
|
|
|
ssl_protocols TLSv1.1 TLSv1.2;
|
|
|
|
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';
|
|
|
|
ssl_prefer_server_ciphers on;
|
|
|
|
ssl_session_timeout 5m;
|
|
|
|
ssl_session_cache shared:SSL:50m;
|
|
|
|
ssl_certificate {{ TLS[0] }};
|
|
|
|
ssl_certificate_key {{ TLS[1] }};
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security max-age=15768000;
|
|
|
|
|
|
|
|
if ($scheme = http) {
|
|
|
|
return 301 https://$host$request_uri;
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if TLS_FLAVOR == 'letsencrypt' %}
|
|
|
|
location ^~ /.well-known/acme-challenge/ {
|
|
|
|
proxy_pass http://localhost:8000;
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
# Actual logic
|
|
|
|
{% if TLS_ERROR %}
|
|
|
|
location / {
|
|
|
|
return 403
|
|
|
|
}
|
|
|
|
{% else %}
|
|
|
|
{% if WEBMAIL != 'none' %}
|
|
|
|
location / {
|
|
|
|
return 301 $scheme://$host/webmail/;
|
|
|
|
}
|
|
|
|
|
|
|
|
location {{ WEB_WEBMAIL }} {
|
|
|
|
rewrite ^{{ WEB_WEBMAIL }}/(.*) /$1 break;
|
|
|
|
proxy_pass http://webmail;
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if ADMIN == 'true' %}
|
|
|
|
location {{ WEB_ADMIN }} {
|
|
|
|
return 301 $scheme://$host{{ WEB_ADMIN }}/ui;
|
|
|
|
}
|
|
|
|
location ~ {{ WEB_ADMIN }}/(ui|static) {
|
|
|
|
rewrite ^{{ WEB_ADMIN }}/(.*) /$1 break;
|
|
|
|
proxy_set_header X-Forwarded-Prefix {{ WEB_ADMIN }};
|
|
|
|
proxy_pass http://admin;
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if WEBDAV != 'none' %}
|
|
|
|
location /webdav {
|
|
|
|
rewrite ^/webdav/(.*) /$1 break;
|
|
|
|
proxy_pass http://webdav:5232;
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mail {
|
|
|
|
server_name {{ HOSTNAMES.split(",")[0] }};
|
|
|
|
auth_http http://{{ ADMIN_ADDRESS }}/internal/nginx;
|
|
|
|
proxy_pass_error_message on;
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 25;
|
|
|
|
protocol smtp;
|
|
|
|
smtp_auth plain;
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 143;
|
|
|
|
protocol imap;
|
|
|
|
imap_auth plain;
|
|
|
|
}
|
|
|
|
}
|