nginx.conf.j2 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.* {{ 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 / {
  43. return 301 https://$host$uri$is_args$args;
  44. }
  45. }
  46. {%endif%}
  47. # Default Server Name
  48. server {
  49. listen 127.0.0.1:65510; # sogo-auth verify internal
  50. {% if not HTTP_REDIRECT %}
  51. listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  52. {%endif%}
  53. listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  54. {% if not DISABLE_IPv6 %}
  55. {% if not HTTP_REDIRECT %}
  56. listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  57. {%endif%}
  58. listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  59. {%endif%}
  60. http2 on;
  61. ssl_certificate /etc/ssl/mail/cert.pem;
  62. ssl_certificate_key /etc/ssl/mail/key.pem;
  63. server_name {{ MAILCOW_HOSTNAME }} autodiscover.* autoconfig.*;
  64. include /etc/nginx/includes/sites-default.conf;
  65. }
  66. # Additional Server Names
  67. {% for SERVER_NAME in ADDITIONAL_SERVER_NAMES %}
  68. server {
  69. listen 127.0.0.1:65510; # sogo-auth verify internal
  70. {% if not HTTP_REDIRECT %}
  71. listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  72. {%endif%}
  73. listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  74. {% if not DISABLE_IPv6 %}
  75. {% if not HTTP_REDIRECT %}
  76. listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  77. {%endif%}
  78. listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  79. {%endif%}
  80. http2 on;
  81. ssl_certificate /etc/ssl/mail/cert.pem;
  82. ssl_certificate_key /etc/ssl/mail/key.pem;
  83. server_name {{ SERVER_NAME }};
  84. include /etc/nginx/includes/sites-default.conf;
  85. }
  86. {% endfor %}
  87. # rspamd dynmaps:
  88. server {
  89. listen 8081;
  90. {% if not DISABLE_IPv6 %}
  91. listen [::]:8081;
  92. {%endif%}
  93. index index.php index.html;
  94. server_name _;
  95. error_log /var/log/nginx/error.log;
  96. access_log /var/log/nginx/access.log;
  97. root /dynmaps;
  98. location ~ \.php$ {
  99. try_files $uri =404;
  100. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  101. fastcgi_pass {{ PHPFPMHOST }}:9001;
  102. fastcgi_index index.php;
  103. include fastcgi_params;
  104. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  105. fastcgi_param PATH_INFO $fastcgi_path_info;
  106. }
  107. }
  108. # rspamd meta_exporter:
  109. server {
  110. listen 9081;
  111. index index.php index.html;
  112. server_name _;
  113. error_log /var/log/nginx/error.log;
  114. access_log /var/log/nginx/access.log;
  115. root /meta_exporter;
  116. client_max_body_size 10M;
  117. location ~ \.php$ {
  118. client_max_body_size 10M;
  119. try_files $uri =404;
  120. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  121. fastcgi_pass {{ PHPFPMHOST }}:9001;
  122. fastcgi_index pipe.php;
  123. include fastcgi_params;
  124. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  125. fastcgi_param PATH_INFO $fastcgi_path_info;
  126. }
  127. }
  128. server {
  129. listen 9082 ssl http2;
  130. ssl_certificate /etc/ssl/mail/cert.pem;
  131. ssl_certificate_key /etc/ssl/mail/key.pem;
  132. index mailcowauth.php;
  133. server_name _;
  134. error_log /var/log/nginx/error.log;
  135. access_log /var/log/nginx/access.log;
  136. root /mailcowauth;
  137. client_max_body_size 10M;
  138. location ~ \.php$ {
  139. client_max_body_size 10M;
  140. try_files $uri =404;
  141. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  142. fastcgi_pass phpfpm:9001;
  143. include fastcgi_params;
  144. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  145. fastcgi_param PATH_INFO $fastcgi_path_info;
  146. }
  147. }
  148. include /etc/nginx/conf.d/*.conf;
  149. {% for cert in valid_cert_dirs %}
  150. server {
  151. {% if not HTTP_REDIRECT %}
  152. listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  153. {%endif%}
  154. listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  155. {% if not DISABLE_IPv6 %}
  156. {% if not HTTP_REDIRECT %}
  157. listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
  158. {%endif%}
  159. listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
  160. {%endif%}
  161. http2 on;
  162. ssl_certificate {{ cert.cert_path }}cert.pem;
  163. ssl_certificate_key {{ cert.cert_path }}key.pem;
  164. server_name {{ cert.domains }};
  165. include /etc/nginx/includes/sites-default.conf;
  166. }
  167. {% endfor %}
  168. }