Ubuntu安装NextCloud

常用到的重启服务指令:

重启PHP-FPM:

$ sudo systemctl restart php7.0-fpm

重启nginx:

$ sudo systemctl restart nginx





NextCloud(https://nextcloud.com/)是开源的、可以用来搭建自己的文件同步和共享的私有云服务器,它是ownCloud的一个分支。

我使用LEMP做为NextCloud的运行环境-MariaDB, PHP-FPM 和 Nginx(Ubuntu 16.04)。

1、安装MariaDB

Ubuntu 16.04 安装 MariaDB

首先,更新升级系统:

$ sudo apt update

$ sudo apt upgrade

安装MariaDB:

$ sudo apt install mariadb-server

启动MariaDB服务:

$ sudo systemctl start mysql

查看状态:

$ sudo systemctl status mysql

为例提高MariaDB的安全,我们可以执行初始化安全脚本:

$ sudo mysql_secure_installation

默认root密码为空;然后设置root密码和其他选项:

- Set root password? [Y/n] y

- Remove anonymous users? [Y/n] y

- Disallow root login remotely? [Y/n] y

- Remove test database and access to it? [Y/n] y

- Reload privilege tables now? [Y/n] y

登陆MariaDB命令行:

$ sudo mysql -u root -p

2、为NextCloud创建一个数据库和用户

MariaDB [(none)]> CREATE DATABASE nextcloud;

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'test1234';

MariaDB [(none)]> FLUSH PRIVILEGES;

MariaDB [(none)]> \q

mysql的登录密码,我也设为test1234,在此记录下。

创建数据库nextcloud;用户名nextcloud,密码test1234。

3、安装PHP和相关模块

$ sudo apt-get -y install php-fpm php-cli php-json php-curl php-imap php-gd php-mysql php-xml php-zip php-intl php-mcrypt php-imagick php-mbstring

配置PHP:

$ sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/fpm/php.ini

$ sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/fpm/php.ini

$ sudo sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/" /etc/php/7.0/fpm/php.ini

$ sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 200M/" /etc/php/7.0/fpm/php.ini

$ sudo sed -i "s/post_max_size = .*/post_max_size = 200M/" /etc/php/7.0/fpm/php.ini

重启PHP-FPM:

$ sudo systemctl restart php7.0-fpm

4、下载NextCloud

下载地址:https://download.nextcloud.com/server/releases/,我安装时最新版本是9.0.52。

$ cd /tmp

$ wget https://download.nextcloud.com/server/releases/nextcloud-9.0.52.zip

解压到/var/www/目录并更改权限:

$ unzip nextcloud-9.0.52.zip

$ sudo mkdir /var/www/

$ sudo mv nextcloud /var/www/

$ sudo chown -R www-data: /var/www/nextcloud

5、安装配置Nginx

$ sudo apt-get install nginx nginx-extras

生成自签名证书:

$ sudo mkdir -p /etc/nginx/ssl

$ cd /etc/nginx/ssl

$ sudo openssl genrsa -des3 -passout pass:x -out nextcloud.pass.key 2048

$ sudo openssl rsa -passin pass:x -in nextcloud.pass.key -out nextcloud.key

$ sudo rm nextcloud.pass.key

$ sudo openssl req -new -key nextcloud.key -out nextcloud.csr

$ sudo openssl x509 -req -days 365 -in nextcloud.csr -signkey nextcloud.key -out nextcloud.crt

也可以使用免费的let encrypt。

创建Nginx server block文件:

$ sudo vim /etc/nginx/sites-available/nextcloud

server {

listen 80;

server_name nextcloud.topspeedsnail.com;

return 301 https://$server_name$request_uri;

}

server {

listen 443 ssl http2;

server_name nextcloud.topspeedsnail.com;

root /var/www/nextcloud;

ssl on;

ssl_certificate /etc/nginx/ssl/nextcloud.crt;

ssl_certificate_key /etc/nginx/ssl/nextcloud.key;

ssl_session_timeout 5m;

ssl_ciphers   'AES128+EECDH:AES128+EDH:!aNULL';

ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;

ssl_prefer_server_ciphers on;

add_header X-Content-Type-Options nosniff;

add_header X-Frame-Options "SAMEORIGIN";

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;

access_log  /var/log/nginx/nextcloud.access.log;

error_log   /var/log/nginx/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;

gzip off;

error_page 403 /core/templates/403.php;

error_page 404 /core/templates/404.php;

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/.+|core/templates/40[34])\.php(?:$|/) {

include fastcgi_params;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

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 unix:/var/run/php/php7.0-fpm.sock;

fastcgi_intercept_errors on;

fastcgi_request_buffering off;

}

location ~ ^/(?:updater|ocs-provider)(?:$|/) {

try_files $uri/ =404;

index index.php;

}

location ~* \.(?:css|js)$ {

try_files $uri /index.php$uri$is_args$args;

add_header Cache-Control "public, max-age=7200";

add_header X-Content-Type-Options nosniff;

add_header X-Frame-Options "SAMEORIGIN";

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 ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {

try_files $uri /index.php$uri$is_args$args;

access_log off;

}

location ~ /\.ht {

deny all;

}

}

注意替换上面的域名。

server_name 改成 10.130.26.130

创建链接:

$ sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/nextcloud

测试Nginx配置文件:

$ sudo nginx -t

重启nginx:

$ sudo systemctl restart nginx

6、完成安装

使用浏览器访问 https://your_domain_or_IP;

https://10.130.26.146


参考自    http://www.linuxdiyf.com/linux/22392.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,924评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,902评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 107,716评论 0 239
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,783评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,166评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,510评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,784评论 2 311
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,476评论 0 196
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,196评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,459评论 2 243
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,978评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,321评论 2 252
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,964评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,046评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,803评论 0 193
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,530评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,420评论 2 265

推荐阅读更多精彩内容