Reputation: 21
I'm trying to proxy api requests to remote api server (https://api.domain.com) That's my nginx config
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name dev.domain.com;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:8080;
}
location /api/ {
proxy_pass https://api.domain.com;
}
But I got error
no live upstreams while connecting to upstream, client: x.x.x.x, server: dev.domain.com, request: "GET /api/current_ip HTTP/1.1", upstream: "https://api.domain.com/api/current_ip", host: "dev.domain.com", referrer: "https://dev.domain.com/api/current_ip"
I don't understand what is missed in my config.
Upvotes: 2
Views: 9441
Reputation: 1118
You try to request url using http
and proxy pass https
, you'll need to add SSL configuration, when is done you have to put location /api/
before location /
server {
listen 80 default_server; # to remove, You will need to setup SSL
listen [::]:80 default_server; # to remove, You will need to setup SSL
listen 443 ssl;
listen [::]:443 ssl;
ssl_....
...
server_name dev.domain.com;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
location /api/ { ## Put this first
proxy_pass https://api.domain.com;
}
location / { ## Put this always at the end (is like a *wilcard)
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:8080;
}
}
If you want to reverse proxy something using TLS, you have to provide TLS too.
At some point it'll be better to hace a standalone config only for this reverse proxy with https
Upvotes: 3