express-gateway
express-gateway copied to clipboard
How to bind express-gateway "host" to localhost and use an Nginx reverse proxy?
Entering Issues
Express-Gateway is unable to bind to localhost or 127.0.0.1
The Reverse proxy works as expected for any other service apart from the gateway.
Accessing the gateway via the nginx returns a Cannot GET /api/erp
However, access the gateway locally on the machine works well as expected.
Binding host: localhost for the http in gateway.config.yml has no effect whatsoever.
How can I resolve this.
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: true
The Reverse proxy with 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; } }
I am also having this concern. @Nditah did you find a way around this?
Me too. I got a problem with this.
I found that the gateway always listens on the server IP address request but not the localhost request. I think that we need to make it support localhost requests.
I found the solution, config the hostname
to 0.0.0.0
"http": {
"hostname": "0.0.0.0",
"port": 1234
},
I have formatted gateway.config.yml through onlineyamltools.com after my changes and it has started working.
NOW IT LOOK LIKE:
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
api:
host: localhost
paths: /ip
reqres:
host: localhost
paths: /api/users
serviceEndpoints:
httpbin:
url: https://httpbin.org
reqresserv:
url: https://reqres.in
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
default:
apiEndpoints:
- api
policies:
- proxy:
- action:
serviceEndpoint: httpbin
changeOrigin: true
reqrespipeline:
apiEndpoints:
- reqres
policies:
- proxy:
- action:
serviceEndpoint: reqresserv
changeOrigin: true
how reverse proxy in nginx for express gateway, my app not found always
@Nditah would you check your nginx config file? I can see two location /
and I don't know how come those both run with different 5000 and 5010 port? How may it differentiate?
BTW, It is possible what you are trying to.