# Writing a module to use with http\_proxy

**URL:** <https://www.ruby-forum.com/t/writing-a-module-to-use-with-http-proxy/209728>\
**Category:** NGINX\
**Created:** [July 21, 2011, 11:53am UTC](https://www.ruby-forum.com/t/writing-a-module-to-use-with-http-proxy/209728 "2011-07-21T11:53:07Z")\
**Posts on this page:** 4\
**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:** [July 21, 2011, 11:53am UTC](https://www.ruby-forum.com/t/writing-a-module-to-use-with-http-proxy/209728/1 "2011-07-21T11:53:07Z")

</div>

Hi. I’m new to nginx module development and I’m going to write a module  
that must do everything that http\_proxy module does except it must do  
some checks before request is passed to the upstream. What’s the best  
way to do that?

Thank you.

Posted at Nginx Forum:

> **[Writing a module to use with http\_proxy](https://forum.nginx.org/read.php?2,212741,212741#msg-212741)**
>
> Hi. I'm new to nginx module development and I'm going to write a module that must do everything that http\_proxy module does except it must do some checks before request is passed to the upstream. What's the best way to do that? Thank you.

---

<div class="post-metadata">

**Author:** ![regall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@regall](https://www.ruby-forum.com/u/regall)\
**Post date:** [July 21, 2011, 12:04pm UTC](https://www.ruby-forum.com/t/writing-a-module-to-use-with-http-proxy/209728/2 "2011-07-21T12:04:51Z")

</div>

To be more precise I need some functionalty to check request and pass it  
to some (formed manually) other url if it passes check procedure and if  
the check fails - return 404 back to client.

Thank you.

Posted at Nginx Forum:

> **[Re: Writing a module to use with http\_proxy](https://forum.nginx.org/read.php?2,212741,212743#msg-212743)**
>
> Hi. I'm new to nginx module development and I'm going to write a module that must do everything that http\_proxy module does except it must do some checks before request is passed to the upstream. What's the best way to do that? Thank you.

---

<div class="post-metadata">

**Author:** ![regall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@regall](https://www.ruby-forum.com/u/regall)\
**Post date:** [July 21, 2011, 5:14pm UTC](https://www.ruby-forum.com/t/writing-a-module-to-use-with-http-proxy/209728/3 "2011-07-21T17:14:51Z")

</div>

I’ve tried to start and I faced a ‘segmentation fault’ error. I tried to  
add handler to NGX\_HTTP\_ACCESS\_PHASE and that causes segmentation fault.  
Here’s the code. Init function is called from merge\_loc\_conf  
function…

// auth check handler  
static ngx\_int\_t ngx\_http\_zd\_aws\_proxy\_check(ngx\_http\_request\_t \*r)  
{  
return NGX\_HTTP\_FORBIDDEN;  
}

// Config initializer, adds core handler to check auth  
static ngx\_int\_t ngx\_http\_zd\_aws\_proxy\_init(ngx\_conf\_t \*cf)  
{

```
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;

cmcf = ngx_http_conf_get_module_main_conf(cf,

```

ngx\_http\_core\_module);

```
h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
if (h == NULL) {
    return NGX_ERROR;
}

*h = ngx_http_zd_aws_proxy_check;

return NGX_OK;

```

}

Any thoughts on that ?

Thank you.

Posted at Nginx Forum:

> **[Re: Writing a module to use with http\_proxy](https://forum.nginx.org/read.php?2,212741,212762#msg-212762)**
>
> Hi. I'm new to nginx module development and I'm going to write a module that must do everything that http\_proxy module does except it must do some checks before request is passed to the upstream. What's the best way to do that? Thank you.

---

<div class="post-metadata">

**Author:** ![regall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@regall](https://www.ruby-forum.com/u/regall)\
**Post date:** [July 21, 2011, 5:22pm UTC](https://www.ruby-forum.com/t/writing-a-module-to-use-with-http-proxy/209728/4 "2011-07-21T17:22:17Z")

</div>

I’ve resolved the problem by addind ‘init’ function into  
postconfiguration slot of module context.  
The next problem is to find out how to get module conf variables from  
there

Posted at Nginx Forum:

> **[Re: Writing a module to use with http\_proxy](https://forum.nginx.org/read.php?2,212741,212764#msg-212764)**
>
> Hi. I'm new to nginx module development and I'm going to write a module that must do everything that http\_proxy module does except it must do some checks before request is passed to the upstream. What's the best way to do that? Thank you.
