如何部署
本文介绍如何部署卷王问卷考试系统 Pro 版本。如果想更快速便捷,可以参考 宝塔部署卷王
环境准备
环境要求
- java 环境,jre>1.8
- redis
- mysql 数据库,版本 >= 5.7
- nginx,建议最新的 stable 版本
- 文件服务,可选 minio
准备文件
- surveyking-pro.sql 数据库初始化脚本
- surveyking-server.2.0.0.jar 后端文件
- surveyking-fe.zip 前端文件
- application.properties,配置文件
初始化数据库
创建数据库,并且导入数据库脚本
# 创建数据库
create database survey default character set utf8mb4 collate utf8mb4_unicode_ci;
# 导入数据库文件
mysql --user="root" --database="survey" --password="123456" < surveyking-pro.sql"
前端部署
# 将解压后的 dist 目录放到 nginx 的 html 目录
# 目录结构应包含 dist/public 和 dist/admin
unzip surveyking-fe.zip
nginx 配置
# 如需使用 $connection_upgrade,请将 map 放在 nginx.conf 的 http 块中。
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
server_name pro.surveyking.cn;
ssl_certificate /root/pro/ssl/pro.surveyking.cn_nginx/pro.surveyking.cn_bundle.pem;
ssl_certificate_key /root/pro/ssl/pro.surveyking.cn_nginx/pro.surveyking.cn.key;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5:!3DES;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
client_max_body_size 30m;
# 直访入口 HTML 时也必须禁用缓存,避免版本更新后继续加载旧 chunk 列表。
location = /pub/index.html {
root /usr/local/nginx/html/dist/public;
etag off;
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always;
add_header Expires "0" always;
add_header X-Version $date_gmt always;
add_header Vary "Accept-Encoding" always;
try_files /index.html =404;
}
location = /adm/index.html {
root /usr/local/nginx/html/dist/admin;
etag off;
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always;
add_header Expires "0" always;
add_header X-Version $date_gmt always;
add_header Vary "Accept-Encoding" always;
try_files /index.html =404;
}
# 答题入口构建资源,对应 Umi publicPath=/pub/。
# 文件名带 hash,可以长缓存;不使用 always,避免 404 响应被浏览器长缓存。
location ^~ /pub/ {
alias /usr/local/nginx/html/dist/public/;
expires 1y;
add_header Cache-Control "public, max-age=31536000, immutable";
add_header Vary "Accept-Encoding" always;
try_files $uri =404;
}
# 后台入口构建资源,对应 Umi publicPath=/adm/。
location ^~ /adm/ {
alias /usr/local/nginx/html/dist/admin/;
expires 1y;
add_header Cache-Control "public, max-age=31536000, immutable";
add_header Vary "Accept-Encoding" always;
try_files $uri =404;
}
# 答题、练习、公开查询、兑换页面走 public 入口。
location ~ ^/(e|s|t|q|redeem)(/|$) {
root /usr/local/nginx/html/dist/public;
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always;
add_header Expires "0" always;
add_header X-Version $date_gmt always;
add_header Vary "Accept-Encoding" always;
try_files /index.html =404;
}
# 登录注册绑定同时被答题和后台使用,线上优先返回 public 入口。
location ~ ^/user/(login|register|binding)/?$ {
root /usr/local/nginx/html/dist/public;
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always;
add_header Expires "0" always;
add_header X-Version $date_gmt always;
add_header Vary "Accept-Encoding" always;
try_files /index.html =404;
}
# 二维码代理
location /captcha {
proxy_pass http://localhost:1991/captcha;
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 30m;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_send_timeout 1800;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
}
# 后端接口代理
location /admin-api {
proxy_pass http://localhost:1991/admin-api;
proxy_buffering off;
proxy_cache off;
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 30m;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_send_timeout 1800;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
}
# 兼容旧版文件访问路径。
location /files {
proxy_pass http://localhost:1991/files;
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 30m;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_send_timeout 1800;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
}
# 健康检查。
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
# 其它前端路由走后台入口。
location / {
root /usr/local/nginx/html/dist/admin;
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always;
add_header Expires "0" always;
add_header X-Version $date_gmt always;
add_header Vary "Accept-Encoding" always;
try_files $uri $uri/ /index.html;
}
}
后端部署
# 启动后端服务
nohup java -jar surveyking-server.jar >sk.log 2>&1 &
配置文件修改
将 application.properties 文件与 surveyking-server.2.0.0.jar 放入同一目录,服务启动时,将自动读取配置文件信息。
spring.application.name=SurveyKing
# 后端端口
server.port=1991
# redis配置
# redis 服务器地址
spring.redis.host=127.0.0.1
# redis 端口
spring.redis.port=6379
# redis 数据库索引
spring.redis.database=1
# 数据库配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 数据库名称
spring.datasource.dynamic.datasource.master.name=surveyking-pro
# 数据库账号
spring.datasource.dynamic.datasource.master.username=root
# 数据库密码
spring.datasource.dynamic.datasource.master.password=123456
# 滑动验证码右下角水印文字(我的水印)
aj.captcha.water-mark=卷王
部署后配置
参考宝塔部署,安装后配置。
需要配置文件服务(必选),第三方登录(可选)、验证码(可选)、登录开关(可选)、身份证Ocr(可选)