激活prod配置文件
java -jar -Dspring.profiles.active=prod -Dlogging.path=/root/logs/mall/ mall.jar
将java项目设置为linux服务后台启动(ExecStart要用绝对路径)
新建文件
vim /etc/systemd/system/mall.service
内容
[Unit]
Description=mall
After=syslog.target
[Service]
User=root
ExecStart=/usr/local/jdk1.8.0_231/bin/java -jar -Dspring.profiles.active=prod -Dlogging.path=/root/logs/mall/ /root/mall.jar
[Install]
WantedBy=multi-user.target
启动
systemctl daemon-reload
systemctl start mall
查看
ps -ef|grep java
nginx反向代理配置(加/转发时不会拼接location的匹配参数)
比如后台接口url是http://101.139.129.189:8080/products
前端请求url是http://101.139.129.189/api/products
对应的nginx配置是
location /api/ {
proxy_pass http://127.0.0.1:8080/;
}
比如后台接口url是http://101.139.129.189:8081/pay/create
前端请求url是http://101.139.129.189/pay/create
对应的nginx配置是 (如果location的匹配参数是后端接口url需要的就要再添加上)
location /pay/ {
proxy_pass http://127.0.0.1:8081/pay/;
}