为什么nginx proxy_pass上游不起作用,但是proxy_pass https url起作用

时间:2018-11-01 09:40:16

标签: nginx

1.conf

server {
  listen 7070;
  server_name localhost;
  location / {
    proxy_redirect off;
    proxy_pass https://baidu;
  }
}

upstream baidu {
   server www.baidu.com;
}

2.conf

server {
  listen 7070;
  server_name localhost;
  location / {
    proxy_redirect off;
    proxy_pass https://www.baidu.com;
  }
}

为什么2.conf可以工作,但是1.conf无法将代理传递给https://baidu.com

它收到502 Bad Gateway个错误

1 个答案:

答案 0 :(得分:0)

如果使用SSL,则必须在上游指令中将端口443添加到服务器: https://docs.nginx.com/nginx/admin-guide/security-controls/securing-http-traffic-upstream/

server {
  listen 7070;
  server_name localhost;
  
  location / {
    proxy_redirect off;
    proxy_pass https://baidu;
  }
}

upstream baidu {
  server www.baidu.com:443;
}