Guest User

nginx

a guest
Dec 25th, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.43 KB | None | 0 0
  1. worker_processes auto;
  2.  
  3. error_log /var/log/nginx/error.log warn;
  4. pid /var/run/nginx.pid;
  5.  
  6.  
  7. events {
  8. worker_connections 1024;
  9. }
  10.  
  11.  
  12. http {
  13. include /etc/nginx/mime.types;
  14. default_type application/octet-stream;
  15.  
  16. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  17. '$status $body_bytes_sent "$http_referer" '
  18. '"$http_user_agent" "$http_x_forwarded_for"';
  19.  
  20. access_log /var/log/nginx/access.log main;
  21.  
  22. sendfile on;
  23. #tcp_nopush on;
  24.  
  25. keepalive_timeout 65;
  26.  
  27. #gzip on;
  28.  
  29. upstream php-handler {
  30. server app:9000;
  31. }
  32.  
  33. server {
  34. listen 80;
  35. listen [::]:80;
  36.  
  37. # HSTS settings
  38. # WARNING: Only add the preload option once you read about
  39. # the consequences in https://hstspreload.org/. This option
  40. # will add the domain to a hardcoded list that is shipped
  41. # in all major browsers and getting removed from this list
  42. # could take several months.
  43. #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
  44.  
  45. # set max upload size
  46. client_max_body_size 512M;
  47. fastcgi_buffers 64 4K;
  48.  
  49. # Enable gzip but do not remove ETag headers
  50. gzip on;
  51. gzip_vary on;
  52. gzip_comp_level 4;
  53. gzip_min_length 256;
  54. gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
  55. 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/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;
  56.  
  57. # Pagespeed is not supported by Nextcloud, so if your server is built
  58. # with the `ngx_pagespeed` module, uncomment this line to disable it.
  59. #pagespeed off;
  60.  
  61. # HTTP response headers borrowed from Nextcloud `.htaccess`
  62. add_header Referrer-Policy "no-referrer" always;
  63. add_header X-Content-Type-Options "nosniff" always;
  64. add_header X-Download-Options "noopen" always;
  65. add_header X-Frame-Options "SAMEORIGIN" always;
  66. add_header X-Permitted-Cross-Domain-Policies "none" always;
  67. add_header X-Robots-Tag "none" always;
  68. add_header X-XSS-Protection "1; mode=block" always;
  69.  
  70. # Remove X-Powered-By, which is an information leak
  71. fastcgi_hide_header X-Powered-By;
  72.  
  73. # Path to the root of your installation
  74. root /var/www/html;
  75.  
  76. # Specify how to handle directories -- specifying `/index.php$request_uri`
  77. # here as the fallback means that Nginx always exhibits the desired behaviour
  78. # when a client requests a path that corresponds to a directory that exists
  79. # on the server. In particular, if that directory contains an index.php file,
  80. # that file is correctly served; if it doesn't, then the request is passed to
  81. # the front-end controller. This consistent behaviour means that we don't need
  82. # to specify custom rules for certain paths (e.g. images and other assets,
  83. # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
  84. # `try_files $uri $uri/ /index.php$request_uri`
  85. # always provides the desired behaviour.
  86. index index.php index.html /index.php$request_uri;
  87.  
  88. # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
  89. location = / {
  90. if ( $http_user_agent ~ ^DavClnt ) {
  91. return 302 /remote.php/webdav/$is_args$args;
  92. }
  93. }
  94.  
  95. location = /robots.txt {
  96. allow all;
  97. log_not_found off;
  98. access_log off;
  99. }
  100.  
  101. # Make a regex exception for `/.well-known` so that clients can still
  102. # access it despite the existence of the regex rule
  103. # `location ~ /(\.|autotest|...)` which would otherwise handle requests
  104. # for `/.well-known`.
  105. location ^~ /.well-known {
  106. # The rules in this block are an adaptation of the rules
  107. # in `.htaccess` that concern `/.well-known`.
  108. allow all;
  109.  
  110. location = /.well-known/carddav { return 301 /remote.php/dav/; }
  111. location = /.well-known/caldav { return 301 /remote.php/dav/; }
  112.  
  113. location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
  114. location /.well-known/pki-validation { try_files $uri $uri/ =404; }
  115.  
  116. # Let Nextcloud's API for `/.well-known` URIs handle all other
  117. # requests by passing them to the front-end controller.
  118. return 301 /index.php$request_uri;
  119.  
  120. }
  121.  
  122. location ^~ '/.well-known/acme-challenge' {
  123. allow all;
  124. }
  125.  
  126. # Rules borrowed from `.htaccess` to hide certain paths from clients
  127. location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
  128. location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
  129.  
  130. # Ensure this block, which passes PHP files to the PHP process, is above the blocks
  131. # which handle static assets (as seen below). If this block is not declared first,
  132. # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
  133. # to the URI, resulting in a HTTP 500 error response.
  134. location ~ \.php(?:$|/) {
  135. # Required for legacy support
  136. rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
  137.  
  138. fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  139. set $path_info $fastcgi_path_info;
  140.  
  141. try_files $fastcgi_script_name =404;
  142.  
  143. include fastcgi_params;
  144. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  145. fastcgi_param PATH_INFO $path_info;
  146. #fastcgi_param HTTPS on;
  147.  
  148. fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
  149. fastcgi_param front_controller_active true; # Enable pretty urls
  150. fastcgi_pass php-handler;
  151.  
  152. fastcgi_intercept_errors on;
  153. fastcgi_request_buffering off;
  154. }
  155.  
  156. location ~ \.(?:css|js|svg|gif)$ {
  157. try_files $uri /index.php$request_uri;
  158. expires 6M; # Cache-Control policy borrowed from `.htaccess`
  159. access_log off; # Optional: Don't log access to assets
  160. }
  161.  
  162. location ~ \.woff2?$ {
  163. try_files $uri /index.php$request_uri;
  164. expires 7d; # Cache-Control policy borrowed from `.htaccess`
  165. access_log off; # Optional: Don't log access to assets
  166. }
  167.  
  168. # Rule borrowed from `.htaccess`
  169. location /remote {
  170. return 301 /remote.php$request_uri;
  171. }
  172.  
  173. location / {
  174. try_files $uri $uri/ /index.php$request_uri;
  175. }
  176. }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment