简体   繁体   English

haproxy 背后的 nginx 邮件代理 - 获取客户端的真实 IP 地址

[英]nginx mail proxy behind haproxy - get clients real ip address

I'm using nginx as a mail proxy, for authentication and some other extras.我使用 nginx 作为邮件代理,用于身份验证和其他一些附加功能。 But I need to use another proxy in front of nginx (like haproxy).但是我需要在 nginx 前面使用另一个代理(如 haproxy)。 All is ok, things working.一切正常,一切正常。 But nginx can't retrieve clients real IP address.但是 nginx 无法检索客户端的真实 IP 地址。

In http module, i can forward it with x-forwarded-for header, and nginx's proxy_protocol.在 http 模块中,我可以使用 x-forwarded-for 标头和 nginx 的 proxy_protocol 转发它。 But in mail module, i can't do that.但是在邮件模块中,我不能这样做。 Mail module does not support proxy_protocol.邮件模块不支持 proxy_protocol。

Is there any way, how can I pass clients real IP address to nginx?有什么办法,我怎样才能将客户端的真实IP地址传递给nginx?

My haproxy and nginx config like;我的 haproxy 和 nginx 配置像;

haproxy.cfg: haproxy.cfg:

frontend IMAP
    bind 0.0.0.0:143 name IMAP tcp-ut 30s

    default_backend IMAP

backend IMAP
    option tcp-check
    tcp-check connect port 11143
    tcp-check expect string * OK

    server localhost 127.0.0.1:11143 send-proxy check

nginx.conf配置文件

mail {
    auth_http 127.0.0.1:333/auth;

    proxy on;
    imap_auth plain;
    server {
        listen 11143;
        protocol imap;
        auth_http_header proxyprotocol imap;
    }
}

This directive appeared in version 1.19.8.该指令出现在 1.19.8 版中。

http://nginx.org/en/docs/mail/ngx_mail_proxy_module.html#proxy_protocol http://nginx.org/en/docs/mail/ngx_mail_proxy_module.html#proxy_protocol

server {
    server_name ImapServer;
    listen 11143 proxy_protocol;
    protocol imap;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM