nginx反向代理之多端口映射的实现

时间:2022-08-30 23:53:52

代码解释

1.1 http:www.baidu.test.com默认是80,访问“/”利用反向代理,然后访问本地8083;

1.2 8083代表本地的前端工程访问地址,前端需要访问后台数据,”/”,继续代理到后台地址9803;

1.3 这样就做到了只要开通80端口就可以完成多个端口访问。

1.4 root配置可以是绝对路径,也可是相对路径。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
server {
   listen    80;
   server_name www.baidu.test.com;#你要填写的域名,多个用逗号隔开
   location / {
     proxy_pass http://localhost:8083;
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     root  /app/esop_web/esopschool;
     index index.html;
     try_files $uri $uri/ /index.html;
   }
   location /rest{
     proxy_pass http://localhost:9803;
     proxy_set_header  Host  $host;
     proxy_set_header  X-Real-IP  $remote_addr;
     proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
   }
 }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/u013067927/article/details/55519590