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: http://nginx.org/en/docs/
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