Nginx 实现API 网关


1,网关

网关(Gateway)就是一个网络连接到另一个网络的“关口”。

在Nginx 配置负载均衡之后,可以进入到网关,在网关决定进入到哪个真实的web 服务器。

 

2,将Ngnix 配置 API 网关

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location /project-a {
            proxy_pass   http://127.0.0.1:8000/;
            index  index.html index.htm;
        }
        location /project-b {
            proxy_pass   http://127.0.0.1:8001/;
            index  index.html index.htm;
        }
    }
}

通过拦截url 请求,如果是project-a 就走http://127.0.0.1:8000/   project-b 就走http://127.0.0.1:8001/;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM