nginx 上安装 NextCloud
  • 分类:Ubuntu
  • 发表:2017-12-15
  • 围观(7,437)
  • 评论(0)

公司淘汰了一台服务器,想着怎么利用一下,想到了自建云服务。

目前比较流行的开源云服务有 Seafile 和 OwnCloud / NextCloud。

 

Seafile 是 C 语言写的,性能非常强大,所有文件加密,安全性很高,但是配置起来比较麻烦,Web 服务和文件服务是两个端口,并且除了网盘,没有其他功能。所以试用了几天就放弃了。

NextCloud 是 OwnCloud 的核心团队出来自立门户创建的,继承了 OwnCloud 的全部功能,并且把很多原本收费的功能免费了(比如 iOS App),理所当然选择 NextCloud。

官方推荐 NextCloud 最好是安装在 Apache 上,但是还是更喜欢 nginx。按照前文所说的,安装好 nginx 、php 7.1、mysql(注意,NextCloud还不支持 php 7.2)

任意目录下下载 最新版本 NextCloud,然后复制到 nginx 的默认 Web 根目录下,然后更改用户。

wget https://download.nextcloud.com/server/releases/nextcloud-12.0.4.zip
unzip nextcloud*.zip
cp -r nextcloud /var/www/
chown -R www-data:www-data /var/www/nextcloud

强烈建议使用 https 安装 NextCloud,目前国内也可以很方便的申请到免费的DV证书了,这里就不多说了。

编辑 nginx 的 conf 文件。

upstream php-handler {
#server 127.0.0.1:9000;
server unix:/var/run/php7.1-fpm.sock; #根据你的php版本来
}

server {
listen 80;
server_name cloud.example.com;  #根据你的域名来
# 强制 https
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl http2;
server_name cloud.example.com;

ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;  #你的证书
ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;  #你的证书密钥

add_header Strict-Transport-Security "max-age=15768000;
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;

# NextCloud文件路径
root /var/www/nextcloud/;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

# 如果使用 user_webfinger 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;
}

# 最大上传文件大小
client_max_body_size 2048M;
fastcgi_buffers 64 4K;

# 打开 gzip
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;

# 自己编译 nginx 的,如果打开了 ngx_pagespeed 模块,需要将下面这样取消注释
#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;
}

location ~ \.(?:css|js|woff|svg|gif)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=15778463";

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;
# 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;
}
}

然后重启 nginx

service nginx restart

就可以访问 NextCloud 云了。

https://cloud.example.com

配置好管理员用户名和密码,数据目录默认就好,mysql 用户和数据库要自己建立,不建议使用 root 账户。

点击完成安装以后就可以进入主界面了

在你的桌面电脑和手机上安装同步客户端就可以开始使用了。

另外需要注意的是,国内的宽带,不管是私人用户还是政企用户,都封禁了 80 端口和 443 端口,需要在路由器上做端口映射。

共有 0 条评论

Top