nginx.conf.j2 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. user nginx;
  2. worker_processes auto;
  3. error_log /var/log/nginx/error.log notice;
  4. pid /var/run/nginx.pid;
  5. events {
  6. worker_connections 1024;
  7. }
  8. http {
  9. include /etc/nginx/mime.types;
  10. default_type application/octet-stream;
  11. server_tokens off;
  12. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  13. '$status $body_bytes_sent "$http_referer" '
  14. '"$http_user_agent" "$http_x_forwarded_for"';
  15. access_log /var/log/nginx/access.log main;
  16. sendfile on;
  17. #tcp_nopush on;
  18. keepalive_timeout 65;
  19. #gzip on;
  20. # map-size.conf:
  21. map_hash_max_size 256;
  22. map_hash_bucket_size 256;
  23. # site.conf:
  24. proxy_cache_path /tmp levels=1:2 keys_zone=sogo:10m inactive=24h max_size=1g;
  25. server_names_hash_max_size 512;
  26. server_names_hash_bucket_size 128;
  27. map $http_x_forwarded_proto $client_req_scheme {
  28. default $scheme;
  29. https https;
  30. }
  31. {% if HTTP_REDIRECT %}
  32. # HTTP to HTTPS redirect
  33. server {
  34. root /web;
  35. listen {{ HTTP_PORT }} default_server;
  36. listen [::]:{{ HTTP_PORT }} default_server;
  37. server_name {{ MAILCOW_HOSTNAME }} autodiscover.* autoconfig.* mta-sts.* {{ ADDITIONAL_SERVER_NAMES | join(' ') }};
  38. if ( $request_uri ~* "%0A|%0D" ) { return 403; }
  39. location ^~ /.well-known/acme-challenge/ {
  40. allow all;
  41. default_type "text/plain";
  42. }
  43. location ^~ /.well-known/mta-sts.txt {
  44. allow all;
  45. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  46. fastcgi_pass {{ PHPFPMHOST }}:9002;
  47. include /etc/nginx/fastcgi_params;
  48. fastcgi_param SCRIPT_FILENAME $document_root/mta-sts.php;
  49. fastcgi_param PATH_INFO $fastcgi_path_info;
  50. }
  51. location / {
  52. return 301 https://$host$uri$is_args$args;
  53. }
  54. }
  55. {%endif%}
  56. # Default Server Name
  57. server {
  58. listen 127.0.0.1:65510; # sogo-auth verify internal
  59. {% if not HTTP_REDIRECT %}
  60. listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  61. {%endif%}
  62. listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  63. {% if ENABLE_IPV6 %}
  64. {% if not HTTP_REDIRECT %}
  65. listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  66. {%endif%}
  67. listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  68. {%endif%}
  69. http2 on;
  70. ssl_certificate /etc/ssl/mail/cert.pem;
  71. ssl_certificate_key /etc/ssl/mail/key.pem;
  72. server_name {{ MAILCOW_HOSTNAME }} autodiscover.* autoconfig.* mta-sts.*;
  73. include /etc/nginx/includes/sites-default.conf;
  74. }
  75. # Additional Server Names
  76. {% for SERVER_NAME in ADDITIONAL_SERVER_NAMES %}
  77. server {
  78. listen 127.0.0.1:65510; # sogo-auth verify internal
  79. {% if not HTTP_REDIRECT %}
  80. listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  81. {%endif%}
  82. listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  83. {% if ENABLE_IPV6 %}
  84. {% if not HTTP_REDIRECT %}
  85. listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  86. {%endif%}
  87. listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  88. {%endif%}
  89. http2 on;
  90. ssl_certificate /etc/ssl/mail/cert.pem;
  91. ssl_certificate_key /etc/ssl/mail/key.pem;
  92. server_name {{ SERVER_NAME }};
  93. include /etc/nginx/includes/sites-default.conf;
  94. }
  95. {% endfor %}
  96. # rspamd dynmaps:
  97. server {
  98. listen 8081;
  99. {% if ENABLE_IPV6 %}
  100. listen [::]:8081;
  101. {%endif%}
  102. index index.php index.html;
  103. server_name _;
  104. error_log /var/log/nginx/error.log;
  105. access_log /var/log/nginx/access.log;
  106. root /dynmaps;
  107. location ~ \.php$ {
  108. try_files $uri =404;
  109. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  110. fastcgi_pass {{ PHPFPMHOST }}:9001;
  111. fastcgi_index index.php;
  112. include fastcgi_params;
  113. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  114. fastcgi_param PATH_INFO $fastcgi_path_info;
  115. }
  116. }
  117. # rspamd meta_exporter:
  118. server {
  119. listen 9081;
  120. index index.php index.html;
  121. server_name _;
  122. error_log /var/log/nginx/error.log;
  123. access_log /var/log/nginx/access.log;
  124. root /meta_exporter;
  125. client_max_body_size 10M;
  126. location ~ \.php$ {
  127. client_max_body_size 10M;
  128. try_files $uri =404;
  129. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  130. fastcgi_pass {{ PHPFPMHOST }}:9001;
  131. fastcgi_index pipe.php;
  132. include fastcgi_params;
  133. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  134. fastcgi_param PATH_INFO $fastcgi_path_info;
  135. }
  136. }
  137. server {
  138. listen 9082 ssl http2;
  139. ssl_certificate /etc/ssl/mail/cert.pem;
  140. ssl_certificate_key /etc/ssl/mail/key.pem;
  141. index mailcowauth.php;
  142. server_name _;
  143. error_log /var/log/nginx/error.log;
  144. access_log /var/log/nginx/access.log;
  145. root /mailcowauth;
  146. client_max_body_size 10M;
  147. location ~ \.php$ {
  148. client_max_body_size 10M;
  149. try_files $uri =404;
  150. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  151. fastcgi_pass phpfpm:9001;
  152. include fastcgi_params;
  153. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  154. fastcgi_param PATH_INFO $fastcgi_path_info;
  155. }
  156. }
  157. include /etc/nginx/conf.d/*.conf;
  158. {% for cert in valid_cert_dirs %}
  159. server {
  160. {% if not HTTP_REDIRECT %}
  161. listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  162. {%endif%}
  163. listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  164. {% if ENABLE_IPV6 %}
  165. {% if not HTTP_REDIRECT %}
  166. listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  167. {%endif%}
  168. listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  169. {%endif%}
  170. http2 on;
  171. ssl_certificate {{ cert.cert_path }}cert.pem;
  172. ssl_certificate_key {{ cert.cert_path }}key.pem;
  173. server_name {{ cert.domains }};
  174. include /etc/nginx/includes/sites-default.conf;
  175. }
  176. {% endfor %}
  177. }