声明:原文转载链接出自:https://www.cnblogs.com/songweipeng/p/16650647.html
一、编辑nginx.conf配置文件命令
## /usr/local/nginx/ nginx的安装路径
vim /usr/local/nginx/conf/nginx.conf
二、后端接口配置信息
server{
listen 80; # 配置端口
server_name localhost; # 配置域名
charset utf-8; # 编码
access_log /usr/local/nginx/logs/access.log main; # 成功日志
error_log /usr/local/nginx/logs/error.log error; # 错误日志
index index.html; # 查找文件顺序
# 其余location
#静态资源访问
location / {
#------------------前台资源跟路径------------------
root /songwp/project/sjsk/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://127.0.0.1:56668;
}
#/api/esbapi 对前端请求的匹配和地址截取
#http://localhost:4800/api/esbapi/manager/cm0004 截取后保留 /manager/cm0004
#然后定位到后端地址 /esbapi/manager/cm0004 其中esbapi是后端的 context-path
location /api/esbapi {
proxy_pass http://127.0.0.1:56668/esbapi;
}
location /api/mqcore {
proxy_pass http://127.0.0.1:56666/mqcore;
}
location /api/mqtask {
proxy_pass http://127.0.0.1:56669/mqtask;
}
}
}
三、重新加载配置文件
## 进入执行文件目录
cd /usr/local/nginx/sbin
## 重新加载配置文件
./nginx -s reload