1、环境搭建
2、打包运行
-
直接git拉取项目代码,mvn package -DskipTests,或本地打包上传
-
nohup java -jar ./xxx-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod &
(nohup:表示退出当前会话时依旧运行,&:表示后台运行),后面加上{ >mylog.log 2>&1 }或{ &>mylog.log }表示日志输出路径,>>表示追加 -
[强烈推荐] 使用Screen窗口多开,直接运行
java -jar -Dfile.encoding=utf-8 xxx-1.0-SNAPSHOT.jar > xxx.log 2>&1
,参考
列举常用命令:
screen -S 窗口名:新建
screen -r id: 重新连接窗口
screen -ls:查看所有窗口
exit:退出并销毁当前窗口
ctrl+a+d,screen -d:保留当前窗口,退出 -
前端代码,
npm run build
,将dist目录压缩成zip文件,上传解压即可:unzip 文件名 -d 指定目录
修改nginx配置文件vim /usr/local/nginx/conf/nginx.conf
,将location根路径root 改为前端代码目录的绝对路径,nginx -s reload
重启一下
常用配置如下
location / {
root /root/services/api/api-frontend;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location ^~ /api/ {
proxy_pass http://127.0.0.1:8090/api/;
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers '*';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
}
3、防火墙开放端口
#查询已开放的端口
netstat -anp
#添加指定需要开放的端口:
firewall-cmd --add-port=123/tcp --permanent
#重载入添加的端口:
firewall-cmd --reload
#查询指定端口是否开启成功:
firewall-cmd --query-port=123/tcp #yes:表示开启 no:表示未开启
#移除指定端口:
firewall-cmd --permanent --remove-port=123/tcp
#最直接 关闭防火墙
systemctl stop firewalld
- nginx:80
- mysql:3306
- redis:6379
- rabbitmq:5672
- nacos:8848