|
| 1 | +upstream php-handler { |
| 2 | + server 127.0.0.1:9000; |
| 3 | +} |
| 4 | + |
| 5 | +server { |
| 6 | + listen {{ .Values.nginx.containerPort }}; |
| 7 | + |
| 8 | + # HSTS settings |
| 9 | + # WARNING: Only add the preload option once you read about |
| 10 | + # the consequences in https://hstspreload.org/. This option |
| 11 | + # will add the domain to a hardcoded list that is shipped |
| 12 | + # in all major browsers and getting removed from this list |
| 13 | + # could take several months. |
| 14 | + #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always; |
| 15 | + |
| 16 | + # set max upload size |
| 17 | + client_max_body_size 10G; |
| 18 | + fastcgi_buffers 64 4K; |
| 19 | + |
| 20 | + # Enable gzip but do not remove ETag headers |
| 21 | + gzip on; |
| 22 | + gzip_vary on; |
| 23 | + gzip_comp_level 4; |
| 24 | + gzip_min_length 256; |
| 25 | + gzip_proxied expired no-cache no-store private no_last_modified no_etag auth; |
| 26 | + gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; |
| 27 | + |
| 28 | + # Pagespeed is not supported by Nextcloud, so if your server is built |
| 29 | + # with the `ngx_pagespeed` module, uncomment this line to disable it. |
| 30 | + #pagespeed off; |
| 31 | + |
| 32 | + # HTTP response headers borrowed from Nextcloud `.htaccess` |
| 33 | + add_header Referrer-Policy "no-referrer" always; |
| 34 | + add_header X-Content-Type-Options "nosniff" always; |
| 35 | + add_header X-Download-Options "noopen" always; |
| 36 | + add_header X-Frame-Options "SAMEORIGIN" always; |
| 37 | + add_header X-Permitted-Cross-Domain-Policies "none" always; |
| 38 | + add_header X-Robots-Tag "noindex, nofollow" always; |
| 39 | + add_header X-XSS-Protection "1; mode=block" always; |
| 40 | + |
| 41 | + # Remove X-Powered-By, which is an information leak |
| 42 | + fastcgi_hide_header X-Powered-By; |
| 43 | + |
| 44 | + # Add .mjs as a file extension for javascript |
| 45 | + # Either include it in the default mime.types list |
| 46 | + # or include you can include that list explicitly and add the file extension |
| 47 | + # only for Nextcloud like below: |
| 48 | + include mime.types; |
| 49 | + types { |
| 50 | + text/javascript js mjs; |
| 51 | + } |
| 52 | + |
| 53 | + # Path to the root of your installation |
| 54 | + root /var/www/html; |
| 55 | + |
| 56 | + # Specify how to handle directories -- specifying `/index.php$request_uri` |
| 57 | + # here as the fallback means that Nginx always exhibits the desired behaviour |
| 58 | + # when a client requests a path that corresponds to a directory that exists |
| 59 | + # on the server. In particular, if that directory contains an index.php file, |
| 60 | + # that file is correctly served; if it doesn't, then the request is passed to |
| 61 | + # the front-end controller. This consistent behaviour means that we don't need |
| 62 | + # to specify custom rules for certain paths (e.g. images and other assets, |
| 63 | + # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus |
| 64 | + # `try_files $uri $uri/ /index.php$request_uri` |
| 65 | + # always provides the desired behaviour. |
| 66 | + index index.php index.html /index.php$request_uri; |
| 67 | + |
| 68 | + # Rule borrowed from `.htaccess` to handle Microsoft DAV clients |
| 69 | + location = / { |
| 70 | + if ( $http_user_agent ~ ^DavClnt ) { |
| 71 | + return 302 /remote.php/webdav/$is_args$args; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + location = /robots.txt { |
| 76 | + allow all; |
| 77 | + log_not_found off; |
| 78 | + access_log off; |
| 79 | + } |
| 80 | + |
| 81 | + # Make a regex exception for `/.well-known` so that clients can still |
| 82 | + # access it despite the existence of the regex rule |
| 83 | + # `location ~ /(\.|autotest|...)` which would otherwise handle requests |
| 84 | + # for `/.well-known`. |
| 85 | + location ^~ /.well-known { |
| 86 | + # The following 6 rules are borrowed from `.htaccess` |
| 87 | +
|
| 88 | + location = /.well-known/carddav { return 301 /remote.php/dav/; } |
| 89 | + location = /.well-known/caldav { return 301 /remote.php/dav/; } |
| 90 | + # Anything else is dynamically handled by Nextcloud |
| 91 | + location ^~ /.well-known { return 301 /index.php$uri; } |
| 92 | + |
| 93 | + try_files $uri $uri/ =404; |
| 94 | + } |
| 95 | + |
| 96 | + # Rules borrowed from `.htaccess` to hide certain paths from clients |
| 97 | + location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; } |
| 98 | + location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; } |
| 99 | + |
| 100 | + # Ensure this block, which passes PHP files to the PHP process, is above the blocks |
| 101 | + # which handle static assets (as seen below). If this block is not declared first, |
| 102 | + # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php` |
| 103 | + # to the URI, resulting in a HTTP 500 error response. |
| 104 | + location ~ \.php(?:$|/) { |
| 105 | + # Required for legacy support |
| 106 | + rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode(_arm64)?\/proxy) /index.php$request_uri; |
| 107 | +
|
| 108 | + fastcgi_split_path_info ^(.+?\.php)(/.*)$; |
| 109 | + set $path_info $fastcgi_path_info; |
| 110 | +
|
| 111 | + try_files $fastcgi_script_name =404; |
| 112 | +
|
| 113 | + include fastcgi_params; |
| 114 | + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
| 115 | + fastcgi_param PATH_INFO $path_info; |
| 116 | + #fastcgi_param HTTPS on; |
| 117 | +
|
| 118 | + fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice |
| 119 | + fastcgi_param front_controller_active true; # Enable pretty urls |
| 120 | + fastcgi_pass php-handler; |
| 121 | +
|
| 122 | + fastcgi_intercept_errors on; |
| 123 | + fastcgi_request_buffering off; |
| 124 | + } |
| 125 | + |
| 126 | + location ~ \.(?:css|js|svg|gif)$ { |
| 127 | + try_files $uri /index.php$request_uri; |
| 128 | + expires 6M; # Cache-Control policy borrowed from `.htaccess` |
| 129 | + access_log off; # Optional: Don't log access to assets |
| 130 | + } |
| 131 | +
|
| 132 | + location ~ \.woff2?$ { |
| 133 | + try_files $uri /index.php$request_uri; |
| 134 | + expires 7d; # Cache-Control policy borrowed from `.htaccess` |
| 135 | + access_log off; # Optional: Don't log access to assets |
| 136 | + } |
| 137 | + |
| 138 | + location / { |
| 139 | + try_files $uri $uri/ /index.php$request_uri; |
| 140 | + } |
| 141 | +} |
0 commit comments