During the last holidays I found the time to buy a Raspberry Pi (B+), at last. My main use case will be an ownCloud server within my home’s LAN. I will also access to it from outside the LAN thanks to the DDNS service provided by (e.g.) no-ip.

Owncloud by default depends on the apache webserver, but it works fine with the lighter nginx server, which is recommended to not stress too much the Pi. You have to manually install owncloud, though. I followed this guide and it worked fine (even installing php5-curl worked for me, required for the External Storage application). Note that you can actually skip the steps 1c, 1d and the last part of step 9. Owncloud works just fine without messing with GPU memory, CPU overclock and swap.

That guide though, as well as the official owncloud guide, assumes that the owncloud installation will be accessible from the root of your server, e.g. from example.com. What if you want it to be like example.com/owncloud ? Actually the solution it’s quite easy, even though it’s not so easy to find it on the web. So, the following is a working nginx configuration file for the discussed setup. Basically I’ve just rewrited the location blocks and the rewrite directives from the configuration file suggested by the linked guides.

upstream php-handler {
    #server unix:/var/run/php5-fpm.sock;

server {
    listen 80;
    server_name example.com;
    return 301 https://$server_name$request_uri;

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/ssl/nginx/cert.pem;
    ssl_certificate_key /etc/ssl/nginx/cert.key;

    root /var/www;

    client_max_body_size 1000M; # set max upload size
    fastcgi_buffers 64 4K;

    # ownCloud blacklist
    location ~ ^/owncloud/(?:\.htaccess|data|config|db_structure\.xml|README) {
        deny all;
        error_page 403 = /owncloud/core/templates/403.php;

    location / {
        index index.html;

    location /owncloud/ {
        error_page 403 = /owncloud/core/templates/403.php;
        error_page 404 = /owncloud/core/templates/404.php;

        rewrite ^/owncloud/caldav(.*)$ /remote.php/caldav$1 redirect;
        rewrite ^/owncloud/carddav(.*)$ /remote.php/carddav$1 redirect;
        rewrite ^/owncloud/webdav(.*)$ /remote.php/webdav$1 redirect;

        rewrite ^(/owncloud/core/doc[^\/]+/)$ $1/index.html;

        # The following rules are only needed with webfinger
        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;

        try_files $uri $uri/ index.php;

    location ~ \.php(?:$|/) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_pass php-handler;

    # Optional: set long EXPIRES header on static assets
    location ~* ^/owncloud(/.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf))$ {
        expires 30d;
        access_log off;  # Optional: Don't log access to assets

On Raspbian/Debian this configuration file is /etc/nginx/sites-available/default, but on different systems it may be located somewhere else. Don’t forget to reload (or restart) nginx after you edit the configuration file.