nginx.conf.j2 6.6 KB

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