_nginx-configuration.tpl 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. {{- define "nginx.configuration" -}}
  2. {{- $fullname := (include "ix.v1.common.lib.chart.names.fullname" $) -}}
  3. {{- if .Values.ncNetwork.certificateID }}
  4. scaleCertificate:
  5. nextcloud-cert:
  6. enabled: true
  7. id: {{ .Values.ncNetwork.certificateID }}
  8. {{ $timeout := 60 }}
  9. {{ $size := .Values.ncConfig.maxUploadLimit | default 3 }}
  10. {{ $useDiffAccessPort := false }}
  11. {{ $externalAccessPort := ":$server_port" }}
  12. {{/* Safely access key as it is conditionaly shown */}}
  13. {{ if hasKey .Values.ncNetwork "nginx" }}
  14. {{ $useDiffAccessPort = .Values.ncNetwork.nginx.useDifferentAccessPort }}
  15. {{ $externalAccessPort = printf ":%v" .Values.ncNetwork.nginx.externalAccessPort }}
  16. {{ $timeout = .Values.ncNetwork.nginx.proxyTimeouts | default 60 }}
  17. {{ end }}
  18. {{/* If its 443, do not append it on the rewrite at all */}}
  19. {{ if eq $externalAccessPort ":443" }}
  20. {{ $externalAccessPort = "" }}
  21. {{ end }}
  22. configmap:
  23. nginx:
  24. enabled: true
  25. data:
  26. nginx.conf: |
  27. events {}
  28. http {
  29. server {
  30. listen {{ .Values.ncNetwork.webPort }} ssl http2;
  31. listen [::]:{{ .Values.ncNetwork.webPort }} ssl http2;
  32. # Redirect HTTP to HTTPS
  33. error_page 497 301 =307 https://$host{{ $externalAccessPort }}$request_uri;
  34. ssl_certificate '/etc/nginx-certs/public.crt';
  35. ssl_certificate_key '/etc/nginx-certs/private.key';
  36. client_max_body_size {{ $size }}G;
  37. add_header Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" always;
  38. location = /robots.txt {
  39. allow all;
  40. log_not_found off;
  41. access_log off;
  42. }
  43. location = /.well-known/carddav {
  44. return 301 $scheme://$host{{ $externalAccessPort }}/remote.php/dav;
  45. }
  46. location = /.well-known/caldav {
  47. return 301 $scheme://$host{{ $externalAccessPort }}/remote.php/dav;
  48. }
  49. location / {
  50. proxy_pass http://{{ $fullname }}:80;
  51. proxy_http_version 1.1;
  52. proxy_cache_bypass $http_upgrade;
  53. proxy_request_buffering off;
  54. # Proxy headers
  55. proxy_set_header Upgrade $http_upgrade;
  56. proxy_set_header Connection "upgrade";
  57. proxy_set_header Host $http_host;
  58. proxy_set_header X-Real-IP $remote_addr;
  59. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  60. proxy_set_header X-Forwarded-Proto https;
  61. proxy_set_header X-Forwarded-Host $host;
  62. proxy_set_header X-Forwarded-Port {{ $externalAccessPort | default "443" | trimPrefix ":" }};
  63. # Proxy timeouts
  64. proxy_connect_timeout {{ $timeout }}s;
  65. proxy_send_timeout {{ $timeout }}s;
  66. proxy_read_timeout {{ $timeout }}s;
  67. }
  68. }
  69. }
  70. {{- end -}}
  71. {{- end -}}