Nginx http redirect to https when https proxy_pass

301-redirectnginxproxypass

I have an nginx configuration which redirect from http to https, but on the https side the location / {} include a proxy_pass to a Go service.

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name *.domain.com domain.com;

  return 301 https://$host$request_uri;
}
server {
  listen 443 ssl http2 default_server;
  listen [::]:443 ssl http2 default_server;
  server_name auth.domain.com;

  location / {
    proxy_pass http://localhost:PORT;
  }
}

But this is not redirect the location where I setted proxy_pass.

UPDATE:

I want to redirect from http to https. There is few location which pointing static files (html), and there is a /api and the / which shows below. When I want to redirect from http to https in the statis files location its redirect, but for the locations which have a proxy_pass in it just loading on http and nothing happened.

Best Answer

Here is the configuration i use for redirecting HTTP to HTTPs :

server {
    listen [::]:80 default_server;
    listen 80 default_server;
    return 301 https://$http_host$request_uri;
}
server {
    ...normal HTTPS conf ...
}