nginx 同一个端口 不同路由 请求 不同 服务

直接上配置

user root;
worker_processes  1;
events {
  worker_connections  1024;
}
http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  server {
    listen       80;
    server_name  localhost;
    location / {
      proxy_pass   http://localhost:50001;
    }
    location /mobile/ {
      proxy_pass   http://localhost:50002/;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
  }

  server {
    listen       50001;
    location / {
      root   /home/ifnk/proj/test-web/build;
      index  index.html index.htm;
    }
    location /api {
      proxy_pass   http://localhost:5005/;
    }
  }
  server {
    listen       50002;
    location / {
      root   /home/ifnk/proj/web-collect-monorepo/packages/web-collect/dist;
      index  index.html index.htm;
    }
    location /api {
      proxy_pass   http://localhost:5005/;
    }
  }
}

有空解释和填坑……

posted @ 2022-03-08 14:38  ifnk  阅读(307)  评论(0编辑  收藏  举报