Linux下Nginx 配置前后端接口
一、編輯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; # 查找文件順序 # 其余l(xiāng)ocation #靜態(tài)資源訪問 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; } } }
三、重新加載配置文件
## 進入執(zhí)行文件目錄 cd /usr/local/nginx/sbin ## 重新加載配置文件 ./nginx -s reload
古今成大事者,不唯有超世之才,必有堅韌不拔之志!

浙公網(wǎng)安備 33010602011771號