返回

Nginx For Windows 路由配置

发布时间:2022-11-24 04:22:09 325
# nginx# 服务器# 服务器# 监控# 信息

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)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线