sites-default.conf.j2 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. include /etc/nginx/mime.types;
  2. charset utf-8;
  3. override_charset on;
  4. server_tokens off;
  5. ssl_protocols TLSv1.2 TLSv1.3;
  6. ssl_prefer_server_ciphers on;
  7. ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;
  8. ssl_ecdh_curve X25519:X448:secp384r1:secp256k1;
  9. ssl_session_cache shared:SSL:50m;
  10. ssl_session_timeout 1d;
  11. ssl_session_tickets off;
  12. add_header Strict-Transport-Security "max-age=15768000;";
  13. add_header X-Content-Type-Options nosniff;
  14. add_header X-XSS-Protection "1; mode=block";
  15. add_header X-Robots-Tag none;
  16. add_header X-Download-Options noopen;
  17. add_header X-Frame-Options "SAMEORIGIN" always;
  18. add_header X-Permitted-Cross-Domain-Policies none;
  19. add_header Referrer-Policy strict-origin;
  20. index index.php index.html;
  21. client_max_body_size 0;
  22. gzip on;
  23. gzip_disable "msie6";
  24. gzip_vary on;
  25. gzip_proxied off;
  26. gzip_comp_level 6;
  27. gzip_buffers 16 8k;
  28. gzip_http_version 1.1;
  29. gzip_min_length 256;
  30. gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
  31. location ~ ^/(fonts|js|css|img)/ {
  32. expires max;
  33. add_header Cache-Control public;
  34. }
  35. error_log /var/log/nginx/error.log;
  36. access_log /var/log/nginx/access.log;
  37. fastcgi_hide_header X-Powered-By;
  38. absolute_redirect off;
  39. root /web;
  40. # If behind reverse proxy, forwards the correct IP
  41. set_real_ip_from 10.0.0.0/8;
  42. set_real_ip_from 172.16.0.0/12;
  43. set_real_ip_from 192.168.0.0/16;
  44. set_real_ip_from fc00::/7;
  45. {% for TRUSTED_PROXY in TRUSTED_PROXIES %}
  46. set_real_ip_from {{ TRUSTED_PROXY }};
  47. {% endfor %}
  48. {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}
  49. real_ip_header X-Forwarded-For;
  50. {% else %}
  51. real_ip_header proxy_protocol;
  52. {% endif %}
  53. real_ip_recursive on;
  54. location @strip-ext {
  55. rewrite ^(.*)$ $1.php last;
  56. }
  57. location ^~ /inc/lib/ {
  58. deny all;
  59. return 403;
  60. }
  61. location ^~ /.well-known/acme-challenge/ {
  62. allow all;
  63. default_type "text/plain";
  64. }
  65. rewrite ^/.well-known/caldav$ /SOGo/dav/ permanent;
  66. rewrite ^/.well-known/carddav$ /SOGo/dav/ permanent;
  67. location / {
  68. try_files $uri $uri/ @strip-ext;
  69. }
  70. location /qhandler {
  71. rewrite ^/qhandler/(.*)/(.*) /qhandler.php?action=$1&hash=$2;
  72. }
  73. location /edit {
  74. rewrite ^/edit/(.*)/(.*) /edit.php?$1=$2;
  75. }
  76. location ~ ^/api/v1/(.*)$ {
  77. try_files $uri $uri/ /json_api.php?query=$1&$args;
  78. }
  79. location ~ ^/cache/(.*)$ {
  80. try_files $uri $uri/ /resource.php?file=$1;
  81. }
  82. location ~ \.php$ {
  83. try_files $uri =404;
  84. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  85. fastcgi_pass {{ PHPFPM_HOST }}:9002;
  86. fastcgi_index index.php;
  87. include /etc/nginx/fastcgi_params;
  88. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  89. fastcgi_param PATH_INFO $fastcgi_path_info;
  90. fastcgi_read_timeout 3600;
  91. fastcgi_send_timeout 3600;
  92. }
  93. location ~* ^/Autodiscover/Autodiscover.xml {
  94. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  95. fastcgi_pass {{ PHPFPM_HOST }}:9002;
  96. include /etc/nginx/fastcgi_params;
  97. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  98. try_files /autodiscover.php =404;
  99. }
  100. location ~* ^/Autodiscover/Autodiscover.json {
  101. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  102. fastcgi_pass {{ PHPFPM_HOST }}:9002;
  103. include /etc/nginx/fastcgi_params;
  104. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  105. try_files /autodiscover-json.php =404;
  106. }
  107. location ~ /(?:m|M)ail/(?:c|C)onfig-v1.1.xml {
  108. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  109. fastcgi_pass {{ PHPFPM_HOST }}:9002;
  110. include /etc/nginx/fastcgi_params;
  111. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  112. try_files /autoconfig.php =404;
  113. }
  114. {% if not SKIP_RSPAMD|lower in ["y", "yes"] %}
  115. location /rspamd/ {
  116. location /rspamd/auth {
  117. # proxy_pass is not inherited
  118. proxy_pass http://{{ RSPAMD_HOST }}:11334/auth;
  119. proxy_intercept_errors on;
  120. proxy_set_header Host $http_host;
  121. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  122. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  123. proxy_redirect off;
  124. error_page 401 /_rspamderror.php;
  125. }
  126. proxy_pass http://{{ RSPAMD_HOST }}:11334/;
  127. proxy_set_header Host $http_host;
  128. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  129. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  130. proxy_redirect off;
  131. }
  132. {% endif %}
  133. {% if not SKIP_SOGO|lower in ["y", "yes"] %}
  134. location ^~ /principals {
  135. return 301 /SOGo/dav;
  136. }
  137. location /sogo-auth-verify {
  138. internal;
  139. proxy_set_header X-Original-URI $request_uri;
  140. proxy_set_header X-Real-IP $remote_addr;
  141. proxy_set_header Host $http_host;
  142. proxy_set_header Content-Length "";
  143. proxy_pass http://127.0.0.1:65510/sogo-auth;
  144. proxy_pass_request_body off;
  145. }
  146. location ^~ /Microsoft-Server-ActiveSync {
  147. auth_request /sogo-auth-verify;
  148. auth_request_set $user $upstream_http_x_user;
  149. auth_request_set $auth $upstream_http_x_auth;
  150. auth_request_set $auth_type $upstream_http_x_auth_type;
  151. proxy_set_header x-webobjects-remote-user "$user";
  152. proxy_set_header Authorization "$auth";
  153. proxy_set_header x-webobjects-auth-type "$auth_type";
  154. proxy_pass http://{{ SOGO_HOST }}:20000/SOGo/Microsoft-Server-ActiveSync;
  155. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  156. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  157. proxy_connect_timeout 75;
  158. proxy_send_timeout 3600;
  159. proxy_read_timeout 3600;
  160. proxy_buffer_size 128k;
  161. proxy_buffers 64 512k;
  162. proxy_busy_buffers_size 512k;
  163. proxy_set_header Host $http_host;
  164. client_body_buffer_size 512k;
  165. client_max_body_size 0;
  166. }
  167. location ^~ /SOGo {
  168. location ~* ^/SOGo/so/.*\.(xml|js|html|xhtml)$ {
  169. auth_request /sogo-auth-verify;
  170. auth_request_set $user $upstream_http_x_user;
  171. auth_request_set $auth $upstream_http_x_auth;
  172. auth_request_set $auth_type $upstream_http_x_auth_type;
  173. proxy_set_header x-webobjects-remote-user "$user";
  174. proxy_set_header Authorization "$auth";
  175. proxy_set_header x-webobjects-auth-type "$auth_type";
  176. proxy_pass http://{{ SOGO_HOST }}:20000;
  177. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  178. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  179. proxy_set_header Host $http_host;
  180. proxy_set_header x-webobjects-server-protocol HTTP/1.0;
  181. proxy_set_header x-webobjects-remote-host $remote_addr;
  182. proxy_set_header x-webobjects-server-name $server_name;
  183. proxy_set_header x-webobjects-server-url $client_req_scheme://$http_host;
  184. proxy_set_header x-webobjects-server-port $server_port;
  185. proxy_hide_header Content-Type;
  186. add_header Content-Type text/plain;
  187. break;
  188. }
  189. auth_request /sogo-auth-verify;
  190. auth_request_set $user $upstream_http_x_user;
  191. auth_request_set $auth $upstream_http_x_auth;
  192. auth_request_set $auth_type $upstream_http_x_auth_type;
  193. proxy_set_header x-webobjects-remote-user "$user";
  194. proxy_set_header Authorization "$auth";
  195. proxy_set_header x-webobjects-auth-type "$auth_type";
  196. proxy_pass http://{{ SOGO_HOST }}:20000;
  197. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  198. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL|lower in ["y", "yes"] %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  199. proxy_set_header Host $http_host;
  200. proxy_set_header x-webobjects-server-protocol HTTP/1.0;
  201. proxy_set_header x-webobjects-remote-host $remote_addr;
  202. proxy_set_header x-webobjects-server-name $server_name;
  203. proxy_set_header x-webobjects-server-url $client_req_scheme://$http_host;
  204. proxy_set_header x-webobjects-server-port $server_port;
  205. proxy_buffer_size 128k;
  206. proxy_buffers 64 512k;
  207. proxy_busy_buffers_size 512k;
  208. proxy_send_timeout 3600;
  209. proxy_read_timeout 3600;
  210. client_body_buffer_size 128k;
  211. client_max_body_size 0;
  212. break;
  213. }
  214. location ~* /sogo$ {
  215. return 301 $client_req_scheme://$http_host/SOGo;
  216. }
  217. location /SOGo.woa/WebServerResources/ {
  218. alias /usr/lib/GNUstep/SOGo/WebServerResources/;
  219. }
  220. location /.woa/WebServerResources/ {
  221. alias /usr/lib/GNUstep/SOGo/WebServerResources/;
  222. }
  223. location /SOGo/WebServerResources/ {
  224. alias /usr/lib/GNUstep/SOGo/WebServerResources/;
  225. }
  226. location (^/SOGo/so/ControlPanel/Products/[^/]*UI/Resources/.*\.(jpg|png|gif|css|js)$) {
  227. alias /usr/lib/GNUstep/SOGo/$1.SOGo/Resources/$2;
  228. }
  229. {% endif %}
  230. include /etc/nginx/conf.d/site.*.custom;
  231. error_page 502 @awaitingupstream;
  232. location @awaitingupstream {
  233. rewrite ^(.*)$ /_status.502.html break;
  234. }
  235. location ~* \.php$ {
  236. return 404;
  237. }
  238. location ~* \.twig$ {
  239. return 404;
  240. }