nginx 簡單實現api網關配置

一、環境:windows10、nginx 1.8

二、nginx配置文件配置
#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  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8088;
        server_name  127.0.0.1;
        
        location /duker-api {
            proxy_pass   http://127.0.0.1:9026/$request_uri;  # $scheme://$host$request_uri;

            index  index.html index.htm;
        }
        location /duker-server-api {
            proxy_pass   http://127.0.0.1:9528/$request_uri; # $scheme://$host$request_uri;
            index  index.html index.htm;
        }
    }
}

說明:兩個api訪問路徑:/duker-api、/duker-server-api,當訪問/duker-api時,讓其訪問到http://127.0.0.1:9026/duker-api/** 服務;當訪問/duker-server-api時,讓其fang訪問到http://127.0.0.1:9528/duker-server-api/** 服務。

 

三、服務demo

 

 

四、測試

訪問:http://localhost:8088/duker-api/getCuInfo

訪問:http://localhost:8088/duker-server-api/user/list

以上爲簡單實現api網關效果,並且記錄,有誤請糾正。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章