nginx反向代理怎么实现多端口映射

代码解释

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

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

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

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

 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; 
    }
  }

以上就是nginx反向代理怎么实现多端口映射的详细内容,更多请关注www.sxiaw.com其它相关文章!