# Modifying nginx for use as transparent, forward proxy

**URL:** <https://www.ruby-forum.com/t/modifying-nginx-for-use-as-transparent-forward-proxy/175269>\
**Category:** NGINX\
**Created:** [September 10, 2009, 11:23am UTC](https://www.ruby-forum.com/t/modifying-nginx-for-use-as-transparent-forward-proxy/175269 "2009-09-10T11:23:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpaxton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@mpaxton](https://www.ruby-forum.com/u/mpaxton)\
**Post date:** [September 10, 2009, 11:23am UTC](https://www.ruby-forum.com/t/modifying-nginx-for-use-as-transparent-forward-proxy/175269/1 "2009-09-10T11:23:18Z")

</div>

Hi All,

My understanding is that nginx cannot be used as a forward proxy out of  
the  
box. Is this correct?

If so, my thinking is that by making some small modifications to  
ngx\_http\_proxy\_module.c, it would be possible to have a nginx.conf file  
with  
“proxy\_pass asdf”, where asdf ends up being ignored with the new  
surgical  
edits to ngx\_http\_proxy\_module.c. Instead of doing the complex lookups  
to  
figure out the backend server, it would simply pull out the “Host” from  
the  
browser/client request being made, and use that as the appropriate URL  
to  
fetch.

Would this work?

(As a background, I currently have a squid + ICAP setup in transparent  
proxy  
mode, and it works fine for proof-of-concept, but falls over in terms of  
performance. As a result, I’m trying to use nginx as a replacement. And  
with  
the http\_sub module, I’m thinking I don’t even need ICAP, since we only  
add  
a small snippet after the HTML head section of every web page.)

If there are better / easier ways of getting nginx to work as a forward  
proxy, please let me know, and I’d be happy to contribute the edits  
back.

Thanks!  
Mark

PS. If the response is in Russian, that’s cool too. I can read it just  
fine  
(and speak it), but my writing is rather poor. 🙂

---

<div class="post-metadata">

**Author:** ![mpaxton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@mpaxton](https://www.ruby-forum.com/u/mpaxton)\
**Post date:** [September 10, 2009, 12:36pm UTC](https://www.ruby-forum.com/t/modifying-nginx-for-use-as-transparent-forward-proxy/175269/2 "2009-09-10T12:36:29Z")

</div>

On Thu, Sep 10, 2009 at 02:12:55AM -0700, Mark P. wrote:

> browser/client request being made, and use that as the appropriate URL to  
> If there are better / easier ways of getting nginx to work as a forward  
> proxy, please let me know, and I’d be happy to contribute the edits back.
> 
> Thanks!  
> Mark
> 
> PS. If the response is in Russian, that’s cool too. I can read it just fine  
> (and speak it), but my writing is rather poor. 🙂

Although writing in Russian is more easy for me I answer in English,  
since this is English mailing list.

You may try the following configuration:

http {

```
 resolver 127.0.0.1; # do not forget to run named on localhost

 server {
     location / {
         proxy_pass http://$http_host$request_line;
         sub ...
     }
 }

```

However, I can not say that it will work without any issue.

---

<div class="post-metadata">

**Author:** ![mpaxton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@mpaxton](https://www.ruby-forum.com/u/mpaxton)\
**Post date:** [September 10, 2009, 12:36pm UTC](https://www.ruby-forum.com/t/modifying-nginx-for-use-as-transparent-forward-proxy/175269/3 "2009-09-10T12:36:29Z")

</div>

Igor, thanks.

2009/9/10 Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
