scyzxp 发表于 2009-11-27 11:04

nginx邮件代理功能的代码及nginx配置

简单测试nginx邮件代理功能

认证代码
auth.php<?php
if (!isset($_SERVER["HTTP_AUTH_USER"] ) || !isset($_SERVER["HTTP_AUTH_PASS"] )){
fail();
}
$username=$_SERVER["HTTP_AUTH_USER"] ;
$userpass=$_SERVER["HTTP_AUTH_PASS"] ;
$protocol=$_SERVER["HTTP_AUTH_PROTOCOL"] ;
// default backend port
$backend_port=110;
if ($protocol=="imap") {
$backend_port=143;
}
if ($protocol=="smtp") {
$backend_port=25;
}

if($username == "jacky@thismail.org"){
        $server_ip = "202.0.0.5";
}else{
        exit;
}

pass($server_ip, $backend_port);

//END


function authuser($user,$pass){
return true;
}



function fail(){
header("Auth-Status: Invalid login or password");
exit;
}

function pass($server,$port){
header("Auth-Status: OK");
header("Auth-Server: $server");
header("Auth-Port: $port");
exit;
}

?>配置nginx
nginx.conf#usernobody;
worker_processes1;

#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;

#pid      logs/nginx.pid;

events {
    worker_connections1024;
}

http {
    include       mime.types;
    default_typeapplication/octet-stream;

    #log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
    #                  '"$status" $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_loglogs/access.logmain;

    client_max_body_size25m;

    client_header_timeout3m;
    client_body_timeout    3m;
    send_timeout         3m;

    client_header_buffer_size 32k;
    large_client_header_buffers 1 128k;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 512k;
    fastcgi_buffers 4 1024k;#8 128
    fastcgi_busy_buffers_size 1024k;
    fastcgi_temp_file_write_size 1024k;
    fastcgi_intercept_errors on;

    server_names_hash_bucket_size 128;
    server_names_hash_max_size 4096;

        ssi on;
    ssi_silent_errors on;
    ssi_types text/shtml;

    gzipon;
    gzip_min_length1000;
    gzip_buffers   4 8k;
    gzip_types       text/* text/css application/javascript application/x-javascript;
    gzip_comp_level9;
    gzip_proxied   any;
    gzip_vary      on;
    gzip_http_version 1.0;
    output_buffers   4 32k;
    postpone_output1460;

    sendfile         on;
    tcp_nopush       on;
    tcp_nodelay      on;

    keepalive_timeout75 20;

    server_name_in_redirect off;


#Mail Proxy
mail {
          auth_httpmail.postfix.cn:80/auth.php;
          pop3_capabilities"TOP""USER";
          imap_capabilities"IMAP4rev1""UIDPLUS";

       #POP3 Auth
          server {
          listen   110;
          protocol   pop3;
          proxy      on;
          }

       #IMAP Auth
          server {
          listen   143;
          protocol   imap;
          proxy      on;
          }

       #SMTP Auth
          server {
              listen 25;
              protocol smtp;
              proxy on;
              xclient off;
              smtp_auth login plain;
}
}

[ 本帖最后由 scyzxp 于 2009-11-27 11:05 编辑 ]

binmouse 发表于 2009-11-27 13:30

这个是什么意思?看的不太明白,但先顶老大了!

scyzxp 发表于 2009-11-27 14:33

回复 #2 binmouse 的帖子

你仔细看看吧。或许对你做大型邮件系统有一点点帮助呢?

anthonyfeng 发表于 2009-11-27 16:03

佩服佩服。

VIP_fuck 发表于 2009-12-04 17:54

做这个认证的配置是否需要安装其他软件?
比如php或者web服务器?
谢谢。

scyzxp 发表于 2009-12-04 22:00

回复 #5 VIP_fuck 的帖子

nginx本身就是web。

cuci 发表于 2009-12-06 23:59

俺有个疑问,如果smtp发信,想把auth login的认证信息直接丢给后端的系统直接认证的话,该如何配置?有点类似透传的性质的那种

scyzxp 发表于 2009-12-07 10:52

回复 #7 cuci 的帖子

改下auth.php那里不做任何认证即可。

VIP_fuck 发表于 2009-12-07 17:17

斑竹,能不能给个运行的截图啊,看看运行是个什么效果。

我是小白,还很想用这个东西做邮件代理。

不知道那个php是干啥的,也不知道要想能运行这个东西要不要安装别的软件。

斑竹大人救命...

scyzxp 发表于 2009-12-07 17:54

回复 #9 VIP_fuck 的帖子

php是起到告诉那个用户在后台那个机器上,也可以做为认证的功能。但代码要重写。我这个只是简单的说明了原理。如果实际使用还要改进认证的代码和效率。

这个东西没有截图。也不好截图。

这个东西做邮件集群很有帮助的。原理就这样的。
页: [1] 2
查看完整版本: nginx邮件代理功能的代码及nginx配置