前提条件

  1. 具有sudo权限的用户
  2. 具有example.com域名,并成功解析到当前ip(可选)

安装Nextcloud

这里使用snap包管理工具安装Nextcloud,该打包系统可以安装自动处理底层系统的snap包,而不是安装和配置Web和数据库服务器,然后配置Nextcloud应用程序在其上运行,非常方便,适合不爱折腾的小白。

通过snap install安装

输入命令:

1
sudo snap install nextcloud

将下载Nextcloud snap 包并将其安装在系统上。

通过snap changes查看

Nextcloud软件包安装到服务器后,可以通过列出与snap关联的更改来确认安装过程是否成功:

1
snap changes nextcloud

获取snap其他信息

snap info命令可以显示描述,可用的Nextcloud管理命令,以及正在跟踪的已安装版本和快照通道:

1
snap info nextcloud

使用SSL保护Nextcloud Web界面

在我们开始使用Nextcloud之前,我们需要保护Web界面。

如果您的域名与Nextcloud服务器关联,则Nextcloud snap可以帮助您从Let的加密中获取和配置受信任的SSL证书。 如果您的Nextcloud服务器没有域名,则Nextcloud可以配置自签名证书,该证书将加密您的Web流量,但无法验证您的服务器的身份。

选项1:使用Let的加密设置SSL

如果域名与Nextcloud服务器相关联,则保护Web界面的最佳选择是获取Let的加密SSL证书。

首先打开防火墙中允许加密用于验证域所有权的端口,将Nextcloud登录页面可公开访问,但由于已经配置了管理员帐户,因此没有人能够劫持安装:

1
sudo ufw allow 80,443/tcp

接下来,输入以下内容来请求Let’s Encrypt证书:

1
sudo nextcloud.enable-https lets-encrypt

首先会询问服务器是否满足从Let’s Encrypt服务请求证书所需的条件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
OutputIn order for Let's Encrypt to verify that you actually own the
domain(s) for which you're requesting a certificate, there are a
number of requirements of which you need to be aware:

1. In order to register with the Let's Encrypt ACME server, you must
agree to the currently-in-effect Subscriber Agreement located
here:

https://letsencrypt.org/repository/

By continuing to use this tool you agree to these terms. Please
cancel now if otherwise.

2. You must have the domain name(s) for which you want certificates
pointing at the external IP address of this machine.

3. Both ports 80 and 443 on the external IP address of this machine
must point to this machine (e.g. port forwarding might need to be
setup on your router).

Have you met these requirements? (y/n)

输入y继续。

接下来,系统会要求提供用于恢复操作的电子邮件地址:

1
OutputPlease enter an email address (for urgent notices or key recovery): your_email@domain.com

最后,输入与Nextcloud服务器关联的域名:

1
OutputPlease enter your domain name(s) (space-separated): example.com

您的Let’s Encrypt证书将被请求,并且如果一切顺利,将重新启动内部Apache实例以立即实施SSL:

1
2
OutputAttempting to obtain certificates... done
Restarting apache... done

到这里就说明设置成功 。

选项2:使用自签名证书设置SSL

如果您的Nextcloud服务器没有域名,您仍然可以通过生成自签名SSL证书来保护Web界面。 此证书将允许通过加密连接访问Web界面,但无法验证服务器的身份,因此您的浏览器可能会显示警告。

要生成自签名证书并配置Nextcloud以使用它,请键入:

1
2
3
sudo nextcloud.enable-https self-signed
OutputGenerating key and self-signed certificate... done
Restarting apache... done

以上输出表明Nextcloud生成并启用了自签名证书。

现在接口是安全的,打开防火墙中的Web端口以允许访问Web界面:

1
sudo ufw allow 80,443/tcp

您现在已准备好第一次登录Nextcloud。

登录Nextcloud Web界面

现在已配置Nextcloud,请在Web浏览器中访问服务器的域名或IP地址:

1
https://example.com

注意:如果设置自签名SSL证书,则浏览器可能会显示连接不安全的警告,因为服务器的证书未由可识别的证书颁发机构签名。 这适用于自签名证书,因此请随意点击警告以继续访问该站点。输入管理员帐户后将进入Nextcloud页面。