Skip to content

Instantly share code, notes, and snippets.

@petarpetrovic
Created March 14, 2013 17:56
Show Gist options
  • Save petarpetrovic/5163565 to your computer and use it in GitHub Desktop.
Save petarpetrovic/5163565 to your computer and use it in GitHub Desktop.
This is the proper config file for nginx and ownCloud version 5. Please note that slight variations might need to be applied in order for your particular instance to work. This one works for me, hence this Gist. Everyone is free to fork it and make proper modifications for different server configurations.
# This is the complete example of nginx configuration file for ownCloud 5
# This config file configures proper rewrite rules for the new release of ownCloud
# Also, this config file configures nginx to listen on both IPv4 and IPv6 addresses
# If you want it to listen to IPv4 address only, use listen 80; instead of listen [::]:80
# First, we configure redirection to HTTPS (substitue owncloud.example.com with the proper address of your OC instance)
server {
listen [::]:80;
server_name owncloud.example.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
# Now comes the main configuration for ownCloud 5
server {
listen [::]:443 ssl; # Make it listen on port 443 for SSL, on both IPv4 and IPv6 interfaces
server_name owncloud.example.com;
root /var/www/owncloud; # Make sure to insert proper path for your ownCloud root directory
index index.php;
# Now we configure SSL certificates. Make sure you enter correct path for your SSL cert files
ssl_certificate /etc/nginx/certs/owncloud.example.com.crt;
ssl_certificate_key /etc/nginx/certs/owncloud.example.com.key;
client_max_body_size 1024M; # This is the first parameter which configures max size of upload, more to come later
fastcgi_buffers 64 4K;
# Configure access & error logs
access_log /var/log/nginx/owncloud.example.com.access_log main;
error_log /var/log/nginx/owncloud.example.com.error_log info;
# Configure proper error pages
error_page 403 = /core/templates/403.php;
error_page 404 = /core/templates/404.php;
# Some rewrite rules, more to come later
rewrite ^/caldav((/|$).*)$ /remote.php/caldav$1 last;
rewrite ^/carddav((/|$).*)$ /remote.php/carddav$1 last;
rewrite ^/webdav((/|$).*)$ /remote.php/webdav$1 last;
# Protecting sensitive files from the evil outside world
location ~ ^/(data|config|\.ht|db_structure.xml|README) {
deny all;
}
# Configure the root location with proper rewrite rule
location / {
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
rewrite ^/apps/calendar/caldav.php /remote.php/caldav/ last;
rewrite ^/apps/contacts/carddav.php /remote.php/carddav/ last;
rewrite ^/apps/([^/]*)/(.*\.(css|php))$ /index.php?app=$1&getfile=$2 last;
rewrite ^(/core/doc[^\/]+/)$ $1/index.html;
index index.php; # This one might be redundant, but it doesn't hurt to leave it here
try_files $uri $uri/ index.php;
}
# Configure PHP-FPM stuff
location ~ ^(<script_name>.+?\.php)(?<path_info>/.*)?$ {
try_files $script_name = 404;
fastcgi_pass unix:/var/run/php5-fpm.sock; # Be sure to check proper socket location for php-fpm, might be different on your system
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
# This one is a little bit tricky, you need to pass all parameters in a single line, separating them with newline (\n)
fastcgi_param PHP_VALUE "upload_max_filesize = 1024M \n post_max_size = 1024M"; # This finishes the max upload size settings
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # On some systems OC will work without this setting, but it doesn't hurt to leave it here
include fastcgi_params;
}
location ~* ^.+.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires 30d;
access_log off;
}
}
@Zer0t3ch
Copy link

I copied the config provided at this doc page which also doesn't have dav_methods in it, and I'm wondering how it works without having that there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment