开源版本服务器部署文档
大约 2 分钟
1. 后端代码打包
1.1 business-serve 配置
business-server/src/main/resources 目录中增加 application-prod.yml 文件,并修改 application.yml 中 spring.profiles.active 为 prod
server:
servlet:
context-path: /business
spring:
datasource:
url: ${db url}
username: ${db username}
password: ${db password}
redis:
host: ${redis host}
database: ${redis database}
port: ${redis port}
password: ${redis password}
security:
oauth2:
resource:
user-info-uri: ${域名/ip地址}/oauthServer/resource/userInfo/me
token-info-uri: ${域名/ip地址}/oauthServer/oauth/check_token
id: business-server-pro
jwt:
key-uri: ${域名/ip地址}/oauthServer/oauth/token_key
client:
access-token-uri: ${域名/ip地址}/oauthServer/oauth/token
user-authorization-uri: ${域名/ip地址}/oauthServer/oauth/authorize
client-id: ${client id,根据数据库中内容进行配置}
client-secret: ${client secret,根据数据库中内容进行配置(明文密码)}
grant-type: authorization_code
scope: all
auto-approve-scopes: all
# 授权回调地址
redirect-uri: ${域名/ip地址}/business/oauth2/callback
sso:
# sso token统一url
sso-redirect-url: ${域名/ip地址}/oauthServer/ssoLoginRedirect?s=%s&t=%s
xluobo:
upload:
# 静态资源/用户上传文件 存储物理地址
file-path: ${文件夹绝对路径}
# 用户导出文件临时存储物理地址
temp-save-export-path: ${文件夹绝对路径}
# 用户导入文件临时存储物理地址
temp-save-import-path: ${文件夹绝对路径}
1.2 base-oauth-server 配置
base-oauth-server/src/main/resources 目录中增加 application-prod.yml 文件,并修改 application.yml 中 spring.profiles.active 为 prod
server:
servlet:
context-path: /oauthServer
spring:
datasource:
url: ${db url}
username: ${db username}
password: ${db password}
redis:
host: ${redis host}
database: ${redis database}
port: ${redis port}
password: ${redis password}
1.3 打包
# 使用maven 进行打包
mvn install -Dmaven.test.skip=true
1.4 上传并启动两个服务
将两个jar包上传并使用profiles 为 prod 进行启动。
2. 前端代码打包
2.1 .env.production
增加 .env.production 配置文件
# just a flag
ENV = 'production'
# base api
VUE_APP_BASE_API = '/business/api'
VUE_APP_SSO_API = '/oauthServer/api'
VUE_APP_RESOURCE_API = '/business'
# sso login url
VUE_APP_SSO_SERVER_URL = '${域名/ip}/oauthServer'
VUE_REMEMBER_ME_COOKIE_NAME = 'remember-me'
# oauth2 info
VUE_APP_OAUTH2_CLIENT_ID = '${client id,根据数据库中内容进行配置}'
VUE_APP_OAUTH2_SCOPE = 'all'
# businessServer
VUE_APP_BUSINESS_SERVER_URL = '${域名/ip}/business'
# frontWebUrl
VUE_APP_FRONT_WEB_URL = '${域名/ip}'
2.2 打包并上传服务器
使用npm 进行打包,打包后将disk文件夹中的内容上传至服务器
npm run build:prod
3. nginx配置
3.1 https 域名
upstream qyxtBussinessServerPro {
server ${ip}:${business-serve服务端口};
}
upstream qyxtOauthServerPro {
server ${ip}:${base-oauth-server服务端口};
}
server {
listen 80;
server_name ${域名};
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name ${域名};
ssl_certificate ${https证书};
ssl_certificate_key ${https证书};
location / {
root ${前端页面所在文件夹};
index index.html;
}
location /business {
proxy_pass http://qyxtBussinessServerPro;
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;
proxy_set_header X-Forwarded-Port $server_port;
}
location /oauthServer {
proxy_pass http://qyxtOauthServerPro;
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;
proxy_set_header X-Forwarded-Port $server_port;
}
}
4. 数据库配置
数据库中需设置oauth2 客户端信息。具体配置表为 oauth_client_details