7a0dd2f3ff3af43da67177f7d2e7660cb7b8bec7
[lhc/ansible.git] / templates / nginx_nuage_server.j2
1 # Set the `immutable` cache control options only for assets with a cache busting `v` argument
2 map $arg_v $asset_immutable {
3 "" "";
4 default "immutable";
5 }
6 server {
7 listen 80;
8 server_name {{ SITE }}.{{ DOMAIN }}.{{ TLD }};
9 #disable_symlinks if_not_owner;
10
11 # Prevent nginx HTTP Server Detection
12 server_tokens off;
13
14 # Enforce HTTPS
15 return 301 https://$server_name$request_uri;
16
17 access_log /home/sites/log/nginx/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/access.log main buffer=32k;
18 error_log /home/sites/log/nginx/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/error.log warn;
19 }
20 server {
21 listen 443 ssl http2;
22 server_name {{ SITE }}.{{ DOMAIN }}.{{ TLD }};
23
24 # Path to the root of your installation
25 root /home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/nextcloud;
26
27 disable_symlinks if_not_owner;
28 {% if ssl_ready is defined and ssl_ready %}
29 ssl_certificate /etc/letsencrypt/live/{{ SITE }}.{{ DOMAIN }}.{{ TLD }}/fullchain.pem;
30 ssl_certificate_key /etc/letsencrypt/live/{{ SITE }}.{{ DOMAIN }}.{{ TLD }}/privkey.pem;
31 {% endif %}
32 access_log /home/sites/log/nginx/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/access.log main buffer=32k;
33 error_log /home/sites/log/nginx/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/error.log warn;
34
35 # Prevent nginx HTTP Server Detection
36 server_tokens off;
37
38 # HSTS settings
39 # WARNING: Only add the preload option once you read about
40 # the consequences in https://hstspreload.{{ TLD }}/. This option
41 # will add the domain to a hardcoded list that is shipped
42 # in all major browsers and getting removed from this list
43 # could take several months.
44 add_header Strict-Transport-Security "max-age=15768000; includeSubDomains" always;
45
46 # set max upload size and increase upload timeout:
47 client_max_body_size 512M;
48 client_body_timeout 300s;
49 fastcgi_buffers 64 4K;
50
51 # Enable gzip but do not remove ETag headers
52 gzip on;
53 gzip_vary on;
54 gzip_comp_level 4;
55 gzip_min_length 256;
56 gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
57 gzip_types application/atom+xml text/javascript application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm 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;
58
59 # Pagespeed is not supported by Nextcloud, so if your server is built
60 # with the `ngx_pagespeed` module, uncomment this line to disable it.
61 #pagespeed off;
62
63 # The settings allows you to optimize the HTTP2 bandwitdth.
64 # See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
65 # for tunning hints
66 client_body_buffer_size 512k;
67
68 # HTTP response headers borrowed from Nextcloud `.htaccess`
69 add_header Referrer-Policy "no-referrer" always;
70 add_header X-Content-Type-Options "nosniff" always;
71 add_header X-Download-Options "noopen" always;
72 add_header X-Frame-Options "SAMEORIGIN" always;
73 add_header X-Permitted-Cross-Domain-Policies "none" always;
74 add_header X-Robots-Tag "noindex, nofollow" always;
75 add_header X-XSS-Protection "1; mode=block" always;
76
77 # Remove X-Powered-By, which is an information leak
78 fastcgi_hide_header X-Powered-By;
79
80 # Add .mjs as a file extension for javascript
81 # Either include it in the default mime.types list
82 # or include you can include that list explicitly and add the file extension
83 # only for Nextcloud like below:
84 include mime.types;
85 types {
86 text/javascript js mjs;
87 }
88
89 location ~ /common-apps/(.*)$ {
90 alias /home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/common/$1;
91 }
92
93 location ~ /instance-apps/(.*)$ {
94 alias /home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/apps/$1;
95 }
96
97 # Specify how to handle directories -- specifying `/index.php$request_uri`
98 # here as the fallback means that Nginx always exhibits the desired behaviour
99 # when a client requests a path that corresponds to a directory that exists
100 # on the server. In particular, if that directory contains an index.php file,
101 # that file is correctly served; if it doesn't, then the request is passed to
102 # the front-end controller. This consistent behaviour means that we don't need
103 # to specify custom rules for certain paths (e.g. images and other assets,
104 # `/updater`, `/ocs-provider`), and thus
105 # `try_files $uri $uri/ /index.php$request_uri`
106 # always provides the desired behaviour.
107 index index.php index.html /index.php$request_uri;
108
109 # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
110 location = {
111 if ( $http_user_agent ~ ^DavClnt ) {
112 return 302 /remote.php/webdav/$is_args$args;
113 }
114 }
115
116 location = /robots.txt {
117 allow all;
118 log_not_found off;
119 access_log off;
120 }
121
122 # Make a regex exception for `/.well-known` so that clients can still
123 # access it despite the existence of the regex rule
124 # `location ~ /(\.|autotest|...)` which would otherwise handle requests
125 # for `/.well-known`.
126 location ^~ /.well-known {
127 # The rules in this block are an adaptation of the rules
128 # in the Nextcloud `.htaccess` that concern `/.well-known`.
129
130 location = /.well-known/carddav { return 301 /remote.php/dav/; }
131 location = /.well-known/caldav { return 301 /remote.php/dav/; }
132
133 location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
134 location /.well-known/pki-validation { try_files $uri $uri/ =404; }
135
136 # Let Nextcloud's API for `/.well-known` URIs handle all other
137 # requests by passing them to the front-end controller.
138 return 301 /index.php$request_uri;
139 }
140
141 # Rules borrowed from `.htaccess` to hide certain paths from clients
142 location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
143 location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
144
145 # Ensure this block, which passes PHP files to the PHP process, is above the blocks
146 # which handle static assets (as seen below). If this block is not declared first,
147 # then Nginx will encounter an infinite rewriting loop when it prepends
148 # `/index.php` to the URI, resulting in a HTTP 500 error response.
149 location ~ \.php(?:$|/) {
150 # Required for legacy support
151 # commented lines from nextcloud nginx template are already in /etc/nginx/conf.d/fastcgi.conf
152 rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
153
154 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
155 #set $path_info $fastcgi_path_info;
156
157 try_files $fastcgi_script_name =404;
158
159 include /etc/nginx/conf.d/fastcgi.conf;
160 #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
161 #fastcgi_param PATH_INFO $path_info;
162 fastcgi_param HTTPS on;
163
164 fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
165 fastcgi_param front_controller_active true; # Enable pretty urls
166
167 fastcgi_param NEXTCLOUD_CONFIG_DIR /home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/config;
168 fastcgi_pass unix:/run/php{{ php_version}}/fpm/php_{{ SIGLE }}_{{ SITE }};
169
170 #fastcgi_intercept_errors on;
171 fastcgi_request_buffering off;
172
173 #fastcgi_max_temp_file_size 0; #2M in /etc/nginx/conf.d/fastcgi.conf
174 }
175
176 # Serve static files
177 location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
178 try_files $uri /index.php$request_uri;
179 add_header Cache-Control "public, max-age=15778463, $asset_immutable";
180 access_log off; # Optional: Don't log access to assets
181
182 location ~ \.wasm$ {
183 default_type application/wasm;
184 }
185 }
186
187 location ~ \.woff2?$ {
188 try_files $uri /index.php$request_uri;
189 expires 7d; # Cache-Control policy borrowed from `.htaccess`
190 access_log off; # Optional: Don't log access to assets
191 }
192
193 # Rule borrowed from `.htaccess`
194 location /remote {
195 return 301 /remote.php$request_uri;
196 }
197
198 location / {
199 try_files $uri $uri/ /index.php$request_uri;
200 }
201 }