sites-default.conf.j2 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 %}
  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. location ^~ /.well-known/mta-sts.txt {
  66. allow all;
  67. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  68. fastcgi_pass {{ PHPFPMHOST }}:9002;
  69. include /etc/nginx/fastcgi_params;
  70. fastcgi_param SCRIPT_FILENAME $document_root/mta-sts.php;
  71. fastcgi_param PATH_INFO $fastcgi_path_info;
  72. }
  73. rewrite ^/.well-known/caldav$ /SOGo/dav/ permanent;
  74. rewrite ^/.well-known/carddav$ /SOGo/dav/ permanent;
  75. location / {
  76. try_files $uri $uri/ @strip-ext;
  77. }
  78. location /qhandler {
  79. rewrite ^/qhandler/(.*)/(.*) /qhandler.php?action=$1&hash=$2;
  80. }
  81. location /edit {
  82. rewrite ^/edit/(.*)/(.*) /edit.php?$1=$2;
  83. }
  84. location ~ ^/api/v1/(.*)$ {
  85. try_files $uri $uri/ /json_api.php?query=$1&$args;
  86. }
  87. location ~ ^/cache/(.*)$ {
  88. try_files $uri $uri/ /resource.php?file=$1;
  89. }
  90. location ~ \.php$ {
  91. try_files $uri =404;
  92. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  93. fastcgi_pass {{ PHPFPMHOST }}:9002;
  94. fastcgi_index index.php;
  95. include /etc/nginx/fastcgi_params;
  96. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  97. fastcgi_param PATH_INFO $fastcgi_path_info;
  98. fastcgi_read_timeout 3600;
  99. fastcgi_send_timeout 3600;
  100. }
  101. location ~* ^/Autodiscover/Autodiscover.xml {
  102. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  103. fastcgi_pass {{ PHPFPMHOST }}:9002;
  104. include /etc/nginx/fastcgi_params;
  105. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  106. try_files /autodiscover.php =404;
  107. }
  108. location ~* ^/Autodiscover/Autodiscover.json {
  109. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  110. fastcgi_pass {{ PHPFPMHOST }}:9002;
  111. include /etc/nginx/fastcgi_params;
  112. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  113. try_files /autodiscover-json.php =404;
  114. }
  115. location ~ /(?:m|M)ail/(?:c|C)onfig-v1.1.xml {
  116. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  117. fastcgi_pass {{ PHPFPMHOST }}:9002;
  118. include /etc/nginx/fastcgi_params;
  119. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  120. try_files /autoconfig.php =404;
  121. }
  122. {% if not SKIP_RSPAMD %}
  123. location /rspamd/ {
  124. location /rspamd/auth {
  125. # proxy_pass is not inherited
  126. proxy_pass http://{{ RSPAMDHOST }}:11334/auth;
  127. proxy_intercept_errors on;
  128. proxy_set_header Host $http_host;
  129. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  130. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  131. proxy_redirect off;
  132. error_page 401 /_rspamderror.php;
  133. }
  134. proxy_pass http://{{ RSPAMDHOST }}:11334/;
  135. proxy_set_header Host $http_host;
  136. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  137. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  138. proxy_redirect off;
  139. }
  140. {% endif %}
  141. {% if not SKIP_SOGO %}
  142. location ^~ /principals {
  143. return 301 /SOGo/dav;
  144. }
  145. location /sogo-auth-verify {
  146. internal;
  147. proxy_set_header X-Original-URI $request_uri;
  148. proxy_set_header X-Real-IP $remote_addr;
  149. proxy_set_header Host $http_host;
  150. proxy_set_header Content-Length "";
  151. proxy_pass http://127.0.0.1:65510/sogo-auth;
  152. proxy_pass_request_body off;
  153. }
  154. location ^~ /Microsoft-Server-ActiveSync {
  155. auth_request /sogo-auth-verify;
  156. auth_request_set $user $upstream_http_x_user;
  157. auth_request_set $auth $upstream_http_x_auth;
  158. auth_request_set $auth_type $upstream_http_x_auth_type;
  159. proxy_set_header x-webobjects-remote-user "$user";
  160. proxy_set_header Authorization "$auth";
  161. proxy_set_header x-webobjects-auth-type "$auth_type";
  162. proxy_pass http://{{ SOGOHOST }}:20000/SOGo/Microsoft-Server-ActiveSync;
  163. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  164. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  165. proxy_connect_timeout 75;
  166. proxy_send_timeout 3600;
  167. proxy_read_timeout 3600;
  168. proxy_buffer_size 128k;
  169. proxy_buffers 64 512k;
  170. proxy_busy_buffers_size 512k;
  171. proxy_set_header Host $http_host;
  172. client_body_buffer_size 512k;
  173. client_max_body_size 0;
  174. }
  175. location ^~ /SOGo {
  176. location ~* ^/SOGo/so/.*\.(xml|js|html|xhtml)$ {
  177. auth_request /sogo-auth-verify;
  178. auth_request_set $user $upstream_http_x_user;
  179. auth_request_set $auth $upstream_http_x_auth;
  180. auth_request_set $auth_type $upstream_http_x_auth_type;
  181. proxy_set_header x-webobjects-remote-user "$user";
  182. proxy_set_header Authorization "$auth";
  183. proxy_set_header x-webobjects-auth-type "$auth_type";
  184. proxy_pass http://{{ SOGOHOST }}:20000;
  185. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  186. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  187. proxy_set_header Host $http_host;
  188. proxy_set_header x-webobjects-server-protocol HTTP/1.0;
  189. proxy_set_header x-webobjects-remote-host $remote_addr;
  190. proxy_set_header x-webobjects-server-name $server_name;
  191. proxy_set_header x-webobjects-server-url $client_req_scheme://$http_host;
  192. proxy_set_header x-webobjects-server-port $server_port;
  193. proxy_hide_header Content-Type;
  194. add_header Content-Type text/plain;
  195. break;
  196. }
  197. auth_request /sogo-auth-verify;
  198. auth_request_set $user $upstream_http_x_user;
  199. auth_request_set $auth $upstream_http_x_auth;
  200. auth_request_set $auth_type $upstream_http_x_auth_type;
  201. proxy_set_header x-webobjects-remote-user "$user";
  202. proxy_set_header Authorization "$auth";
  203. proxy_set_header x-webobjects-auth-type "$auth_type";
  204. proxy_pass http://{{ SOGOHOST }}:20000;
  205. proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
  206. proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
  207. proxy_set_header Host $http_host;
  208. proxy_set_header x-webobjects-server-protocol HTTP/1.0;
  209. proxy_set_header x-webobjects-remote-host $remote_addr;
  210. proxy_set_header x-webobjects-server-name $server_name;
  211. proxy_set_header x-webobjects-server-url $client_req_scheme://$http_host;
  212. proxy_set_header x-webobjects-server-port $server_port;
  213. proxy_buffer_size 128k;
  214. proxy_buffers 64 512k;
  215. proxy_busy_buffers_size 512k;
  216. proxy_send_timeout 3600;
  217. proxy_read_timeout 3600;
  218. client_body_buffer_size 128k;
  219. client_max_body_size 0;
  220. break;
  221. }
  222. location ~* /sogo$ {
  223. return 301 $client_req_scheme://$http_host/SOGo;
  224. }
  225. location /SOGo.woa/WebServerResources/ {
  226. alias /usr/lib/GNUstep/SOGo/WebServerResources/;
  227. }
  228. location /.woa/WebServerResources/ {
  229. alias /usr/lib/GNUstep/SOGo/WebServerResources/;
  230. }
  231. location /SOGo/WebServerResources/ {
  232. alias /usr/lib/GNUstep/SOGo/WebServerResources/;
  233. }
  234. location (^/SOGo/so/ControlPanel/Products/[^/]*UI/Resources/.*\.(jpg|png|gif|css|js)$) {
  235. alias /usr/lib/GNUstep/SOGo/$1.SOGo/Resources/$2;
  236. }
  237. {% endif %}
  238. include /etc/nginx/conf.d/site.*.custom;
  239. error_page 502 @awaitingupstream;
  240. location @awaitingupstream {
  241. rewrite ^(.*)$ /_status.502.html break;
  242. }
  243. location ~* \.php$ {
  244. return 404;
  245. }
  246. location ~* \.twig$ {
  247. return 404;
  248. }