阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

用Nginx TCP反向代理作mail邮件代理

208次阅读
没有评论

共计 3630 个字符,预计需要花费 10 分钟才能阅读完成。

用 Nginx TCP 反向代理作 mail 邮件代理

    • 1. 背景

    • 2. Nginx 安装(包括 nginx_upstream_check_module)

    • 3. Nginx 配置

    • 4. 总结

1. 背景

新版本 nginx 有 TCP 反向代理功能,nginx 的 mail proxy 配置认证又太麻烦,于是就想用 TCP 反向功能作 mail 代理。

2. Nginx 安装(包括 nginx_upstream_check_module)

cd /tmp
tar zxf pcre-8.35.tar.gz
cd pcre-8.35/
./configure --prefix=/usr/local/pcre
make
make install

cd /tmp
tar zxf openssl-1.0.2g.tar.gz
cd openssl-1.0.2g/
./config enable-tl***t
make
make install
mv -f /usr/bin/openssl /usr/bin/openssl.old
mv -f /usr/include/openssl /usr/include/openssl.old
ln -sf /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -sf /usr/local/ssl/include/openssl /usr/include/openssl

cd /tmp
git clone git@github.com:yaoweibin/nginx_upstream_check_module.git

cd /tmp
tar zxf nginx-1.13.4.tar.gz
cd nginx-1.13.4/
patch -p1 < ../nginx_upstream_check_module/check_1.12.1+.patch
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-stream=dynamic --with-stream_ssl_module --with-pcre=../pcre-8.35 --with-http_ssl_module --with-openssl=../openssl-1.0.2g --add-module=../nginx_upstream_check_module
make
make install

3. Nginx 配置

cat nginx.conf

user  www;
worker_processes  8;

error_log  logs/info.log  info;

#pid        logs/nginx.pid;

load_module modules/ngx_stream_module.so;  # 此处要添加模块

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;

   sendfile        on;
   #tcp_nopush     on;

   #keepalive_timeout  0;
   keepalive_timeout  65;

   #gzip  on;

   # 设定请求缓冲  
   server_names_hash_bucket_size 128;  
   client_header_buffer_size 32k;  
   large_client_header_buffers 4 32k;  
   client_max_body_size 300m;  
   #sendfile on;  
   tcp_nopush     on;  
   #keepalive_timeout 60;  
   tcp_nodelay on;  
   server_tokens off;  
   client_body_buffer_size 512k;  
   proxy_connect_timeout   20;  
   proxy_send_timeout      60;  
   proxy_read_timeout      20;  
   proxy_buffer_size       16k;  
   proxy_buffers           4 64k;  
   proxy_busy_buffers_size 128k;  
   proxy_temp_file_write_size 128k;  
   client_header_timeout  3m;  
   client_body_timeout    3m;  
   send_timeout           3m;  


   gzip on;# 开启 gzip,节省带宽  
   gzip_min_length  1100;  
   gzip_buffers     4 8k;  
   gzip_types       text/plain text/css application/x-Javascript image/bmp application/javascript;    

   output_buffers   1 32k;  
   postpone_output  1460;  

   limit_rate_after 3m;# 限速模块,前 3M 下载时不限速  
   limit_rate 512k; # 限速模块  


include vhost/*.conf;

}

stream {
include stream/*.conf;
}

cat stream/mail_pro.conf

######### TCP 反向代理负载均衡设置 ###############
upstream mailsmtp_pro {
       server smtp.mxhichina.com:25;
}

server {
       listen 25; # 对外提供服务 TCP 监听
       proxy_connect_timeout 5s;
       proxy_timeout 5s;
       proxy_pass mailsmtp_pro;
}

4. 总结

Nginx 功能强大,此文也是给想使用 TCP 反向代理的朋友作个示例参考吧。

更多 Nginx 关教程见以下内容

Nginx 403 forbidden 的解决办法  http://www.linuxidc.com/Linux/2017-08/146084.htm

CentOS 7 下 Nginx 服务器的安装配置  http://www.linuxidc.com/Linux/2017-04/142986.htm

CentOS 上安装 Nginx 服务器实现虚拟主机和域名重定向  http://www.linuxidc.com/Linux/2017-04/142642.htm

CentOS 6.8 安装 LNMP 环境(Linux+Nginx+MySQL+PHP)http://www.linuxidc.com/Linux/2017-04/142880.htm

Linux 下安装 PHP 环境并配置 Nginx 支持 php-fpm 模块  http://www.linuxidc.com/Linux/2017-05/144333.htm

Nginx 服务的 SSL 认证和 htpasswd 认证  http://www.linuxidc.com/Linux/2017-04/142478.htm

Ubuntu 16.04 上启用加密安全的 Nginx Web 服务器  http://www.linuxidc.com/Linux/2017-07/145522.htm

Linux 中安装配置 Nginx 及参数详解  http://www.linuxidc.com/Linux/2017-05/143853.htm

Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

CentOS 7.2 下 Nginx+PHP+MySQL+Memcache 缓存服务器安装配置  http://www.linuxidc.com/Linux/2017-03/142168.htm

CentOS6.9 编译安装 Nginx1.4.7  http://www.linuxidc.com/Linux/2017-06/144473.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

 本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-08/146599.htm 

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计3630字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中