sslnginx-reverse-proxynginx-configdebian-busterpass-through

How to Correct 'nginx: [emerg] "stream" directive is not allowed here'


The Question

Why does the following Nginx configuration return nginx: [emerg] "stream" directive is not allowed here in /etc/nginx/sites-enabled/default:1?

Nginx Configuration...

stream {
  map $ssl_preread_server_name $upstream {
    example.com 1051;
  }
  upstream 1051 {
    server 127.0.0.1:1051;
  }
  server {
    listen 443;
    proxy_pass $upstream;
    ssl_preread on;
  }
}

Version / Build information...

OS: Debian 10

Here is the stripped down nginx -V output confirming the presence of the modules I understand I need...

nginx version: nginx/1.14.2
TLS SNI support enabled
configure arguments: ... --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module ...

The Context

I have a single static IP address. At the static IP address, I am setting up a reverse proxy Nginx server to forward traffic to a variety of backend services. Several of the services are websites with unique domain names.

+-----+        +----------------------+        +---------+
| WAN | <----> | Nginx Reverse Proxy  | <----> | Service |
+-----+        +----------------------+        +---------+

At boot, the service uses systemd to run this port forwarding ssh command to connect to the reverse proxy: ssh -N -R 1051:localhost:443 tunnel@example.com (That is working well.)

I want the certificate to reside on the service - not the reverse proxy. From what I understand I need to leverage SNI on Nginx to passthrough the SSL connections bases on domain name. But I cannot get the Nginx reverse proxy to passthrough SSL.

Resources

Here are a few of the resources I have pored over...


Solution

  • The problem was I tried to embed a stream block inside an http block. I was not properly accounting for the include in /etc/nginx/nignx.conf file.