ユーザ用ツール

サイト用ツール


serverapps:nginx:streammailproxy

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
serverapps:nginx:streammailproxy [2017/07/16 09:02] – [注意] hayashiserverapps:nginx:streammailproxy [2017/07/16 09:36] (現在) – [参考] hayashi
行 1: 行 1:
 +====== upstreamによるメールproxy ======
  
 +===== このページについて =====
 +
 +[[serverapps:nginx:mailproxy|mailモジュールを使ったsmtp proxy]]に挫折したため、streamを利用してみます。
 +
 +
 +
 +==== 注意 ====
 +※アプリケーション層より下でProxyされるため、Nginx側でSSLを設定できません。
 +
 +===== Proxy側 =====
 +==== /usr/local/etc/nginx/nginx.conf ====
 +<code nginx>
 +
 +stream {
 +
 +    proxy_protocol on;
 +
 +    #-- smtp ------------------------------------------
 +    upstream smtp {
 +        server SMTPSERVER:25;
 +    }
 +    server {
 +        listen          {ProxyIP}:25;
 +        error_log       /var/log/nginx/smtp-error.log error;
 +        proxy_pass      smtp;
 +    }
 +    #-- smtp isubmissionport----------------------------
 +    upstream smtp_submission {
 +        server SMTPSERVER:587;
 +    }
 +    server {
 +        listen          {ProxyIP}:587;
 +        error_log       /var/log/nginx/smtp-error.log error;
 +        proxy_pass      smtp_submission;
 +    }
 +    #-- imap ------------------------------------------
 +    upstream imap {
 +        server SMTPSERVER:143;
 +    }
 +    server {
 +        listen          {ProxyIP}:143;
 +        error_log       /var/log/nginx/imap-error.log error;
 +        proxy_pass      imap;
 +    }
 +    #-- pop3 ------------------------------------------
 +    upstream pop3 {
 +        server SMTPSERVER:110;
 +    }
 +    server {
 +        listen          {ProxyIP}:110;
 +        error_log       /var/log/nginx/pop3-error.log error;
 +        proxy_pass      pop3;
 +    }
 +
 +}
 +</code>
 +
 +
 +===== メールサーバ側 =====
 +
 +==== /usr/local/etc/postfix/main.cf ====
 +
 +<code postfix>
 +smtpd_upstream_proxy_protocol = haproxy
 +</code>
 +
 +==== /usr/local/etc/dovecot/local.conf ====
 +
 +<code dovecot>
 +haproxy_trusted_networks = {Proxy IP}
 +</code>
 +
 +==== /usr/local/etc/dovecot/conf.d/10-master.conf ====
 +
 +<code dovecot>
 +service imap-login {
 +  inet_listener imap {
 +    #port = 143
 +    haproxy = yes
 +  }
 +}
 +service pop3-login {
 +  inet_listener pop3 {
 +    #port = 110
 +    haproxy = yes
 +  }
 +}
 +</code>
 +
 +===== 参考 =====
 +
 +[[https://www.nginx.com/resources/admin-guide/tcp-load-balancing/|NGINX LOAD BALANCING – TCP AND UDP LOAD BALANCER]]
 +
 +[[https://tipstricks.itmatrix.eu/tcp-load-balancing-for-email-servers-with-nginx/|TCP Load balancing email/web servers with NginX]]
 +
 +[[https://wiki2.dovecot.org/HAProxy|dovecot haproxy]]
 +
 +[[http://www.postfix.org/postconf.5.html#smtpd_upstream_proxy_protocol| smtpd_upstream_proxy_protocol]]
 +
 +[[http://tech.mercari.com/entry/2016/08/17/170114|nginxによるTCPロードバランサー]]