ownCloud

Pre-install notes

If you have previously configured nginx, be sure you have an up to date nginx.conf file that contains the line include /home/user/.config/nginx/includes/*.conf;

Setup

  1. Follow the directions in the Userland Nginx article to enable nginx and PHP on your slot. Make a note of the port number your nginx configuration is using, as it will be needed below.

  2. Create the ~/.config/nginx/includes/owncloud.conf file by running touch ~/.config/nginx/includes/owncloud.conf and add the following content to it:

     location ~ ^/owncloud {
         error_page 403 /core/templates/403.php;
         error_page 404 /core/templates/404.php;
    
         location ~ ^/owncloud/(data|config|\.ht|db_structure\.xml|README) {
             deny all;
         }
    
         location ~ ^(.+?\.php)(/.*)?$ {
             try_files $1 =404;
    
             include fastcgi_params;
             fastcgi_param SCRIPT_FILENAME $document_root$1;
             fastcgi_param PATH_INFO $2;
             fastcgi_pass unix:/home/user/.config/php-fpm/socket;
         }
    
         location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
             expires 30d;
             # Optional: Don't log access to assets
             access_log off;
         }
     }
    
  3. Restart nginx by running killall nginx; ~/.config/nginx/start

  4. Enter the root of your nginx server. This is the path under # path you want to share in your ~/.config/nginx/nginx.conf file. By default, this is /home/user/files: cd /home/user/files

  5. Download and extract ownCloud by running curl https://download.owncloud.org/community/owncloud-9.0.2.tar.bz2 | tar xj

  6. Go to http://server.whatbox.ca:15005/owncloud/index.php (or https://server.whatbox.ca:15005/owncloud/index.php if you're using HTTPS) to complete the ownCloud installation. Replace "(Port)" with the proper port from your nginx configuration.

Further support for using ownCloud can be found in ownCloud's official documentation

SSL (optional)

If you are using HTTPS in your main nginx configuration, use this for your ~/.config/nginx/includes/owncloud.conf file:

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

        location ~ ^/owncloud/(data|config|\.ht|db_structure\.xml|README) {
            deny all;
        }

        location ~ ^(.+?\.php)(/.*)?$ {
            try_files $1 =404;

            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$1;
            fastcgi_param PATH_INFO $2;
            fastcgi_param HTTPS on;
            fastcgi_pass unix:/home/user/.config/php-fpm/socket;
        }

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

Restart nginx by running killall nginx; ~/.config/nginx/start

You can then access ownCloud via https://server.whatbox.ca:(Port)/owncloud/index.php to complete the ownCloud installation. Replace "(Port)" with the proper port from your nginx configuration.

Disable nginx authentication for ownCloud (optional)

If you want to create public share links that don't require the enduser to login (much like the shared links on Dropbox), edit your nginx.conf file nano ~/.config/nginx/nginx.conf to disable authentication to your owncloud directory.

To ownCloud, the path that you share, /home/user/files is root. We want server authentication in root, so we will keep authentication alive there. When we (or any shared users) enter ownCloud, we want to arrive at the ownCloud homepage and login with ownCloud credentials. Therefore, we want to disable nginx/server authentication in this directory, /home/user/files/owncloud or, from the perspective of owncloud, /owncloud

Add the following to your nginx.conf under the server { heading. Make sure you don't have any duplicated entries otherwise nginx will still ask you to login.

# file with user:pass info
    location / {
        auth_basic_user_file /home/user/.config/nginx/htpasswd.conf;
        auth_basic "Personal file server";
    }
        
    location /owncloud {
        auth_basic "off";
    }
    

Restart nginx by running killall nginx; ~/.config/nginx/start