sites-default.conf.j2 9.5 KB

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