再次利用nginx反向代理发送邮件隐藏源站IP

越来越发觉nginx是个神器,从上次隐藏回调IP,现在再次利用它来隐藏邮件发送的源站IP!

这两天网站加了CDN,目的是隐藏源站IP,现在问题来了,前置CDN解决了IP暴露问题,但是对于使用邮件注册会员的系统来说,就产生了IP暴露的问题,我们来看看是怎么回事

我使用的是QQ域名邮箱,显示邮件原文后就可以看到源站IP,这不是直接脱了裤子让人家打吗,问题总是需要解决的,研究了下nginx的用法,发现nginx可以TCP反代,这可是好东西啊!

先设置源站的nginx配置文件

stream {
upstream mail.com {
server 172.16.110.13:465 weight=1;
server 172.16.110.12:465 weight=1;
server 172.16.110.14:465 weight=1;
}

server {
    listen       465;
    proxy_pass   mail.com;
}

}

然后设置源站的hosts文件

127.0.0.1 mail.com

最后设置3台代理服务器的nginx配置

stream {
server {
listen 465;
proxy_pass smtp.qq.com:465;
}
}

因为使用的是SSL,采用465端口,自己看就明白了,举一反三,其他端口应该也差不多!

邮件配置

email.host=mail.com
email.port=465
email.username=service@umistrong.com.cn
email.password=password
email.from=service@umistrong.com.cn

最后贴一下我用的邮件发送工具类,是SSL版本的


import java.security.GeneralSecurityException;
import java.util.; import javax.mail.;
import javax.mail.internet.*;
import com.sun.mail.util.MailSSLSocketFactory;
public class EmailUtils {

private static String host = PropertiesUtils.getProperties().getProperty("email.host");
private static String port = PropertiesUtils.getProperties().getProperty("email.port");
private static String userName = PropertiesUtils.getProperties().getProperty("email.username");
private static String password = PropertiesUtils.getProperties().getProperty("email.password");
private static String from = PropertiesUtils.getProperties().getProperty("email.from");

public static void sendHTMLEmail(String to,String subject,String content) throws GeneralSecurityException{
    // 获取系统属性
    Properties properties = System.getProperties();

    // 设置邮件服务器
    properties.setProperty("mail.smtp.host", host);
    properties.put("mail.smtp.port", port);

    properties.put("mail.smtp.auth", "true");
    MailSSLSocketFactory sf = new MailSSLSocketFactory();
    sf.setTrustAllHosts(true);
    properties.put("mail.smtp.ssl.enable", "true");
    properties.put("mail.smtp.ssl.socketFactory", sf);
    // 获取默认session对象
    Session session = Session.getDefaultInstance(properties,new Authenticator(){
        public PasswordAuthentication getPasswordAuthentication()
        {
            return new PasswordAuthentication(userName,password); //发件人邮件用户名、密码
        }
    });

    try{
        // 创建默认的 MimeMessage 对象
        MimeMessage message = new MimeMessage(session);

        // Set From: 头部头字段
        message.setFrom(new InternetAddress(from));

        // Set To: 头部头字段
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

        // Set Subject: 头部头字段
        message.setSubject(subject);

        // 设置消息体
        message.setContent(content,"text/html; charset=utf-8");

        // 发送消息
        Transport.send(message);
    }catch (MessagingException mex) {
        mex.printStackTrace();
    }
}
}

这样搞完以后,对原先支付系统无需任何改动,只需要改动配置文件的邮件发送服务器地址即可,负载均衡发邮件,美滋滋!!!

收工睡觉,哈哈哈!

“再次利用nginx反向代理发送邮件隐藏源站IP”的14个回复

  1. 试了下umistrong.cn不能访问,还以为没人注册,刚想去抢注然后高价卖你,结果发现已经被注册了(手动滑稽)
    不过话说回来,阿里的企业邮箱都比腾讯那破邮箱好看且好用,我最近却开始喜欢Outlook

      1. 我把我名字、公司名字,公司缩写、英文名字、中文拼音全注册了,com org net 。。。
        只差一个我自己的中国的名字的.cn拼音域名被别人注册了,我找他要买他也没回复,哎

  2. Nice post. I be taught one thing more difficult on different blogs everyday. It will at all times be stimulating to read content from other writers and practice slightly one thing from their store. I抎 want to make use of some with the content material on my weblog whether or not you don抰 mind. Natually I抣l provide you with a hyperlink on your net blog. Thanks for sharing.

  3. I not to mention my pals have been checking out the excellent suggestions located on your web site and then then I had a terrible feeling I had not expressed respect to the web blog owner for them. All the women appeared to be so thrilled to see them and already have quite simply been having fun with them. Thank you for actually being quite thoughtful and then for selecting certain helpful information millions of individuals are really needing to be informed on. Our sincere apologies for not expressing gratitude to earlier.

  4. A lot of thanks for every one of your effort on this blog. Gloria enjoys conducting internet research and it’s really easy to understand why. Many of us notice all relating to the lively means you offer very helpful steps by means of this web blog and therefore recommend contribution from other individuals about this concern then our girl is undoubtedly being taught a whole lot. Have fun with the remaining portion of the year. Your conducting a fabulous job.

  5. I definitely wanted to develop a brief note to appreciate you for some of the marvelous tricks you are giving out at this website. My particularly long internet research has at the end of the day been honored with reasonable insight to write about with my great friends. I would tell you that many of us website visitors actually are truly endowed to be in a very good place with very many lovely people with interesting advice. I feel very much lucky to have used your webpage and look forward to plenty of more exciting times reading here. Thanks a lot once again for all the details.

  6. I am also commenting to make you understand of the magnificent experience my friend’s princess undergone reading yuor web blog. She realized many details, with the inclusion of how it is like to possess an incredible coaching character to get many more with no trouble comprehend specified tortuous topics. You undoubtedly did more than readers’ desires. Many thanks for distributing the great, trustworthy, informative and even fun tips about your topic to Ethel.

  7. My husband and i ended up being absolutely thankful Chris could do his investigations from your ideas he obtained in your web site. It’s not at all simplistic just to continually be offering secrets and techniques which often other people may have been making money from. And we acknowledge we’ve got the blog owner to thank because of that. Those explanations you have made, the straightforward website navigation, the relationships you assist to instill – it’s got many fabulous, and it’s really aiding our son in addition to us know that this theme is entertaining, which is certainly pretty mandatory. Thank you for the whole lot!

  8. A lot of thanks for each of your labor on this blog. Kate take interest in getting into investigations and it’s simple to grasp why. I hear all regarding the lively manner you present insightful guides through this blog and as well as inspire participation from other individuals on that area and our own girl is certainly being taught a whole lot. Take advantage of the remaining portion of the new year. You’re the one carrying out a stunning job.

  9. I have to express some thanks to you just for rescuing me from this circumstance. Right after surfing around throughout the internet and meeting advice that were not beneficial, I assumed my life was gone. Living without the solutions to the difficulties you have fixed all through your main blog post is a crucial case, and those that might have in a wrong way damaged my entire career if I had not encountered your blog. Your good expertise and kindness in maneuvering the whole lot was tremendous. I am not sure what I would have done if I had not encountered such a step like this. I can also at this time look forward to my future. Thank you so much for your expert and effective guide. I won’t think twice to endorse the blog to any individual who will need recommendations on this subject matter.

  10. I as well as my friends have already been analyzing the best ideas found on the website and instantly came up with a horrible suspicion I never expressed respect to the blog owner for those strategies. My guys happened to be as a consequence excited to learn all of them and already have very much been having fun with those things. Many thanks for actually being so considerate and for choosing some tremendous topics most people are really desirous to discover. My very own sincere apologies for not saying thanks to sooner.

  11. I have to show some appreciation to this writer for bailing me out of such a difficulty. Because of exploring through the the web and meeting solutions which were not helpful, I believed my life was over. Living without the presence of strategies to the problems you have fixed through your main posting is a crucial case, as well as ones that might have adversely damaged my entire career if I had not noticed the blog. Your good ability and kindness in maneuvering every part was crucial. I’m not sure what I would’ve done if I hadn’t encountered such a thing like this. I can also now relish my future. Thanks for your time so much for your expert and results-oriented guide. I won’t be reluctant to suggest your web blog to any individual who requires guide on this situation.

发表评论

电子邮件地址不会被公开。 必填项已用*标注