nginx: [emerg] "stream" directive is not allowed here
Asked Answered
P

0

6

i'm try to setup load balancer with nginx to keep Client IP at backends node by create file /etc/nginx/sites-available/test.conf and symlink for it

stream {
    upstream backend_servers {
        server http://server1.com;
        server http://server2.com;
    }
    
    server {
        listen     80;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass backend_servers;
    }
}

But when i run nginx -t to check, this error appear. can anyone tell me what to do now? Thanks!

Pleo answered 29/9, 2021 at 9:26 Comment(2)
stream is a top-level block statement and needs to be in your main Nginx configuration file. The sites-enabled directory is intended for configuration fragments that are included into the http block. Use nginx -T (uppercase T) to view the entire configuration across all included files.Automat
@Pleo See more detailed explanation here.Depersonalize

© 2022 - 2024 — McMap. All rights reserved.