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