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