【nginx】配置nginx.conf && 配置多个代理

当我们的Vue项目中有多个代理时,前端webpack中

proxy:{
  //匹配字段
  '/proxyApi': {
    //代理地址
    target: 'http://192.0.0.0:7080',
    changeOrigin: true,
    //重写路径
    pathRewrite: {
      '^/proxyApi': '/back'
    }
  },
  '/apiProxy': {
    target:'http://168.0.0.0:8080',
    changeOrigin: true,
    pathRewrite: {
      '^/apiProxy/': '/new'
    }
  }
}

ngin中的配置也要同步,需要在原有的基础上增加一个 location

如果ngin中没有同步会报404

  server {
      //端口号
      listen       80;   
      server_name  localhost;

      #charset koi8-r;

      #access_log  logs/host.access.log  main;

      location / {
          //项目地址,注意需要双斜号
          root   D:\\Object\\vue
          //项目入口chunk  
          index  index.html index.htm;
      }
      //代理(原先的)
      location /proxyApi/ {
          client_max_body_size  500m;
          proxy_pass   http://localhost:7080/back/;
      }
      //代理(后加的)
      location /apiProxy/{
          client_max_body_size  500m;
          proxy_pass   http://代理地址:端口号/back/index;
      }

      #error_page  404              /404.html;

      # redirect server error pages to the static page /50x.html
      #
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   html;
      }
  }

server 要写在 http 里面  不然会报

nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:70

配置完成之后重启nginx就行了

nginx重启:nginx.exe -s reload

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值