Advertisement
crossRT

Nginx config for OwnCloud 8.2 - subdirectory

Feb 29th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 3.31 KB | None | 0 0
  1. server {
  2.     listen 443 default_server;
  3.     ssl on;
  4.     ssl_certificate /PATH/TO/YOUR/SSL.crt;
  5.     ssl_certificate_key /PATH/TO/YOUR/SSL.key;
  6.  
  7.     server_name domainname.com;
  8.     root /PATH/TO/YOUR/domainname.com;
  9.     index index.php index.html index.htm;
  10.  
  11.     location / {
  12.         try_files $uri $uri/ /index.php?q=$uri&$args;
  13.     }
  14.  
  15.     location ~ \.php$ {
  16.         try_files $uri =404;
  17.         fastcgi_split_path_info ^(.+\.php)(/.+)$;
  18.         fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  19.         fastcgi_index index.php;
  20.         include fastcgi_params;
  21.     }
  22.  
  23.     # deny access to .htaccess files, if Apache's document root concurs with nginx's one
  24.     location ~ /\.ht {
  25.         deny all;
  26.     }
  27.  
  28.     error_page 404 /404.html;
  29.     error_page 500 502 503 504 /50x.html;
  30.     location = /50x.html {
  31.         root /usr/share/nginx/html;
  32.     }
  33.  
  34.     # Add headers to serve security related headers
  35.     # add Strict-Transport-Security to prevent man in the middle attacks
  36.     add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
  37.     add_header X-Content-Type-Options nosniff;
  38.     add_header X-Frame-Options "SAMEORIGIN";
  39.     add_header X-XSS-Protection "1; mode=block";
  40.     add_header X-Robots-Tag none;
  41.  
  42.     location /owncloud {
  43.  
  44.         client_max_body_size 2G; # set max upload size
  45.         fastcgi_buffers 64 4K;
  46.  
  47.         error_page 403 /owncloud/core/templates/403.php;
  48.         error_page 404 /owncloud/core/templates/404.php;
  49.  
  50.         rewrite ^/owncloud/.well-known/carddav /remote.php/carddav/ permanent;
  51.         rewrite ^/owncloud/.well-known/caldav /remote.php/caldav/ permanent;
  52.  
  53.         # The following 2 rules are only needed for the user_webfinger app.
  54.         # Uncomment it if you're planning to use this app.
  55.         #rewrite ^/owncloud/.well-known/host-meta /public.php?service=host-meta last;
  56.         #rewrite ^/owncloud/.well-known/host-meta.json /public.php?service=host-meta-json last;
  57.  
  58.         location = /owncloud/robots.txt {
  59.             allow all;
  60.             log_not_found off;
  61.             access_log off;
  62.         }
  63.  
  64.         location ~ ^/owncloud/(build|tests|config|lib|3rdparty|templates|data)/ {
  65.             deny all;
  66.         }
  67.  
  68.         location ~ ^/owncloud/(?:\.|autotest|occ|issue|indie|db_|console) {
  69.             deny all;
  70.         }
  71.  
  72.         rewrite ^/owncloud/remote/(.*) /remote.php last;
  73.         rewrite ^/owncloud(/core/doc/[^\/]+/)$ $1/index.html;
  74.         try_files $uri $uri/ =404;
  75.  
  76.         location ~ \.php(?:$|/) {
  77.             fastcgi_split_path_info ^(.+\.php)(/.+)$;
  78.             include fastcgi_params;
  79.             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  80.             fastcgi_param PATH_INFO $fastcgi_path_info;
  81.             fastcgi_param HTTPS on;
  82.             fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
  83.             fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  84.             fastcgi_intercept_errors on;
  85.         }
  86.  
  87.         # Adding the cache control header for js and css files
  88.         # Make sure it is BELOW the location ~ \.php(?:$|/) { block
  89.         location ~* \.(?:css|js)$ {
  90.             add_header Cache-Control "public, max-age=7200";
  91.             # Add headers to serve security related headers
  92.             add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
  93.             add_header X-Content-Type-Options nosniff;
  94.             add_header X-Frame-Options "SAMEORIGIN";
  95.             add_header X-XSS-Protection "1; mode=block";
  96.             add_header X-Robots-Tag none;
  97.             # Optional: Don't log access to assets
  98.             access_log off;
  99.         }
  100.  
  101.         # Optional: Don't log access to other assets
  102.         location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {
  103.             access_log off;
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement