<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p><tt>That's a pretty self-explanatory error actually:</tt><tt><br>
      </tt> </p>
    <tt> </tt>
    <pre class="moz-quote-pre" wrap="">Jun 06 18:18:19 proxy-lb02.srvmail.ma.gov.br nginx[52777]: nginx: [emerg]
"stream" directive is not allowed here in
/etc/nginx/email/balanceador.conf:1

Your mail configuration file is imported inside a mail block.  That won't work.

Stream operates on the same level as an http or mail block - that is, it's not *part* of the mail{} block but instead its own stream block.  You would need to import the stream function directly at /etc/nginx/nginx.conf root level and NOT as part of the mail{} block.  Details on *that* are in the nginx documentation: <a href="http://nginx.org/en/docs/stream/ngx_stream_core_module.html#stream" moz-do-not-send="true">http://nginx.org/en/docs/stream/ngx_stream_core_module.html#stream</a>

Basically, you're trying to include the stream configuration at the wrong level - the stream{} block you are configuring needs to be at the nginx.conf base level and NOT as part of the mail{} block as your nginx.conf is trying to do.


Thomas

</pre>
    <div class="moz-cite-prefix">On 6/6/20 6:51 PM, andersonsserra
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:fefa82797059cafe5676eae8f384d772.NginxMailingListEnglish@forum.nginx.org">
      <pre class="moz-quote-pre" wrap="">Hi folks,

I'm trying to do a round-robin load balancing for outgoing connections from
my MTA servers. At first I tried it as follows:

[root@proxy-lb02 email]# pwd
/etc/nginx/email
[root@proxy-lb02 email]# cat balanceador.conf
stream {
        upstream stream_backend_mail {
                least_conn;
                server mta-01.srvmail.com.br:26  max_fails=2
fail_timeout=15s;
                server mta-02.srvmail.com.br:26  max_fails=2
fail_timeout=15s;
                server mta-03.srvmail.com.br:26  max_fails=2
fail_timeout=15s;
                server mta-04.srvmail.com.br:26  max_fails=2
fail_timeout=15s;
                server mta-05.srvmail.com.br:26  max_fails=2
fail_timeout=15s;
                }


        server {
        listen     0.0.0.0:25;
        proxy_pass stream_backend_mail;
        }
}

[root@proxy-lb02 nginx]# pwd
/etc/nginx
[root@proxy-lb02 nginx]# cat nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request"
'
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;




}

mail {

        include /etc/nginx/email/*.conf;

}


[root@proxy-lb02 nginx]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error
code. See "systemctl status nginx.service" and "journalctl -xe" for
details.

[root@proxy-lb02 nginx]# systemctl status nginx -l
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor
preset: disabled)
   Active: failed (Result: exit-code) since Sáb 2020-06-06 18:18:19 EDT; 58s
ago
     Docs: <a class="moz-txt-link-freetext" href="http://nginx.org/en/docs/" moz-do-not-send="true">http://nginx.org/en/docs/</a>
  Process: 51695 ExecStop=/bin/kill -s TERM $MAINPID (code=exited,
status=0/SUCCESS)
  Process: 52777 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
(code=exited, status=1/FAILURE)
 Main PID: 51686 (code=exited, status=0/SUCCESS)

Jun 06 18:18:19 proxy-lb02.srvmail.ma.gov.br systemd[1]: Starting nginx -
high performance web server...
Jun 06 18:18:19 proxy-lb02.srvmail.ma.gov.br nginx[52777]: nginx: [emerg]
"stream" directive is not allowed here in
/etc/nginx/email/balanceador.conf:1
Jun 06 18:18:19 proxy-lb02.srvmail.ma.gov.br systemd[1]: nginx.service:
control process exited, code=exited status=1
Jun 06 18:18:19 proxy-lb02.srvmail.ma.gov.br systemd[1]: Failed to start
nginx - high performance web server.
Jun 06 18:18:19 proxy-lb02.srvmail.ma.gov.br systemd[1]: Unit nginx.service
entered failed state.
Jun 06 18:18:19 proxy-lb02.srvmail.ma.gov.br systemd[1]: nginx.service
failed.


[root@proxy-lb02 nginx]# nginx -v
nginx version: nginx/1.18.0

Could someone help me find the solution to this error?

Thanks.

Anderson Serra

Posted at Nginx Forum: <a class="moz-txt-link-freetext" href="https://forum.nginx.org/read.php?2,288282,288282#msg-288282" moz-do-not-send="true">https://forum.nginx.org/read.php?2,288282,288282#msg-288282</a>

_______________________________________________
nginx mailing list
<a class="moz-txt-link-abbreviated" href="mailto:nginx@nginx.org" moz-do-not-send="true">nginx@nginx.org</a>
<a class="moz-txt-link-freetext" href="http://mailman.nginx.org/mailman/listinfo/nginx" moz-do-not-send="true">http://mailman.nginx.org/mailman/listinfo/nginx</a></pre>
    </blockquote>
  </body>
</html>