特快-网关无法绑定到本地主机或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/erpThe issue
nginx反向代理正常工作,但在访问网关时返回失败的响应。
Cannot GET /api/erp绑定主机: gateway.config.yml中http的本地主机没有任何效果。即使当我将主机更改为另一个IP地址和端口时,端口也反映了更改,但在快递网关控制台中,主机的IP地址保持不变为::5000。
拜托,我怎么解决这个问题?
gateway.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: trueNginx的反向代理
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;
}
}发布于 2020-11-14 15:25:35
您需要指定gateway.config.*文件的主机名。
"http": {
"hostname": "0.0.0.0",
"port": 1234
},主机名也可以是localhost。
对于快递网关,如果未指定主机名,则服务器IP地址将用作默认主机名。
示例:您的服务器IP地址:123.456.789.12在启动网关gateway http server listening on 123.456.789.12:5000时将显示以下日志
这就是nginx不能调用localhost:5000的原因
当指定主机名时,日志应该是:info: gateway http server listening on 0.0.0.0:5000
发布于 2021-03-15 22:26:52
在本部分中将本地主机更改为本地ip:
erpService:
url: 'http://localhost:5010'更改为示例:
erpService:
url: 'http://192.168.0.3:5010'并更改nginx配置端口82到5010。
server {
listen 5010;
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;
}
}这个配置适合我。
发布于 2021-09-24 13:53:14
您可以更改本地主机。这个解决方案适用于我:
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
api:
host: "gateway.example.com" =>>main domain for gateway
paths: "/ip"
panel:
host: "gateway.example.com" =>>main domain for gateway
paths: "/panel/api/v1/*"
account:
host: "gateway.example.com" =>>main domain for gateway
paths: "/account/api/v1/*"
serviceEndpoints:
httpbin:
url: "https://httpbin.org"
panelService:
urls:
- "https://panel-api.example.com" =>> panel domain
accountService:
urls:
- "https://account-api.example.com" =>> account domainhttps://stackoverflow.com/questions/63289404
复制相似问题