nginx 代理imap pop smtp
2015-10-23 00:00
661 查看
nginx安装的时候要编译添加mail 支持
--with-mail --with-mail_ssl_module
nginx配置文件
auth 认证127.0.0.1:8070 这边是采用的 tornado
php版api认证
--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认证
<?php if(!isset($_SERVER ["HTTP_AUTH_USER"] ) || ! isset($_SERVER ["HTTP_AUTH_PASS"] )) { header("Auth-Status: Invalid login or password"); exit; } $auth_user = $_SERVER['HTTP_AUTH_USER']; $auth_pass = $_SERVER['HTTP_AUTH_PASS']; $auth_protocol = $_SERVER['HTTP_AUTH_PROTOCOL']; list($uid, $domain) = explode("@", $auth_user); $conn = mysql_connect("127.0.0.1","root","123456"); if (!$conn){ die('Could not connect: ' . mysql_error()); } mysql_select_db("mail", $conn); $result = mysql_query("select host from mail where pdomain='".$domain."' limit 1"); while($row=mysql_fetch_array($result)){ $host = $row['host']; } /* PHP7使用mysqli连接数据库 $con = new mysqli($dbhost,$dbuser,$dbpwd,$dbname); if(mysqli_connect_errno()){ echo "mysqli connect fail: " .mysqli_connect_error(); exit(); } $result = $con->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(); } ?>
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Nginx 学习笔记(一)
- 网站502与504错误分析
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- web 应用中常用的各种 cache详解
- Linux系统上配置Nginx+Ruby on Rails+MySQL超攻略
- window+nginx+php环境配置 附配置搭配说明
- 解析CI即CodeIgniter框架在Nginx下的重写规则
- 将PHP从5.3.28升级到5.3.29时Nginx出现502错误
- 基于Nginx0.8.54+PHP5.3.4+MySQL5.5.8的全新LNMP稳定版架构搭建的VPS
- Nginx(PHP/fastcgi)的PATH_INFO问题