落后于nginx反向代理

时间:2019-10-24 11:42:17

标签: nginx kong

我将Kong用作在Docker容器中运行的API网关。通过从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>
.......

但是,我的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":"Не верная авторизация"}

我的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;
}
}

我尝试使用$ http_host-这也行不通。

1 个答案:

答案 0 :(得分:0)

另一台主机属于nginx上的default_server。或在server_name中必须在kong api中写入所有域。