nginx将http重定向到代理ssl中的https

时间:2019-01-29 01:29:03

标签: nginx

这是我当前的nginx配置:

server {
  listen *:80;
  server_name upload.expert;
  proxy_set_header Host upload.expert;
  location / {
    rewrite ^(.*)$ https://upload.expert$1 permanent;
  }
}

server {
  listen *:443 ssl;
  server_name upload.expert;
  proxy_set_header Host upload.expert;
  location / {
    proxy_pass http://localhost:3000;
  }
}

https站点正常运行,http返回ERR_CONNECTION_REFUSED,怎么了?

真实网站:http://upload.experthttps://upload.expert

1 个答案:

答案 0 :(得分:0)

您可以像这样重定向(带有请求uri):

server {
      listen *:80;
      server_name upload.expert;
      return 301 https://$host$request_uri;
    }

    server {
      listen *:443 ssl;
      server_name upload.expert;
      proxy_set_header Host upload.expert;
      location / {
        proxy_pass http://localhost:3000;
      }
    }