IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    nginx自适应https的反向代理

    C1G发表于 2023-02-28 12:27:11
    love 0

    方式一,写死地址,用变量

    最简洁

    map $scheme $online_proxy_www {
    default 39.156.66.10;
    }

    proxy_pass $scheme://$online_proxy_www:$server_port;

    方式二,写两个upstream,再用proxy_pass覆盖法

    缺点需要维护2个upsteam

    upstream online_proxy_www {
    server 39.156.66.10:80;
    }
    upstream online_proxy_www_https {
    server 39.156.66.10:443;
    }

    proxy_pass $scheme://online_proxy_www;

    自适应https

    if ( $scheme = https) {
    proxy_pass $scheme://online_proxy_www_https;
    }

    方式三,upstream backup法

    最简单,缺点会多一次请求,多个错误日志

    upstream online_proxy_www {
    server 39.156.66.10:80;39.156.66.10
    server 39.156.66.10:443 backup;
    }
    proxy_pass $scheme://online_proxy_www;

    ==========================

    nginx.conf示例

    upstream online_proxy_www {
        server   39.156.66.10:80;
        #server   39.156.66.10:443 backup;
    }
    upstream online_proxy_www_https {
        server   39.156.66.10:443;
    }
    
    
    server
    {
        listen       80;
        listen       443 ssl;
        server_name  blog.c1gstudio.com;
        index index.html index.htm index.php;
        root  /opt/htdocs/www;
        access_log  /var/log/nginx/blog.c1gstudio.com.log  access ;
    
        include ssl.conf;
    
        location /
        {
            proxy_set_header Host  $host;
            proxy_set_header X-Forwarded-For $proxypass_forwarded_for;
            proxy_pass $scheme://$online_proxy_www:$server_port;
    
            add_header      X-Cache   C1GPROXY1;
        }
    
    
    }

    Related Posts

    • [转]WEB架构 – v.2008.163.com对新架构的尝试 ( 2009-10-19)
    • Nginx 修补bug,平滑升级至0.8.16 ( 2009-10-16)
    • Nginx 0.7.x + PHP 5.2.10 +Mysql 5.1.37 on CentOs 5.2 ( 2009-09-03)

    The post nginx自适应https的反向代理 first appeared on C1G军火库.



沪ICP备19023445号-2号
友情链接