Express-Gateway无法绑定到 localhost 或 127.0.0.1
调用端点直接按预期工作:
curl http://localhost:5000/ip
curl http://localhost:5010/erp
通过端口 5000 上的 ExpressGateway 访问所有端点按预期工作
curl http://localhost:5000/ip
curl http://localhost:5000/api/erp
问题
nginx反向代理正常工作但访问网关时返回失败响应
Cannot GET /api/erp
绑定主机:gateway.config.yml 中 http 的 localhost 没有任何效果。即使我将主机更改为另一个 IP 地址和端口,端口也会反映更改,但主机的 IP 地址在 express-gateway 控制台中保持不变,为 [:::5000]。
请问,我该如何解决这个问题?
网关.config.yml
http:
port: 5000
admin:
port: 9876
host: localhost
apiEndpoints:
api:
host: localhost
paths: '/ip'
erp:
host: localhost
paths: ['/api/erp', '/api/erp/*']
serviceEndpoints:
httpbin:
url: 'https://httpbin.org'
erpService:
url: 'http://localhost:5010'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
default:
apiEndpoints:
- api
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: httpbin
changeOrigin: true
erpPipeline:
apiEndpoints:
- erp
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: erpService
changeOrigin: true
Nginx 的反向代理
server {
listen 82;
location / {
proxy_pass http://localhost:5010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 81;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}