Advertisement
Guest User

Untitled

a guest
Feb 17th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. upstream php-handler {
  2. server unix:/run/php/php-fpm.sock;
  3. }
  4.  
  5. # Set the `immutable` cache control options only for assets with a cache busting `v` argument
  6. map $arg_v $asset_immutable {
  7. "" "";
  8. default ", immutable";
  9. }
  10.  
  11. server {
  12. listen 80;
  13. listen [::]:80;
  14. server_name nextcloud.domain.com;
  15.  
  16.  
  17. # Prevent nginx HTTP Server Detection
  18. server_tokens off;
  19.  
  20. }
  21. # Path to the root of your installation
  22. root /var/www/html/nextcloud;
  23.  
  24. # set max upload size and increase upload timeout:
  25. client_max_body_size 10G;
  26. fastcgi_buffers 64 4K;
  27. client_body_timeout 3600s;
  28.  
  29. # Enable gzip but do not remove ETag headers
  30. gzip on;
  31. gzip_vary on;
  32. gzip_comp_level 4;
  33. gzip_min_length 256;
  34. gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
  35. 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;
  36.  
  37. # Pagespeed is not supported by Nextcloud, so if your server is built
  38. # with the `ngx_pagespeed` module, uncomment this line to disable it.
  39. #pagespeed off;
  40.  
  41. # The settings allows you to optimize the HTTP2 bandwidth.
  42. # See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
  43. # for tuning hints
  44. client_body_buffer_size 512k;
  45.  
  46. # HTTP response headers borrowed from Nextcloud `.htaccess`
  47. add_header Referrer-Policy "no-referrer" always;
  48. add_header X-Content-Type-Options "nosniff" always;
  49. add_header X-Frame-Options "SAMEORIGIN" always;
  50. add_header X-Permitted-Cross-Domain-Policies "none" always;
  51. add_header X-Robots-Tag "noindex, nofollow" always;
  52. add_header X-XSS-Protection "1; mode=block" always;
  53.  
  54. # Remove X-Powered-By, which is an information leak
  55. fastcgi_hide_header X-Powered-By;
  56.  
  57. # Set .mjs and .wasm MIME types
  58. # Either include it in the default mime.types list
  59. # and include that list explicitly or add the file extension
  60. # only for Nextcloud like below:
  61. include mime.types;
  62. types {
  63. text/javascript js mjs;
  64. application/wasm wasm;
  65. }
  66.  
  67. # Specify how to handle directories -- specifying `/index.php$request_uri`
  68. # here as the fallback means that Nginx always exhibits the desired behaviour
  69. # when a client requests a path that corresponds to a directory that exists
  70. # on the server. In particular, if that directory contains an index.php file,
  71. # that file is correctly served; if it doesn't, then the request is passed to
  72. # the front-end controller. This consistent behaviour means that we don't need
  73. # to specify custom rules for certain paths (e.g. images and other assets,
  74. # `/updater`, `/ocs-provider`), and thus
  75. # `try_files $uri $uri/ /index.php$request_uri`
  76. # always provides the desired behaviour.
  77. index index.php index.html /index.php$request_uri;
  78.  
  79. # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
  80. location = / {
  81. if ( $http_user_agent ~ ^DavClnt ) {
  82. return 302 /remote.php/webdav/$is_args$args;
  83. }
  84. }
  85.  
  86. location = /robots.txt {
  87. allow all;
  88. log_not_found off;
  89. access_log off;
  90. }
  91.  
  92. # Make a regex exception for `/.well-known` so that clients can still
  93. # access it despite the existence of the regex rule
  94. # `location ~ /(\.|autotest|...)` which would otherwise handle requests
  95. # for `/.well-known`.
  96. location ^~ /.well-known {
  97. # The rules in this block are an adaptation of the rules
  98. # in `.htaccess` that concern `/.well-known`.
  99.  
  100. location = /.well-known/carddav { return 301 /remote.php/dav/; }
  101. location = /.well-known/caldav { return 301 /remote.php/dav/; }
  102.  
  103. location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
  104. location /.well-known/pki-validation { try_files $uri $uri/ =404; }
  105.  
  106. # Let Nextcloud's API for `/.well-known` URIs handle all other
  107. # requests by passing them to the front-end controller.
  108. return 301 /index.php$request_uri;
  109. }
  110.  
  111. # Rules borrowed from `.htaccess` to hide certain paths from clients
  112. location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
  113. location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
  114.  
  115. # Ensure this block, which passes PHP files to the PHP process, is above the blocks
  116. # which handle static assets (as seen below). If this block is not declared first,
  117. # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
  118. # to the URI, resulting in a HTTP 500 error response.
  119. location ~ \.php(?:$|/) {
  120. # Required for legacy support
  121. rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
  122.  
  123. fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  124. set $path_info $fastcgi_path_info;
  125.  
  126. try_files $fastcgi_script_name =404;
  127.  
  128. include fastcgi_params;
  129.  
  130. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  131. fastcgi_param PATH_INFO $path_info;
  132. fastcgi_param HTTPS on;
  133.  
  134. fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
  135. fastcgi_param front_controller_active true; # Enable pretty urls
  136. fastcgi_pass php-handler;
  137.  
  138. fastcgi_intercept_errors on;
  139. fastcgi_request_buffering off;
  140.  
  141. fastcgi_read_timeout 3600;
  142. fastcgi_send_timeout 3600;
  143. fastcgi_connect_timeout 3600;
  144.  
  145. fastcgi_max_temp_file_size 0;
  146. }
  147.  
  148. # Serve static files
  149. location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
  150. try_files $uri /index.php$request_uri;
  151. add_header Cache-Control "public, max-age=15778463, $asset_immutable";
  152. expires 6M;
  153. access_log off; # Optional: Don't log access to assets
  154.  
  155. location ~ \.wasm$ {
  156. default_type application/wasm;
  157. }
  158. }
  159.  
  160. location ~ \.woff2?$ {
  161. try_files $uri /index.php$request_uri;
  162. expires 7d; # Cache-Control policy borrowed from `.htaccess`
  163. access_log off; # Optional: Don't log access to assets
  164. }
  165.  
  166. # Rule borrowed from `.htaccess`
  167. location /remote {
  168. return 301 /remote.php$request_uri;
  169. }
  170.  
  171. location / {
  172. # enable for basic auth
  173. #auth_basic "Restricted";
  174. #auth_basic_user_file /config/nginx/.htpasswd;
  175.  
  176. try_files $uri $uri/ /index.php$request_uri;
  177. }
  178.  
  179. # deny access to .htaccess/.htpasswd files
  180. location ~ /\.ht {
  181. deny all;
  182. }
  183. }
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement