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/;
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章