Zfile部署以及Nginx方向代理埠轉發
阿新 • • 發佈:2022-04-09
Zfile簡介
此專案是一個線上檔案目錄的程式, 支援各種物件儲存和本地儲存, 使用定位是個人放常用工具下載, 或做公共的檔案庫. 不會向多賬戶方向開發.
前端基於 h5ai 的原有功能使用 Vue 重新開發、後端採用 SpringBoot, 資料庫採用內嵌資料庫.
預覽地址: https://zfile.vip
文件地址: https://docs.zfile.vip
社群地址: https://bbs.zfile.vip
github開源地址:https://github.com/zhaojun1998/zfile/
z-file 安裝
安裝java依賴
# Debian/Ubuntu系統 apt update apt install -y openjdk-8-jre-headless unzip
下載專案
下面命令中第一行表示預設安裝到使用者目錄下: ~/zfile
下。
對於 root
使用者, ~
= /root
, ~/zfile
表示在 /root/zfile
路徑下。
對於其他使用者, ~
= /hone/使用者名稱
表示在 /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 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 # 啟動專案
~/zfile/bin/stop.sh # 停止專案
~/zfile/bin/restart.sh # 重啟專案
更新方式
# 停止程式 ~/zfile/bin/stop.sh # 刪除安裝資料夾 rm -rf ~/zfile # 重新下載安裝最新版 export ZFILE_INSTALL_PATH=~/zfile mkdir -p $ZFILE_INSTALL_PATH && cd $ZFILE_INSTALL_PATH wget https://c.jun6.net/ZFILE/zfile-release.war unzip zfile-release.war && rm -rf zfile-release.war chmod +x $ZFILE_INSTALL_PATH/bin/*.sh
DEBUG 模式
配置檔案在~/zfile/WEB-INF/classes/application.yml
開啟 debug 模式後:
- 可以訪問
http(s)://ip:port/h2-console
,使用內建的 h2 資料庫控制檯來維護資料庫。 - 可以訪問
http(s)://ip:port/debug/resetPwd
,會將使用者名稱強制重置為 admin,密碼修改為 123456。
在配置檔案 application.yml 中 zfile -> debug 修改。
NGINX 反向代理
安裝
#注:以下命令切勿使用apt 解除安裝/安裝!apt不能徹底解除安裝或者安裝!
#解除安裝之前安裝nginx
apt-get --purge remove nginx
# 安裝nginx
apt-get install nginx
#安裝位置資訊
whereis nginx
#nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
#nginx 配置資訊地址:/etc/ngin
配置
主配置資訊:/etc/nginx/nginx.conf
修改倒數兩行程式碼,若僅用nginx代理8080埠的話,可以註釋掉最後一行;否則,可將sites-enabled內的default刪除!
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
}
在conf.d檔案下,隨便新建一個a.conf
server {
listen 80;
server_name dazhutizi.top;
#access_log logs/dazhutizi_top.log;
#error_log logs/dazhutizi_top_error.log;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
}
}
常用命令
# 重新載入配置
nginx -s reload
# 檢視nginx.service狀態,按q退出
systemctl status nginx
# 關閉服務
systemctl stop nginx
#開啟服務,若重啟則,restart
systemctl start nginx
# 若報錯如下,則說明nginx服務已經存在,已經佔據埠80,可對其kill後重啟
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
#若報pid無法啟動,則以下命令啟動
nginx -c /etc/nginx/nginx.conf
# 注意!
# 注意!
# 注意!
# 測試時,請新建一個無痕瀏覽器,預設瀏覽器會快取靜態html檔案!在短時間內請求相同地址時,直接顯示已快取內容!!!!!!
# nginx -h
nginx version: nginx/1.18.0 (Ubuntu)
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/share/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file