一、环境:windows10、nginx 1.8

nginx 简单实现api网关配置

二、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

nginx 简单实现api网关配置

 

nginx 简单实现api网关配置

 

四、测试

访问:http://localhost:8088/duker-api/getCuInfo

nginx 简单实现api网关配置

访问:http://localhost:8088/duker-server-api/user/list

nginx 简单实现api网关配置

以上为简单实现api网关效果,并且记录,有误请纠正。

相关文章:

  • 2021-05-16
  • 2021-12-08
  • 2021-08-17
  • 2022-12-23
  • 2021-08-06
  • 2021-11-22
  • 2021-06-06
猜你喜欢
  • 2021-07-22
  • 2021-08-20
  • 2021-06-12
  • 2022-01-14
  • 2022-12-23
相关资源
相似解决方案