歡迎您光臨本站 註冊首頁

nginx郵件代理功能的代碼及nginx配置

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

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#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

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

    #access_log  logs/access.log  main;

    client_max_body_size  25m;

    client_header_timeout  3m;
    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;

    gzip  on;
    gzip_min_length  1000;
    gzip_buffers     4 8k;
    gzip_types       text/* text/css application/javascript application/x-javascript;
    gzip_comp_level  9;
    gzip_proxied     any;
    gzip_vary        on;
    gzip_http_version 1.0;
    output_buffers   4 32k;
    postpone_output  1460;

    sendfile         on;
    tcp_nopush       on;
    tcp_nodelay      on;

    keepalive_timeout  75 20;

    server_name_in_redirect off;


#Mail Proxy
mail {
          auth_http  mail.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 編輯 ]
《解決方案》

這個是什麼意思?看的不太明白,但先頂老大了!
《解決方案》

回復 #2 binmouse 的帖子

你仔細看看吧。或許對你做大型郵件系統有一點點幫助呢?
《解決方案》

佩服佩服。
《解決方案》

做這個認證的配置是否需要安裝其他軟體?
比如php或者web伺服器?
謝謝。
《解決方案》

回復 #5 VIP_fuck 的帖子

nginx本身就是web。
《解決方案》

俺有個疑問,如果smtp發信,想把auth login的認證信息直接丟給後端的系統直接認證的話,該如何配置?有點類似透傳的性質的那種
《解決方案》

回復 #7 cuci 的帖子

改下auth.php那裡不做任何認證即可。
《解決方案》

斑竹,能不能給個運行的截圖啊,看看運行是個什麼效果。

我是小白,還很想用這個東西做郵件代理。

不知道那個php是幹啥的,也不知道要想能運行這個東西要不要安裝別的軟體。

斑竹大人救命...
《解決方案》

回復 #9 VIP_fuck 的帖子

php是起到告訴那個用戶在後台那個機器上,也可以做為認證的功能。但代碼要重寫。我這個只是簡單的說明了原理。如果實際使用還要改進認證的代碼和效率。

這個東西沒有截圖。也不好截圖。

這個東西做郵件集群很有幫助的。原理就這樣的。

[火星人 ] nginx郵件代理功能的代碼及nginx配置已經有1291次圍觀

http://coctec.com/docs/service/show-post-11354.html