]> git.somenet.org - root/pub/somesible.git/blob - roles/service/nextcloud/vars/default/vars_nginx_vhost_custom.yml
roles/service/mattermost/defaults
[root/pub/somesible.git] / roles / service / nextcloud / vars / default / vars_nginx_vhost_custom.yml
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>
6 #
7 ---
8 vhost_custom_pre_server: |-
9
10 vhost_custom: |-
11     # Enable gzip but do not remove ETag headers
12     #gzip on;
13     #gzip_vary on;
14     #gzip_comp_level 4;
15     #gzip_min_length 256;
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;
18
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.
21     #pagespeed off;
22
23     # The settings allows you to optimize the HTTP2 bandwitdth.
24     # See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
25     # for tunning hints
26     client_body_buffer_size 512k;
27
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-Download-Options                   "noopen"        always;
32     add_header X-Frame-Options                      "SAMEORIGIN"    always;
33     add_header X-Permitted-Cross-Domain-Policies    "none"          always;
34     add_header X-Robots-Tag                         "none"          always;
35     add_header X-XSS-Protection                     "1; mode=block" always;
36
37     # Remove X-Powered-By, which is an information leak
38     fastcgi_hide_header X-Powered-By;
39
40     # Path to the root of your installation
41     root /var/www/{{vhost_name}};
42
43     # Specify how to handle directories -- specifying `/index.php$request_uri`
44     # here as the fallback means that Nginx always exhibits the desired behaviour
45     # when a client requests a path that corresponds to a directory that exists
46     # on the server. In particular, if that directory contains an index.php file,
47     # that file is correctly served; if it doesn't, then the request is passed to
48     # the front-end controller. This consistent behaviour means that we don't need
49     # to specify custom rules for certain paths (e.g. images and other assets,
50     # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
51     # `try_files $uri $uri/ /index.php$request_uri`
52     # always provides the desired behaviour.
53     index index.php index.html /index.php$request_uri;
54
55     # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
56     location = / {
57         if ( $http_user_agent ~ ^DavClnt ) {
58             return 302 /remote.php/webdav/$is_args$args;
59         }
60     }
61
62     # Make a regex exception for `/.well-known` so that clients can still
63     # access it despite the existence of the regex rule
64     # `location ~ /(\.|autotest|...)` which would otherwise handle requests
65     # for `/.well-known`.
66     location ^~ /.well-known {
67         # The rules in this block are an adaptation of the rules
68         # in `.htaccess` that concern `/.well-known`.
69
70         location = /.well-known/carddav { return 301 /remote.php/dav/; }
71         location = /.well-known/caldav  { return 301 /remote.php/dav/; }
72         location /.well-known/pki-validation    { try_files $uri $uri/ =404; }
73
74         # Let Nextcloud's API for `/.well-known` URIs handle all other
75         # requests by passing them to the front-end controller.
76         return 301 /index.php$request_uri;
77     }
78
79     # Rules borrowed from `.htaccess` to hide certain paths from clients
80     location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
81     location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console)                { return 404; }
82
83     # Ensure this block, which passes PHP files to the PHP process, is above the blocks
84     # which handle static assets (as seen below). If this block is not declared first,
85     # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
86     # to the URI, resulting in a HTTP 500 error response.
87     location ~ \.php(?:$|/) {
88         # Required for legacy support
89         rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
90
91         fastcgi_split_path_info ^(.+?\.php)(/.*)$;
92         set $path_info $fastcgi_path_info;
93
94         try_files $fastcgi_script_name =404;
95
96         include fastcgi_params;
97         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
98         fastcgi_param PATH_INFO $path_info;
99         fastcgi_param HTTPS on;
100
101         fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice
102         fastcgi_param front_controller_active true;     # Enable pretty urls
103         fastcgi_pass unix:/var/run/php/php-fpm.sock;
104
105         fastcgi_intercept_errors on;
106         fastcgi_request_buffering off;
107
108         fastcgi_max_temp_file_size 0;
109     }
110
111     location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
112         try_files $uri /index.php$request_uri;
113         add_header Cache-Control "public, max-age=15778463";
114
115         location ~ \.wasm$ {
116             default_type application/wasm;
117         }
118     }
119
120     location ~ \.woff2?$ {
121         try_files $uri /index.php$request_uri;
122         expires 7d;         # Cache-Control policy borrowed from `.htaccess`
123     }
124
125     # Rule borrowed from `.htaccess`
126     location /remote {
127         return 301 /remote.php$request_uri;
128     }
129
130     location / {
131         try_files $uri $uri/ /index.php$request_uri;
132     }