简体   繁体   English

Kong 背后 nginx 反向代理

[英]Kong behind nginx reverse proxy

I use Kong as my API Gateway, running in a Docker container.我使用 Kong 作为我的 API 网关,在 Docker 容器中运行。 By executing the following command from docker host, i get the correct answer.通过从 docker 主机执行以下命令,我得到了正确的答案。

root@prod-s-swarm01:~# curl -i -X GET --url http://prod-s-swarm:8000 --header 'Host: example.com' --header 'apikey: auth-key-maks'

HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Date: Thu, 24 Oct 2019 11:16:10 GMT
Server: Apache/2.4.7 (Ubuntu)
Vary: Accept-Encoding
X-RateLimit-Remaining-hour: 4
X-RateLimit-Limit-second: 2
X-RateLimit-Remaining-second: 1
X-RateLimit-Limit-hour: 5
X-Kong-Upstream-Latency: 25
X-Kong-Proxy-Latency: 139
Via: kong/1.3.0

<!DOCTYPE html>
<html lang="ru">
<head>
.......

But, this request over my nginx proxy return not correct answer:但是,这个请求通过我的 nginx 代理返回不正确的答案:

root@prod-s-swarm01:~# curl -i -X GET --url https://kong.myserver.com --header 'Host: example.com' --header 'apikey: auth-key-maks'
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 24 Oct 2019 11:14:33 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 97
Connection: keep-alive
X-Powered-By: Express
ETag: W/"61-Mn0BCF+92vC7dF087oyDAFsiE"

{"Status":"ERROR","Error":"Bad authorize","ErrorDesc":"Не верная авторизация"}

My nginx proxy config:我的 nginx 代理配置:

server {

listen  443 ssl;
server_name kong.myserver.com;
ssl_certificate   /etc/letsencrypt/live/appgw/fullchain.pem;
ssl_certificate_key   /etc/letsencrypt/live/appgw/privkey.pem;

location / {
     proxy_pass      http://prod-s-swarm:8000;
     proxy_set_header   Host    $host;
}
}

I tried to use, $http_host - this also not work.我尝试使用 $http_host - 这也不起作用。

Another Host's fall into in default_server on nginx.另一个主机落入 nginx 上的 default_server 中。 Or in server_name is necessary write all domains in kong api.或者必须在 server_name 中写入 kong api 中的所有域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM