美文网首页
nginx http https共用同一个端口

nginx http https共用同一个端口

作者: 叶迎宪 | 来源:发表于2023-03-08 11:15 被阅读0次

    nginx大于1.15.2版本

    stream {
        upstream http {
            server localhost:8000;
        }
    
        upstream https {
            server localhost:8001;
        }
    
        map $ssl_preread_protocol $upstream {
            default https;
            "" http;
        }
    
        server {
            listen 8080;
            listen [::]:8080;
            proxy_pass $upstream;
            ssl_preread on;
        }
    }
    
    server {
        listen 8000;
        listen [::]:8000;
        listen 8001 ssl;
        listen [::]:8001 ssl;
    ...
    

    关键设置 ssl_preread on。有了这个设置之后,可以使用map指令,通过 $ssl_preread_protocol 判断不同的ssl协议进行分发

    参考 https://serverfault.com/questions/47876/handling-http-and-https-requests-using-a-single-port-with-nginx
    http://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html

    相关文章

      网友评论

          本文标题:nginx http https共用同一个端口

          本文链接:https://www.haomeiwen.com/subject/eiwsldtx.html