# Trouble with forward proxying

**URL:** <https://www.ruby-forum.com/t/trouble-with-forward-proxying/206658>\
**Category:** NGINX\
**Created:** [May 6, 2011, 6:17pm UTC](https://www.ruby-forum.com/t/trouble-with-forward-proxying/206658 "2011-05-06T18:17:11Z")\
**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:** [May 6, 2011, 6:17pm UTC](https://www.ruby-forum.com/t/trouble-with-forward-proxying/206658/1 "2011-05-06T18:17:11Z")

</div>

Hello, I’ve looked far and wide but couldn’t find an answer to my  
problem.

Here’s a quick description: an appserver must use the company’s http  
proxy for outgoing http requests, but cannot be configured. So I (tried)  
set up nginx to act as a forward proxy, like this:

server {  
listen 9099;  
resolver 10.102.10.14;  
location / {  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header Host $http\_host;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;

```
proxy_pass

```

http://proxy.example.org:80$scheme://$http\_host$request\_uri;  
}

error\_log /cygdrive/E/data/logs/forward-proxy-nginx-error.log debug;  
access\_log /cygdrive/E/data/logs/forward-proxy-nginx-access.log  
combined buffer=32k;  
}

I couldn’t find any config examples where the parent proxy is used in  
the proxy\_pass directive.

It seems like there is no other way to specify the company proxy than to  
add it to the proxy\_pass directive.

The error message I get is this, apparently, nginx looks for a colon and  
takes the rest as the port number:

2011/05/06 18:01:32 [error] 2420#0: \*1 invalid port in upstream  
“proxy.example.orghttp://www.google.com/”, client: 127.0.0.1, server: ,  
request: “GET [http://www.google.com/](http://www.google.com/) HTTP/1.1”, host: “[www.google.com](http://www.google.com)”

If I change the proxy\_pass directive to

proxy\_pass  
[http://proxy.example.org:80/$scheme://$http\_host$request\_uri](http://proxy.example.org:80/$scheme://$http_host$request_uri);

it’s the parent proxy that complains that a URL cannot start with a /  
character:

The following error was encountered while trying to retrieve the URL: [/http://www.g  
oogle.com/](https://www.ruby-forum.com/http://www.google.com/)

I’m at a loss how to continue. Could somebody please help? Thanks very  
much in advance, Jakob.

Posted at Nginx Forum:

> **[trouble with forward proxying](https://forum.nginx.org/read.php?2,196115,196115#msg-196115)**
>
> Hello, I've looked far and wide but couldn't find an answer to my problem. Here's a quick description: an appserver must use the company's http proxy for outgoing http requests, but cannot be configured. So I (tried) set up nginx to act as a forward...

---

<div class="post-metadata">

**Author:** ![jfix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce73a5/32.png) [@jfix](https://www.ruby-forum.com/u/jfix)\
**Post date:** [May 6, 2011, 6:32pm UTC](https://www.ruby-forum.com/t/trouble-with-forward-proxying/206658/2 "2011-05-06T18:32:00Z")

</div>

On Fri, May 6, 2011 at 11:16 PM, jfix [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m at a loss how to continue. Could somebody please help? Thanks very  
> much in advance, Jakob.

I don’t know, perhaps it’s related with nginx’s description?

---

<div class="post-metadata">

**Author:** ![jfix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce73a5/32.png) [@jfix](https://www.ruby-forum.com/u/jfix)\
**Post date:** [May 6, 2011, 8:21pm UTC](https://www.ruby-forum.com/t/trouble-with-forward-proxying/206658/3 "2011-05-06T20:21:55Z")

</div>

On Fri, May 06, 2011 at 12:16:55PM -0400, jfix wrote:

> location / {  
> combined buffer=32k;
> 
> character:
> 
> The following error was encountered while trying to retrieve the URL: [/http://www.g  
> oogle.com/](https://www.ruby-forum.com/http://www.google.com/)
> 
> I’m at a loss how to continue. Could somebody please help? Thanks very  
> much in advance, Jakob.

nginx is not intended to run as a forward proxy.

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![jfix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce73a5/32.png) [@jfix](https://www.ruby-forum.com/u/jfix)\
**Post date:** [May 13, 2011, 10:07pm UTC](https://www.ruby-forum.com/t/trouble-with-forward-proxying/206658/4 "2011-05-13T22:07:09Z")

</div>

2011/5/14 jfix [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> thanks, I have switched to squid. Jakob.

Squid is Proxy + Caching, it will improve the speed if you have lots  
of static files.  
But Squid is not compatible as well as Nginx for HTTP/1.1.

–  
Jeff P.

> **[403 Forbidden](http://www.dnsbed.com)**

---

<div class="post-metadata">

**Author:** ![jfix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce73a5/32.png) [@jfix](https://www.ruby-forum.com/u/jfix)\
**Post date:** [May 13, 2011, 10:01pm UTC](https://www.ruby-forum.com/t/trouble-with-forward-proxying/206658/5 "2011-05-13T22:01:36Z")

</div>

thanks, I have switched to squid. Jakob.

Posted at Nginx Forum:

> **[Re: trouble with forward proxying](https://forum.nginx.org/read.php?2,196115,197896#msg-197896)**
>
> Hello, I've looked far and wide but couldn't find an answer to my problem. Here's a quick description: an appserver must use the company's http proxy for outgoing http requests, but cannot be configured. So I (tried) set up nginx to act as a forward...
