Search code examples
nginxwebserver

"ssl_preread" is not working in NGINX


I am trying to implement "ssl_preread" in my nginx. My nginx is compiled with "--with-stream_ssl_preread_module" this module.

I mentioned "ssl_preread on;" in server directive of nginx.conf. But i am getting below error.

nginx: [emerg] "ssl_preread" directive is not allowed here in /opt/nginx/conf/nginx.conf:43

I am following below doc.

http://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html


Solution

    1. Compile with both modules

    --with-stream

    --with-stream_ssl_preread_module

    1. Create a stream block outside http block
    stream {
        upstream app {
            server IP1:Port;
          server IP2:Port;
        }
    
        map $ssl_preread_server_name $upstream {
            default app;
        }
    
        server {
            listen PORT;
    
            ssl_preread on;
            proxy_pass $upstream;
        }
    }
    

    This worked for me. Let me know if this works for you too