
服务器安装集成云盘
下载安装zfile
项目:https://docs.zfile.vip/install/os-linux
安装依赖
首次部署才需要安装依赖,更新部署见下方:更新版本
apt update
apt install -y openjdk-8-jre-headless unzip下载并解压
安装说明
下面命令中第一行表示默认安装到用户目录下: ~/zfile 下。
对于 root 用户, ~ = /root, ~/zfile 表示在 /root/zfile 路径下。
对于其他用户, ~ = /home/用户名 表示在 /home/用户名/ 路径下。如对于 oracle 用户, ~/zfile 则表示安装在 /home/oracle/zfile 下。
如需更改安装路径, 请自行修改,如 export ZFILE_INSTALL_PATH=/data/zfile,表示安装在 /data/zfile 路径下。
export ZFILE_INSTALL_PATH=~/zfile
mkdir -p $ZFILE_INSTALL_PATH && cd $ZFILE_INSTALL_PATH
wget --no-check-certificate https://c.jun6.net/ZFILE/zfile-release.war
unzip zfile-release.war && rm -rf zfile-release.war
chmod +x $ZFILE_INSTALL_PATH/bin/*.sh启动项目
~/zfile/bin/start.sh启动后浏览器访问 http://ip:8080 即可,如启动后无法访问,请检查 端口是否冲突 或 防火墙/安全组是否开启。
简单检查方式为在服务器执行 curl http://127.0.0.1:8080
- 如返回
curl: (7) Failed connect to 127.0.0.1:8080; Connection refused表示未启动成功。 - 如返回
<!DOCTYPE html> <html lang="zh-CN">……等字样表示启动成功,如启动成功但通过服务器 IP 无法访问,那一般就是防火墙/安全组未放行端口问题。
其他命令
以下为默认未修改安装路径下的情况,如修改了安装路径请自行更改命令所在路径。
# 启动
~/zfile/bin/start.sh
# 停止
~/zfile/bin/stop.sh 配置文件路径
如需修改配置文件,配置文件路径为:
~/zfile/WEB-INF/classes/application.properties更新版本
警告
更新程序前务必停止程序再进行操作,命令见下方黄色高亮部分。
如果没修改过安装路径,则停止程序后,删除安装文件夹即可,默认命令为:
如修改过安装路径,则替换下方命令中的 ~/zfile 部分为你的安装路径即可,见下方蓝色高亮部分:
~/zfile/bin/stop.sh # 停止程序
rm -rf ~/zfile # 删除安装文件夹
# 重新下载安装最新版
export ZFILE_INSTALL_PATH=~/zfile # 声明安装到的路径
mkdir -p $ZFILE_INSTALL_PATH && cd $ZFILE_INSTALL_PATH # 创建文件夹并进入
wget --no-check-certificate https://c.jun6.net/ZFILE/zfile-release.war # 下载 zfile 最新版
unzip zfile-release.war && rm -rf zfile-release.war # 解压并删除压缩包
chmod +x $ZFILE_INSTALL_PATH/bin/*.sh # 授权启动停止脚本
~/zfile/bin/start.sh # 启动项目使用HTTP访问
要将运行在Docker容器中的服务通过域名访问,并使用Nginx作为反向代理来转发到宿主机的8080端口,你需要完成几个步骤。这包括设置DNS记录、配置Nginx以及确保网络安全。下面是具体步骤:
步骤 1: 设置DNS记录
确保你的域名 drive.lthero.cn 的DNS记录指向托管Nginx的服务器的IP地址。这通常在你的域名注册商处进行设置:
- A记录:将域名指向IPv4地址。
- AAAA记录:将域名指向IPv6地址(如果适用)。
步骤 2: 安装并启动Nginx
步骤 1: 更新软件包列表
打开终端,首先使用apt命令更新你的包列表,以确保你安装的是最新版本的Nginx。
sudo apt update步骤 2: 安装Nginx
使用apt安装Nginx。
sudo apt install nginx步骤 3: 配置Nginx
你需要在Nginx中创建一个新的服务器块(server block),或者在已有的默认配置中修改,以设置反向代理。以下是一个基本的Nginx配置示例,将会把所有到 drive.lthero.cn 的请求转发到本地的8080端口:
- 打开或创建一个新的Nginx配置文件:
sudo vim /etc/nginx/sites-available/drive.lthero.cn- 添加以下配置: 这个配置做了以下几点:
server {
listen 80;
server_name drive.lthero.cn;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}listen 80;告诉Nginx监听80端口(HTTP标准端口)。server_name drive.lthero.cn;设置这个块应当响应的域名。proxy_pass http://localhost:8080;指定所有传入的请求转发到本地的8080端口。proxy_set_header指令将重要的HTTP头信息转发给后端应用。
- 启用配置文件通过创建一个符号链接(一定要做)
sudo ln -s /etc/nginx/sites-available/drive.lthero.cn /etc/nginx/sites-enabled/- 检查Nginx配置文件是否有语法错误:
sudo nginx -t- 如果没有错误,重启Nginx以应用配置(一定要做)
sudo systemctl restart nginx步骤 4: 调整防火墙规则
确保你的服务器的防火墙规则允许HTTP(端口80)和HTTPS(端口443,如果你使用SSL)的流量。如果你正在使用ufw,可以使用以下命令:
sudo ufw allow 'Nginx Full'
sudo ufw reload步骤 5: 测试配置
在浏览器中输入 http://drive.lthero.cn 或使用命令行工具如 curl 来测试你的配置:
curl http://drive.lthero.cn你应该能看到从Docker容器中运行的服务响应的内容。
这样,你就配置好了Nginx作为反向代理,将域名 drive.lthero.cn 的流量转发到宿主机的8080端口上的服务。如果你希望使用HTTPS,你还需要设置SSL证书,可以考虑使用Let’s Encrypt免费证书并配置HTTPS。
使用HTTPS访问
要让你的域名 drive.lthero.cn 使用 HTTPS,你需要获取 SSL/TLS 证书,并配置 Nginx 以使用这些证书来加密网页内容。以下是详细的步骤,包括如何使用 Let’s Encrypt 提供的免费证书自动化这个过程。
步骤 1: 安装 Certbot
Certbot 是一个自动获取并安装 Let’s Encrypt 证书的客户端。在 Ubuntu 上安装 Certbot 及其 Nginx 插件非常简单:
sudo apt update
sudo apt install certbot python3-certbot-nginx步骤 2: 获取和安装证书
使用 Certbot 获取并为你的域名安装证书:
sudo certbot --nginx -d drive.lthero.cn此命令会自动为指定的域名 drive.lthero.cn 配置 SSL 证书,并更新 Nginx 配置以使用这些证书。Certbot 会询问你一些问题,比如电子邮件地址(用于紧急联系和证书续订提醒),以及是否重定向所有 HTTP 请求到 HTTPS(强烈建议启用)。
生成的证书位置/etc/letsencrypt/live/
步骤 3: 更新 Nginx 配置
如果你想手动编辑 Nginx 配置文件,可以按以下方式配置:
sudo vim /etc/nginx/sites-available/drive.lthero.cn手动配置如下,一般certbot会自动配置好
server {
listen 80;
server_name drive.lthero.cn;
return 301 https://$server_name$request_uri; # 强制重定向所有 HTTP 请求到 HTTPS
}
server {
listen 443 ssl http2;
server_name drive.lthero.cn;
ssl_certificate /etc/letsencrypt/live/drive.lthero.cn/fullchain.pem; # 证书文件路径
ssl_certificate_key /etc/letsencrypt/live/drive.lthero.cn/privkey.pem; # 私钥文件路径
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m; # 缓存 SSL 会话以提升性能
ssl_session_tickets off;
# 现代加密套件配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers on;
# 其他 SSL 优化设置
ssl_stapling on;
ssl_stapling_verify on;
# 允许最大请求体大小为 1000MB
client_max_body_size 1000m;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}这个配置不仅启用了 HTTPS,还包括了一些现代的安全实践,如启用 HTTP/2,配置加密套件和协议等。
步骤 4: 重新加载 Nginx
更改配置后,需要重新加载 Nginx 以应用新的配置:
检查配置文件是否有语法错误,如果有warn!直接看“遇到的问题”部分,重新加载配置是不一定能work的
# 检查配置文件是否有语法错误
sudo nginx -t
# 重新加载配置
sudo systemctl reload nginx
# 如果重新加载配置后无效,可以尝试重启nginx
sudo systemctl restart nginx步骤 5: 验证 HTTPS
在浏览器中访问 https://drive.lthero.cn 来检查是否配置成功。你应该能够看到一个安全锁标志,表明连接是通过 HTTPS 加密的。
步骤 6: 自动续订证书
Let’s Encrypt 的证书有效期为90天,因此建议设置自动续订:
sudo certbot renew这个命令会测试证书续订过程。如果这个测试成功,添加定时任务crontab:
crontab -e再填写下面内容,表示每月第一天会自动执行
先用which certbot查看软件位置
0 0 1 * * /usr/local/bin/certbot renew --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --deploy-hook "nginx -s reload"续签的证书位置/etc/letsencrypt/renewal
通过以上步骤,你的站点 drive.lthero.cn 现在应该能够安全地使用 HTTPS 进行通信了。
如果要换编辑器,运行下面的命令
select-editor遇到的问题
输入了这条命令后sudo nginx -t,发现存在warn
root@ubuntu-sf:~/zfile# sudo nginx -t
nginx: [warn] conflicting server name "drive.lthero.cn" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "drive.lthero.cn" on 0.0.0.0:443, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfu解决方法:https://stackoverflow.com/questions/11426087/nginx-error-conflicting-server-name-ignored
我的解决方法:
进入sites-available目录
cd /etc/nginx/sites-available随后执行
grep -rnw . -e drive.lthero.cn这个命令会输出当前目录下,所有包含“drive.lthero.cn”字段的文件,以及出现的行数,如下
root@ubuntu-sf:/etc/nginx/sites-available# grep -rnw . -e drive.lthero.cn
./default:115: server_name drive.lthero.cn; # managed by Certbot
./default:145: ssl_certificate /etc/letsencrypt/live/drive.lthero.cn/fullchain.pem; # managed by Certbot
./default:146: ssl_certificate_key /etc/letsencrypt/live/drive.lthero.cn/privkey.pem; # managed by Certbot
./default:152: if ($host = drive.lthero.cn) {
./default:159: server_name drive.lthero.cn;
./drive.lthero.cn:3: server_name drive.lthero.cn;
./drive.lthero.cn:10: server_name drive.lthero.cn;出现的问题是在default中出来了drive.lthero.cn相关的内容
随后,我把default替换成原来的内容,如下
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}再执行reload和restart就好了
sudo systemctl reload nginx # 重新加载配置
# 如果重新加载配置后无效,可以尝试重启nginx
sudo systemctl restart nginx- 文章作者:
- Lthero博客
- 版权声明:
- 本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0许可协议。转载请注明来自 Lthero博客!




