1 #####################################
2 ### someone"s ansible provisioner ###
3 #####################################
4 # Part of: https://git.somenet.org/root/pub/somesible.git
5 # 2017-2024 by someone <someone@somenet.org>
8 vhost_custom_pre_server: |-
11 # Enable gzip but do not remove ETag headers
16 #gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
17 #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/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;
19 # Pagespeed is not supported by Nextcloud, so if your server is built
20 # with the `ngx_pagespeed` module, uncomment this line to disable it.
23 # The settings allows you to optimize the HTTP2 bandwitdth.
24 # See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
26 client_body_buffer_size 512k;
28 # HTTP response headers borrowed from Nextcloud `.htaccess`
29 add_header Referrer-Policy "no-referrer" always;
30 add_header X-Content-Type-Options "nosniff" always;
31 add_header X-Frame-Options "SAMEORIGIN" always;
32 add_header X-Permitted-Cross-Domain-Policies "none" always;
33 add_header X-Robots-Tag "noindex, nofollow" always;
34 add_header X-XSS-Protection "1; mode=block" always;
36 # Remove X-Powered-By, which is an information leak
37 fastcgi_hide_header X-Powered-By;
42 application/wasm wasm;
45 # Path to the root of your installation
46 root /var/www/{{vhost_name}};
48 # Specify how to handle directories -- specifying `/index.php$request_uri`
49 # here as the fallback means that Nginx always exhibits the desired behaviour
50 # when a client requests a path that corresponds to a directory that exists
51 # on the server. In particular, if that directory contains an index.php file,
52 # that file is correctly served; if it doesn't, then the request is passed to
53 # the front-end controller. This consistent behaviour means that we don't need
54 # to specify custom rules for certain paths (e.g. images and other assets,
55 # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
56 # `try_files $uri $uri/ /index.php$request_uri`
57 # always provides the desired behaviour.
58 index index.php index.html /index.php$request_uri;
60 # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
62 if ( $http_user_agent ~ ^DavClnt ) {
63 return 302 /remote.php/webdav/$is_args$args;
67 # Make a regex exception for `/.well-known` so that clients can still
68 # access it despite the existence of the regex rule
69 # `location ~ /(\.|autotest|...)` which would otherwise handle requests
71 location ^~ /.well-known {
72 # The rules in this block are an adaptation of the rules
73 # in `.htaccess` that concern `/.well-known`.
75 location = /.well-known/carddav { return 301 /remote.php/dav/; }
76 location = /.well-known/caldav { return 301 /remote.php/dav/; }
78 location /.well-known/pki-validation { try_files $uri $uri/ =404; }
80 # Let Nextcloud's API for `/.well-known` URIs handle all other
81 # requests by passing them to the front-end controller.
82 return 301 /index.php$request_uri;
85 # Rules borrowed from `.htaccess` to hide certain paths from clients
86 location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
87 location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
89 # Ensure this block, which passes PHP files to the PHP process, is above the blocks
90 # which handle static assets (as seen below). If this block is not declared first,
91 # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
92 # to the URI, resulting in a HTTP 500 error response.
93 location ~ \.php(?:$|/) {
94 # Required for legacy support
95 rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode(_arm64)?\/proxy) /index.php$request_uri;
97 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
98 set $path_info $fastcgi_path_info;
100 try_files $fastcgi_script_name =404;
102 include fastcgi_params;
103 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
104 fastcgi_param PATH_INFO $path_info;
105 fastcgi_param HTTPS on;
107 fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
108 fastcgi_param front_controller_active true; # Enable pretty urls
109 fastcgi_pass unix:/var/run/php/php-fpm.sock;
111 fastcgi_intercept_errors on;
112 fastcgi_request_buffering off;
114 fastcgi_max_temp_file_size 0;
118 location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
119 try_files $uri /index.php$request_uri;
120 # HTTP response headers borrowed from Nextcloud `.htaccess`
121 add_header Cache-Control "public, max-age=15778463";
122 add_header Referrer-Policy "no-referrer" always;
123 add_header X-Content-Type-Options "nosniff" always;
124 add_header X-Frame-Options "SAMEORIGIN" always;
125 add_header X-Permitted-Cross-Domain-Policies "none" always;
126 add_header X-Robots-Tag "noindex, nofollow" always;
127 add_header X-XSS-Protection "1; mode=block" always;
130 location ~ \.woff2?$ {
131 try_files $uri /index.php$request_uri;
132 expires 7d; # Cache-Control policy borrowed from `.htaccess`
135 # Rule borrowed from `.htaccess`
137 return 301 /remote.php$request_uri;
141 try_files $uri $uri/ /index.php$request_uri;