nginx如何代理转发第三方https网站

准备nginx

  • 这里准备官方nginx镜像
docker pull nginx:latest

配置default.conf


server {
    listen       80;
    server_name  localhost;


    location / {
              proxy_pass  https://xxx.com/;
              #proxy_set_header X-Real-IP $remote_addr;
              #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              #proxy_set_header X-Forwarded-Proto $scheme;
              #proxy_ssl_verify off;
              proxy_ssl_server_name on;
              proxy_ssl_session_reuse off; 
    }
}

上诉示例中,如果是https,proxy_ssl_session_reuse ,proxy_ssl_server_name ,这两个没有会报ssl SSL_do_handshake() failed
SSL_do_handshake() failed (SSL: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:SSL alert number 40) while SSL handshaking to upstream, client: 127.0.0.1, server: 127.0.0.1, request: “POST /api/test HTTP/1.1”, upstream: “https://xxxx”, host: “127.0.0.1”, referrer: “http://127.0.0.1/”
no live upstreams while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: “POST /api/test HTTP/1.1”, upstream: “https://xxxx”, host: “127.0.0.1”, referrer: “http://127.0.0.1/”

部署

  • docker-compose
version: '3'
services:
  nginx:
    container_name: nginx
    image: nginx
    restart: always
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf
    ports:
      - 10001:80
    privileged: true

你可能感兴趣的:(通用,linux,nginx,https,ssl)