Problem:
I've set up a Lambda function behind API gateway which works beautifully. I have a hosted site that I want only a certain location to hit the API.
Example
https://www.example.com/ (Serves up html from hosted server)
https://www.example.com/foobar (Returns a JSON payload that is generated by Lambda and returned by AWS)
Here is my server block:
location = /foobar {
proxy_pass https://someawsuri;
proxy_redirect default;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
I've tried reviewing the docs and read multiple SO posts, but I haven't been able to do what I want. Everything that I've tried has produced the error 502 Bad Gateway
.
Question:
How do I configure nginx to make a request to API gateway?
Thanks.
I think you need those two lines:
Here is the explanation about the why:
The
HOST
header is required as is described hereThe
proxy_ssl_server_name on;