nginx 代理imap pop smtp

为什么80%的码农都做不了架构师?>>>   hot3.png

nginx安装的时候要编译添加mail 支持 --with-mail --with-mail_ssl_module

nginx配置文件

worker_processes  4;
error_log  logs/error.log  info;
events {
    worker_connections  1024;
}
mail {
    auth_http  127.0.0.1:8070;
    pop3_capabilities  "TOP"  "USER";
    imap_capabilities  "IMAP4rev1"  "UIDPLUS";
    smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;

    server {
            listen     110;
            protocol   pop3;
            proxy      on;
    }
    server {
            listen     143;
            protocol   imap;
            proxy      on;
    }
    server {
        listen    25;
        protocol    smtp;
        proxy    on;
        smtp_auth login plain;
        xclient    off;
    }
}

auth 认证127.0.0.1:8070 这边是采用的 tornado

#!/usr/bin/env python
#coding:utf-8

import tornado.ioloop
import tornado.web
import tornado.httpserver 

class IndexHandler(tornado.web.RequestHandler):
    def get(self):
        auth_user = self.request.headers['Auth-User']
        auth_pass = self.request.headers['Auth-Pass']
        client_ip = self.request.headers['Client-Ip']
        auth_protocol = self.request.headers['Auth-Protocol']
        self.set_header('Auth-Status','OK')
        self.set_header('Auth-Server','imap.mail.com')
        self.set_header('Auth-Port','143')
        
        return
application = tornado.web.Application([
    (r"/", IndexHandler),

])      
if __name__ == "__main__":
    application.listen(8070)
    tornado.ioloop.IOLoop.current().start()

php版api认证

query("select host from mail where pdomain='".$domain."' limit 1");
while($row=mysqli_fetch_array($result)){
    $host = $row['host'];   
}
*/
switch($host){
    case "mail1.com":
        $backend = "192.168.1.1";
        break;
    case "mail2.com":
        $backend = "192.168.1.2";
        break;
}

if ($auth_protocol == "imap"){
    //header("Auth-Status:OK");
    header("Auth-Server:$backend");
    header("Auth-Port:143");
    exit();
}
else if($auth_protocol == "pop3"){
    //header("Auth-Status:OK");
    header("Auth-Server:$backend");
    header("Auth-Port:110");
    exit();
}
else if($auth_protocol == "smtp"){
    #header("Auth-Status:OK");
    header("Auth-Server:$backend");
    header("Auth-Port:25");
    exit();
}

?>

转载于:https://my.oschina.net/hxily/blog/521376

你可能感兴趣的:(nginx 代理imap pop smtp)