在Debian上使用Nginx,MariaDB和PHP7设置OwnCloud 9服务器
在本教程中,我将向您展示如何使用Nginx,MariaDB和PHP7在Debian 8 VPS上设置ownCloud个人云存储。 安装过程与在Debian 8上安装WordPress非常相似。该教程在仅128MB内存的VPS上进行了演示,并且可以毫无问题地运行ownCloud。 我假设您已经在Debian 8上配置了LEMP堆栈。如果尚未配置,请查看下面的简单指南,以了解如何做。
如何在Debian 8 Jessie(Nginx,MariaDB,PHP7)上安装LEMP Stack
步骤1:在Debian 8 VPS上安装ownCloud 9服务器
首先,使用wget将ownCloud签名密钥提取到您的Debian 8 VPS上。 -nv
代表不详细。
wget -nv https://download.owncloud.org/download/repositories/stable/Debian_8.0/Release.key -O Release.key
然后使用 apt-key
将此签名密钥添加到Debian 8。
sudo apt-key add - < Release.key
接下来,运行此命令以添加官方的ownCloud存储库。
sudo sh -c "echo 'deb http://download.owncloud.org/download/repositories/stable/Debian_8.0/ /' >> /etc/apt/sources.list.d/owncloud.list"
之后,更新本地软件包索引并安装 owncloud-files
。
sudo apt-get update;sudo apt-get install owncloud-files
您可以安装两个软件包: owncloud
和 owncloud-files
。 区别在于,如果您安装owncloud,则它将自动安装apache2,mysql和php5。 因为我们已经在Debian 8 VPS上配置了Nginx,MariaDB和PHP7堆栈,所以我们只需要安装独立的 owncloud-files
。
OwnCloud文件存储在 /var/www/owncloud
目录。
步骤2:为ownCloud创建数据库和用户
登录到MariaDB数据库服务器:
mysql -u root -p
然后为owncloud创建一个数据库。
create database owncloud;
在本地主机上创建数据库用户。
create user [email protected] identified by 'password';
授予该用户对owncloud数据库的所有特权。
grant all privileges on owncloud.* to [email protected] identified by 'password';
刷新特权并退出。
flush privileges; exit;
步骤3:在MariaDB中启用二进制日志记录
打开 my.cnf
文件。 您的my.cnf文件可能位于 /etc/mysql/my.cnf
。
sudo nano /etc/my.cnf
在下面添加以下三行 [mysqld] 部分。
log-bin = /var/log/mysql/mariadb-bin log-bin-index = /var/log/mysql/mariadb-bin.index binlog_format = mixed
二进制日志的格式必须混合。 保存并关闭文件。 然后重新加载MariaDB服务。
sudo service mysql reload or sudo systemctl reload mysql
步骤4:从“让我们加密”获取免费的SSL证书
首先从Github安装Let’s Encrypt客户端。
sudo apt-get install git git clone https://github.com/letsencrypt/letsencrypt
现在cd进入letsencypt目录。
cd letsencrypt/
停止Nginx进程。
sudo service nginx stop or sudo systemctl stop nginx
使用以下命令为您的域名获取SSL证书:
./letsencrypt-auto certonly --standalone --email <your-email-address> --agree-tos -d owncloud.your-domain.com
注意:我假设您正在使用诸如owncloud.your-domain.com之类的域名来访问ownCloud Web界面。 在运行上述命令之前,还需要将域名指向DNS中的服务器IP。
certonly表示客户端获得SSL证书,但不会安装它。 由于Let’s Encrypt仍处于beta中,并且不支持Nginx的自动SSL配置,因此我们必须手动配置(安装)SSL。
您的SSL证书将保存在 /etc/letsencrypt/live/<your-domain.com>
目录。
步骤5:为owncloud创建一个Nginx配置文件
sudo nano /etc/nginx/conf.d/owncloud.conf
将以下文本放入文件中。
upstream php-handler { #server 127.0.0.1:9000; server unix:/run/php/php7.0-fpm.sock; } server { listen 80; server_name owncloud.your-domain.com; # enforce https return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name owncloud.your-domain.com; ssl_certificate /etc/letsencrypt/live/owncloud.your-domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/owncloud.your-domain.com/privkey.pem; # Add headers to serve security related headers add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; 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; # Path to the root of your installation root /var/www/owncloud/; # set max upload size client_max_body_size 10G; fastcgi_buffers 64 4K; # Disable gzip to avoid the removal of the ETag header gzip off; # Uncomment if your server is build with the ngx_pagespeed module # This module is currently not supported. #pagespeed off; index index.php; error_page 403 /core/templates/403.php; error_page 404 /core/templates/404.php; rewrite ^/.well-known/carddav /remote.php/carddav/ permanent; rewrite ^/.well-known/caldav /remote.php/caldav/ permanent; # 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 = /robots.txt { allow all; log_not_found off; access_log off; } location ~ ^/(build|tests|config|lib|3rdparty|templates|data)/ { deny all; } location ~ ^/(?:.|autotest|occ|issue|indie|db_|console) { deny all; } location / { rewrite ^/remote/(.*) /remote.php last; rewrite ^(/core/doc/[^/]+/)$ $1/index.html; try_files $uri $uri/ =404; } location ~ .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; #Avoid sending the security headers twice fastcgi_pass php-handler; fastcgi_intercept_errors on; } # Adding the cache control header for js and css files # Make sure it is BELOW the location ~ .php(?:$|/) { block location ~* .(?:css|js)$ { add_header Cache-Control "public, max-age=7200"; # Add headers to serve security related headers add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; 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; # Optional: Don't log access to assets access_log off; } # Optional: Don't log access to other assets location ~* .(?:jpg|jpeg|gif|bmp|ico|png|swf)$ { access_log off; } }
将红色文本替换为您的实际数据。 此配置文件假定您的php-fpm进程在Unix套接字上侦听。 如果您的php-fpm侦听127.0.0.1:9000,则需要更改上游部分。 您也可以在此配置中为SSL启用http2。 请注意,直到1.9.5版,Nginx才支持http2。 查看以下教程,了解如何在Debian 8服务器上使用最新的Nginx版本启用HTTP2。
如何在Debian 8服务器上使用最新的Nginx版本启用HTTP2
保存此配置文件后,安装所需的php7扩展名。
sudo apt install php7.0-common php7.0-gd php7.0-json php7.0-curl php7.0-zip php7.0-xml php7.0-mbstring
现在重新启动Nginx进程。
sudo service nginx restart or sudo systemctl restart nginx
步骤6:设置Web界面
在浏览器地址栏中,键入
owncloud.your-domain.com
您需要创建一个管理帐户,并将ownCloud服务与MariaDB数据库连接。
完成后,您将进入owncloud的Web界面。 恭喜! 现在,您可以开始使用owncloud作为私有云存储。
如您所见,安装ownCloud的过程与安装WordPress和Drupal的过程非常相似。
总是欢迎提出意见,问题或建议。 如果您发现这篇文章有用, 请在社交媒体上与您的朋友分享! 请继续关注更多Linux教程。