0
点赞
收藏
分享

微信扫一扫

Nginx For Windows 路由配置


Nginx For Windows 路由配置

  • ​​一、路由配置说明​​
  • ​​二、需求说明​​
  • ​​三、配置文件​​

一、路由配置说明

使用Nginx进行路由配置。

使用过 SpringCloud 网关的同学都知道,网关可以使用同一IP地址同一端口号不同的服务ID,转发不同服务API信息,不会出现跨域的问题。

SpringCloud Gateway 的默认路由规则:http://Gateway_HOST:Gateway_PORT/大写的serviceId/xxx

如:
http://192.168.1.1:8080/USER-API/ 转发到 http://192.168.1.200:9090/
http://192.168.1.1:8080/CAR-API/ 转发到 http://192.168.1.201:9092/
http://192.168.1.1:8080/ORDER-API/ 转发到 http://192.168.1.202:9094/

二、需求说明

监控本地服务器的 9000 端口,根据不同的URL路径,转发到不同的网络地址。

http://127.0.0.1:9000/t1/ 转发到 http://127.0.0.1:9001/
http://127.0.0.1:9000/t2/ 转发到 http://127.0.0.1:9002/
http://127.0.0.1:9000/baidu/ 转发到 https://www.baidu.com/

三、配置文件

完整配置文件如下,测试可用

#user  nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024000;
}


http {
server {
listen 9000;
server_name localhost;
location /t1/ {
proxy_pass http://127.0.0.1:9001/;
}
location /t2/ {
proxy_pass http://127.0.0.1:9002/;
}
location /baidu/ {
proxy_pass https://www.baidu.com/;
}
}
}


举报

相关推荐

0 条评论