之前用docker安装了seafile,发现docker的可玩性太少,自己尝试手动安装seafile,发现问题很多,没有成功。从而改为安装nextcloud。网上说Nextcloud是owncloud的分支。确实如此,在它的客户端配置中,还能见到owncloud的字样。下面介绍如何手动安装nextcloud。主要参考的文档是:https://www.wenjinyu.me/zh/install-nextcloud-to-build-a-proprietary-personal-netdisk/
安装主要分为三步:
1. 安装数据库
2. 安装Nginx,并且安装php支持
3.安装nextcloud
一、安装数据库
安装数据库,可以参考:https://computingforgeeks.com/how-to-install-seafile-server-on-ubuntu-linux/
sudo apt update
sudo apt install mariadb-server
下面初始化mariadb-server,刚刚安装的数据库,root的密码是空,直接回车。然后问要不要设置root密码。设置完密码,其他默认回车。
sudo mysql_secure_installation
建一个nextcloud-db的库。新建nextcloud的用户,并将nextcloud-db库赋予nextcloud用户。
$ mysql -u root -p
CREATE DATABASE nextclouddb;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY '你的密码';
GRANT ALL ON nextclouddb.* TO 'nextcloud'@'localhost';
QUIT;
安装一些依赖,以免出现错误
sudo apt update
sudo apt install python3 python3-{pip,pil,ldap,urllib3,setuptools,mysqldb,memcache,requests}
sudo apt install libpython3.8 ffmpeg
二、 安装Nginx,并且安装php支持
安装nginx
sudo apt update
sudo apt install nginx
安装PHP-FPM
sudo apt update
sudo apt install php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
安装完成后,通过 ls /run/php/命令查看安装的PHP-FPM情况:
$ ls /run/php/
php-fpm.sock php7.4-fpm.pid php7.4-fpm.sock
查看是否已经运行:
$ systemctl status php7.4-fpm.service
三、安装nextcloud
在官网看看最新的版本是哪个,然后下载。官网:https://download.nextcloud.com/server/releases/
先安装zip(这里不作介绍),然后下载nextcloud并解压,改归属权限
cd /var/www/
wget https://download.nextcloud.com/server/releases/nextcloud-20.0.5.zip
unzip nextcloud-*.zip
chown -R www-data:www-data /var/www/nextcloud
配置nginx:
可以通过nginx -t命令,看看nginx.conf的文件在哪个目录。一般是在/etc/nginx/目录下,编辑nginx.conf配置文档。
vim /etc/nginx/nginx.conf
修改配置如下:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}然后在/etc/nginx/conf.d/目录下(如果没有这个目录,就创建一个),创建一个nextcloud.conf的文件,并vim编辑内容如下
详细可以参考官网配置:https://docs.nextcloud.com/server/20/admin_manual/installation/nginx.html
(将你的网站域名替换里面的www.example.com)
upstream php-handler {
server unix:/run/php/php-fpm.sock;
}
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
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;
add_header Referrer-Policy "no-referrer";
add_header X-Frame-Options SAMEORIGIN;
add_header Cache-Control "public, max-age=15778463";
root /var/www/nextcloud/;
error_log /var/log/nextcloud-error.log;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
client_max_body_size 512M;
fastcgi_buffers 64 4K;
proxy_buffering off;
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;
location / {
rewrite ^ /index.php$request_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;
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;
}
location ~ \.(?:css|js|woff|svg|gif)$ {
try_files $uri /index.php$request_uri;
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
access_log off;
}
}
server
{
listen 80;
server_name www.example.com;
return 301 https://$server_name$request_uri;
}nginx -t命令检查配置是否正确,然后重启nginx
nginx -t
nginx -s reload
配置nextcloud:
在浏览器中打开你的网站,就会出现nextcloud的配置页面。(确保nginx、mysql、php7.4-fpm都启动了。通过下面三条命令查看)
systemctl status nginx
systemctl status mysql
systemctl status php7.4-fpm
正常浏览器出现下面图像
创建nextcloud管理员以及密码。输出之前已经在数据库创建的数据库用户nextcloud以及密码,和数据库nextcloud-db。点击完成。就完成了nextcloud的安装。
关于错误:
您的网络服务器不使用 JavaScript MIME 类型提供 ".mjs" 文件。 这会阻止浏览器执行 JavaScript 文件,从而破坏某些应用程序。 您应该配置您的网络服务器以使用 "text/javascript" 或 "application/javascript" MIME 类型提供 ".mjs" 文件。
修改nginx配置如下: location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
try_files $uri /index.php$request_uri;
# HTTP response headers borrowed from Nextcloud `.htaccess`
add_header Cache-Control "public, max-age=15778463$asset_immutable";
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "noindex, nofollow" always;
add_header X-XSS-Protection "1; mode=block" always;
access_log off; # Optional: Don't log access to assets
location ~ \.mjs$ {
default_type application/javascript;
}
location ~ \.wasm$ {
default_type application/wasm;
}
}
上面红色字体内容为增加的内容。