# How to control access for specific IP-addresses of clients when using as mail proxy

**URL:** <https://www.ruby-forum.com/t/how-to-control-access-for-specific-ip-addresses-of-clients-when-using-as-mail-proxy/212958>\
**Category:** NGINX\
**Created:** [October 19, 2011, 8:06am UTC](https://www.ruby-forum.com/t/how-to-control-access-for-specific-ip-addresses-of-clients-when-using-as-mail-proxy/212958 "2011-10-19T08:06:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [October 19, 2011, 8:06am UTC](https://www.ruby-forum.com/t/how-to-control-access-for-specific-ip-addresses-of-clients-when-using-as-mail-proxy/212958/1 "2011-10-19T08:06:55Z")

</div>

Hi,

I am running nginx 1.0.8 for mail proxy , and I would like to add access  
control feature(by IP address) to this proxy.  
For HTTP, there is http access module for this purpose, however mail  
module doesn’t seem to have this feature.  
Do someone know how to implement this feature?

I found ngx\_tcpwrapper on [ngx\_tcpwrappers in Launchpad](https://launchpad.net/ngx-tcpwrappers) ,  
but unfortunately this is also only for HTTP.

Thanks and Regards,  
Soichiro

Posted at Nginx Forum:

> **[How to control access for specific IP-addresses of clients when using as mail...](https://forum.nginx.org/read.php?2,216892,216892#msg-216892)**
>
> Hi, I am running nginx 1.0.8 for mail proxy , and I would like to add access control feature(by IP address) to this proxy. For HTTP, there is http access module for this purpose, however mail module doesn't seem to have this feature. Do someone know...

---

<div class="post-metadata">

**Author:** ![mikiso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e8c25b/32.png) [@mikiso](https://www.ruby-forum.com/u/mikiso)\
**Post date:** [October 19, 2011, 11:42am UTC](https://www.ruby-forum.com/t/how-to-control-access-for-specific-ip-addresses-of-clients-when-using-as-mail-proxy/212958/2 "2011-10-19T11:42:44Z")

</div>

I have added this feature in my nginx\_tcp\_proxy\_module. You can do it as  
a  
reference:

> <https://github.com/yaoweibin/nginx_tcp_proxy_module/commit/fcacae8236444261d5e9301c144e085b706d5f32#diff-5>

2011/10/19 mikiso [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mikiso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e8c25b/32.png) [@mikiso](https://www.ruby-forum.com/u/mikiso)\
**Post date:** [October 20, 2011, 2:45am UTC](https://www.ruby-forum.com/t/how-to-control-access-for-specific-ip-addresses-of-clients-when-using-as-mail-proxy/212958/3 "2011-10-20T02:45:28Z")

</div>

Thank you very much.  
I’ll refer to these codes and add something like mail access module  
to the mail core module.

## 姚伟斌 Wrote:

> I have added this feature in my  
> nginx\_tcp\_proxy\_module. You can do it as a  
> reference:  
> [https://github.com/yaoweibin/nginx\_tcp\_proxy\_modul](https://github.com/yaoweibin/nginx_tcp_proxy_modul)  
> e/commit/fcacae8236444261d5e9301c144e085b706d5f32#  
> diff-5

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,216892,216944#msg-216944](http://forum.nginx.org/read.php?2,216892,216944#msg-216944)

---

<div class="post-metadata">

**Author:** ![mikiso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e8c25b/32.png) [@mikiso](https://www.ruby-forum.com/u/mikiso)\
**Post date:** [October 21, 2011, 2:20am UTC](https://www.ruby-forum.com/t/how-to-control-access-for-specific-ip-addresses-of-clients-when-using-as-mail-proxy/212958/4 "2011-10-21T02:20:58Z")

</div>

Finally I wrote mail access module with reference to the source code of  
http access module and  
Evan M.'s guide to Nginx module development because we need this  
feature for only pop3 proxy.

And I noticed I don’t understand how my module to be called before the  
pop3 handler.  
From the guide it is important the order of the modules, however it  
doesn’t mention granular control  
for request/connection handling.

So I’d like to know how to call this handler before the pop3 handler and  
how the ngx\_mail\_pop3\_init\_session is  
called after “epoll\_process\_event”.

Do I need to register connection handler or do I need to implement tcp  
based source code as he does?

Regards,  
Soichiro

Posted at Nginx Forum:

> **[Re: How to control access for specific IP-addresses of clients when using as...](https://forum.nginx.org/read.php?2,216892,216979#msg-216979)**
>
> Hi, I am running nginx 1.0.8 for mail proxy , and I would like to add access control feature(by IP address) to this proxy. For HTTP, there is http access module for this purpose, however mail module doesn't seem to have this feature. Do someone know...

---

<div class="post-metadata">

**Author:** ![mikiso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e8c25b/32.png) [@mikiso](https://www.ruby-forum.com/u/mikiso)\
**Post date:** [October 21, 2011, 9:40am UTC](https://www.ruby-forum.com/t/how-to-control-access-for-specific-ip-addresses-of-clients-when-using-as-mail-proxy/212958/5 "2011-10-21T09:40:18Z")

</div>

I noticed that HTTP request will be processed according to the  
ngx\_http\_phases and  
mail core module doesn’t have the same mechanism.

So it seems I have to refer to his code if I don’t want to modify the  
core code…

Posted at Nginx Forum:

> **[Re: How to control access for specific IP-addresses of clients when using as...](https://forum.nginx.org/read.php?2,216892,216989#msg-216989)**
>
> Hi, I am running nginx 1.0.8 for mail proxy , and I would like to add access control feature(by IP address) to this proxy. For HTTP, there is http access module for this purpose, however mail module doesn't seem to have this feature. Do someone know...
