@@ -41,25 +41,80 @@ http {
41
41
https https;
42
42
}
43
43
44
- # Default
44
+ {% if HTTP_REDIRECT %}
45
+ # HTTP to HTTPS redirect
46
+ server {
47
+ root /web;
48
+ listen {{ HTTP_PORT }} default_server;
49
+ listen [::]:{{ HTTP_PORT }} default_server;
50
+
51
+ server_name {{ MAILCOW_HOSTNAME }} autodiscover.* autoconfig.* {{ ADDITIONAL_SERVER_NAMES | join(' ') }};
52
+
53
+ if ( $request_uri ~* "%0A|%0D" ) { return 403; }
54
+ location ^~ /.well-known/acme-challenge/ {
55
+ allow all;
56
+ default_type "text/plain";
57
+ }
58
+ location / {
59
+ return 301 https://$host$uri$is_args$args;
60
+ }
61
+ }
62
+ {% endif %}
63
+
64
+ # Default Server Name
45
65
server {
46
66
listen 127.0.0.1:65510; # sogo-auth verify internal
67
+
68
+ {% if not HTTP_REDIRECT %}
47
69
listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ;
70
+ {% endif %}
48
71
listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ssl;
72
+
49
73
{% if not DISABLE_IPv 6 %}
74
+ {% if not HTTP_REDIRECT %}
50
75
listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ;
76
+ {% endif %}
51
77
listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ssl;
52
78
{% endif %}
79
+
53
80
http2 on;
54
81
55
82
ssl_certificate /etc/ssl/mail/cert.pem;
56
83
ssl_certificate_key /etc/ssl/mail/key.pem;
57
84
58
- server_name {{ MAILCOW_HOSTNAME }} autodiscover.* autoconfig.* {{ ADDITIONAL_SERVER_NAMES }} ;
85
+ server_name {{ MAILCOW_HOSTNAME }} autodiscover.* autoconfig.*;
59
86
60
87
include /etc/nginx/includes/sites-default.conf;
61
88
}
62
89
90
+ # Additional Server Names
91
+ {% for SERVER_NAME in ADDITIONAL_SERVER_NAMES %}
92
+ server {
93
+ listen 127.0.0.1:65510; # sogo-auth verify internal
94
+
95
+ {% if not HTTP_REDIRECT %}
96
+ listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ;
97
+ {% endif %}
98
+ listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ssl;
99
+
100
+ {% if not DISABLE_IPv 6 %}
101
+ {% if not HTTP_REDIRECT %}
102
+ listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ;
103
+ {% endif %}
104
+ listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ssl;
105
+ {% endif %}
106
+
107
+ http2 on;
108
+
109
+ ssl_certificate /etc/ssl/mail/cert.pem;
110
+ ssl_certificate_key /etc/ssl/mail/key.pem;
111
+
112
+ server_name {{ SERVER_NAME }};
113
+
114
+ include /etc/nginx/includes/sites-default.conf;
115
+ }
116
+ {% endfor %}
117
+
63
118
# rspamd dynmaps:
64
119
server {
65
120
listen 8081;
@@ -106,12 +161,18 @@ http {
106
161
107
162
{% for cert in valid_cert_dirs %}
108
163
server {
164
+ {% if not HTTP_REDIRECT %}
109
165
listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ;
166
+ {% endif %}
110
167
listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ssl;
168
+
111
169
{% if not DISABLE_IPv 6 %}
170
+ {% if not HTTP_REDIRECT %}
112
171
listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ;
172
+ {% endif %}
113
173
listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{% endif %} ssl;
114
174
{% endif %}
175
+
115
176
http2 on;
116
177
117
178
ssl_certificate {{ cert.cert_path }}cert.pem;
0 commit comments