This is an old revision of the document!
This article describes how to setup a Nextcloud server on your NB2800 router.
Nextcloud is a free and open source cloud hosting software. It lets you easily provide files for and share them with others, and lets you customize your cloud with a lot of tools and additional apps.
All basic preparations made are described in this article: How to set up a NB2800 File Server
If you need instructions on how to set up a LXC Container on NB2800 Routers, you can refer to this page: http://wiki.netmodule.com/app-notes/virtualisation.
Before Nextcloud can be installed, some other programs need to be installed and set up. In the first step, enter
apt-get install nginx mariadb-client mariadb-server php7.0-common php7.0-fpm php7.0-cli php7.0-json php7.0-mysql php7.0-curl php7.0-intl php7.0-mcrypt php-pear php7.0-gd php7.0-zip php7.0-xml php7.0-mbstring php7.0-apcu
Now, the Nextcloud folder is created and given to the correct user:
mkdir -p /var/www/nextcloud chown -R www-data:www-data /var/www
For setting up PHP, several values in three files have to be edited. First, go to /etc/php/7.0/fpm/pool.d/www.conf and edit the following values (Note: all values described here have to be edited, decommented or added):
user = www-data group = www-data listen = /run/php/php7.0-fpm.sock env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
Next, go to /etc/php/7.0/fpm/php.ini and edit these values:
cgi.fix_pathinfo = 0 opcache.enable = 1 opcache.enable_cli = 1 opcache.memory_consumption = 128 opcache.interned_strings_buffer = 8 opcache.max_accelerated_files = 10000 opcache.revalidate_freq = 1 opcache.save_comments = 1
The last file for configuring PHP is /etc/php/7.0/cli/php.ini:
cgi.fix_pathinfo = 0
Now enter
service php7.0-fpm restart
to restart PHP.
First, you have to finish the MariDB installation:
mysql_secure_installation
Here you have to enter your root password. All other questions can be answered with (Y)es.
Before going on, you need to restart MariaDB:
service mysql restart
Now you have to create a new MariaDB user which is only needed for Nextcloud access. To enter the MariaDB editing shell, enter
mysql -u root -p
First, you have to create a new database for Nextcloud. Here this database is called “nextcloud_db”, but you can name it however you want to:
create database nextcloud_db;
Now create a new MariaDB-user with a password which can access the “nextcloud_db”:
create user 'user'@localhost identified by 'password';
Note that you have to enter your own credentials for 'user' and 'password'.
Now all necessary right have to be granted to this new user:
grant all privileges on nextcloud_db.* to 'user'@localhost; flush privileges;
Now that everything is set up correctly, you can leave the MariaDB shell:
exit;
Now three lines have to be added to some configuration files:
echo "log-bin = /var/log/mysql/mariadb-bin" >> /etc/mysql/my.cnf echo "log-bin-index = /var/log/mysql/mariadb-bin.index" >> /etc/mysql/my.cnf echo "binlog_format = mixed" >> /etc/mysql/my.cnf
Now restart MariaDB again:
service mysql restart
First, go to /etc/nginx/nginx.conf and edit the following three lines:
überprüfen ob user = www-data überprüfen ob worker_process = auto in html-Block: server_tokens off
In the next step, the Nginx default page needs to be backuped and stored:
mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.backup
Now, a new default page needs to be created:
nano /etc/nginx/sites-available/default
This new file has to be filled with this code (All passages that need to be edited are marked in the code):
upstream php-handler { server unix:/run/php/php7.0-fpm.sock; } server { listen 80; server_name mediacontainer.local; //* edit to own domain name *// # enforce https return 301 https://$server_name$request_uri; } server { listen 443 ssl http2; server_name mediacontainer.local; ssl_certificate /home/NCUser/CA/cacert.pem; //* edit to own files and directorys *// ssl_certificate_key /home/NCUser/CA/private/cakey.pem; //* edit to own files and directorys *// # Add headers to serve security related headers # Before enabling Strict-Transport-Security headers please read into this # topic first. add_header Strict-Transport-Security "max-age=63072000; includeSubdomains" always; # includeSubDomains; preload;"; # # WARNING: Only add the preload option once you read about # the consequences in https://hstspreload.org/. This option # will add the domain to a hardcoded list that is shipped # in all major browsers and getting removed from this list # could take several months. add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; # Path to the root of your installation root /var/www/nextcloud/; //* edit to own directory *// location = /robots.txt { allow all; log_not_found off; access_log off; } # The following 2 rules are only needed for the user_webfinger app. # Uncomment it if you're planning to use this app. #rewrite ^/.well-known/host-meta /public.php?service=host-meta last; #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json # last; location = /.well-known/carddav { return 301 $scheme://$host/remote.php/dav; } location = /.well-known/caldav { return 301 $scheme://$host/remote.php/dav; } # set max upload size client_max_body_size 512M; fastcgi_buffers 64 4K; # Enable gzip but do not remove ETag headers gzip on; gzip_vary on; gzip_comp_level 4; gzip_min_length 256; gzip_proxied expired no-cache no-store private no_last_modified no_etag auth; gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; # Uncomment if your server is build with the ngx_pagespeed module # This module is currently not supported. #pagespeed off; location / { rewrite ^ /index.php$uri; } location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { deny all; } location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { deny all; } location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.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; #Avoid sending the security headers twice fastcgi_param modHeadersAvailable true; fastcgi_param front_controller_active true; fastcgi_pass php-handler; fastcgi_intercept_errors on; fastcgi_request_buffering off; } location ~ ^/(?:updater|ocs-provider)(?:$|/) { try_files $uri/ =404; index index.php; } # Adding the cache control header for js and css files # Make sure it is BELOW the PHP block location ~ \.(?:css|js|woff|svg|gif)$ { try_files $uri /index.php$uri$is_args$args; add_header Cache-Control "public, max-age=15778463"; # Add headers to serve security related headers (It is intended to # have those duplicated to the ones above) # Before enabling Strict-Transport-Security headers please read into # this topic first. # add_header Strict-Transport-Security "max-age=15768000; # includeSubDomains; preload;"; # # WARNING: Only add the preload option once you read about # the consequences in https://hstspreload.org/. This option # will add the domain to a hardcoded list that is shipped # in all major browsers and getting removed from this list # could take several months. add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; # Optional: Don't log access to assets access_log off; } location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ { try_files $uri /index.php$uri$is_args$args; # Optional: Don't log access to other assets access_log off; } }