Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aquaxp/5198234 to your computer and use it in GitHub Desktop.
Save aquaxp/5198234 to your computer and use it in GitHub Desktop.
# 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 bla-bla;
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 bla-bla;
root /var/www/; # 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;
ssl_certificate /usr/local/nginx/conf/server.crt;
ssl_certificate_key /usr/local/nginx/conf/server.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 ^/owncloud/caldav((/|$).*)$ /owncloud/remote.php/caldav$1 last;
rewrite ^/owncloud/carddav((/|$).*)$ /owncloud/remote.php/carddav$1 last;
rewrite ^/owncloud/webdav((/|$).*)$ /owncloud/remote.php/webdav$1 last;
# Protecting sensitive files from the evil outside world
location ~ ^/owncloud/(data|config|\.ht|db_structure.xml|README) {
deny all;
}
# Configure the root location with proper rewrite rule
location /owncloud/ {
rewrite ^/owncloud/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/owncloud/.well-known/host-meta.json /public.php?service=host-meta-json last;
rewrite ^/owncloud/.well-known/carddav /remote.php/carddav/ redirect;
rewrite ^/owncloud/.well-known/caldav /remote.php/caldav/ redirect;
rewrite ^/owncloud/apps/calendar/caldav.php /remote.php/caldav/ last;
rewrite ^/owncloud/apps/contacts/carddav.php /remote.php/carddav/ last;
rewrite ^/owncloud/apps/([^/]*)/(.*\.(css|php))$ /index.php?app=$1&getfile=$2 last;
rewrite ^(/owncloud/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 127.0.0.1:9000; # 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment