# Ngnix as Proxy with Multiple Directories Issue

**URL:** <https://www.ruby-forum.com/t/ngnix-as-proxy-with-multiple-directories-issue/210891>\
**Category:** NGINX\
**Created:** [August 19, 2011, 4:25pm UTC](https://www.ruby-forum.com/t/ngnix-as-proxy-with-multiple-directories-issue/210891 "2011-08-19T16:25:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 19, 2011, 4:25pm UTC](https://www.ruby-forum.com/t/ngnix-as-proxy-with-multiple-directories-issue/210891/1 "2011-08-19T16:25:40Z")

</div>

Hi Everyone,

I am having an odd issue here with Ngnix as a my proxy for my pages  
served up by Apache. This is a pretty vanilla proxy setup - the issues  
I am facing (and my respective config) are as follows:

I have my DNS and everything setup properly so I know that is not an  
issue. All requests to [licensing.fixflyer.com](http://licensing.fixflyer.com) and licensing are sent to  
the Ngnix web proxy and I can confirm that it is not in fact any DNS  
issue. With that -

The issue:

Whenever I type licensing/downloads or [licensing.fixflyer.com/downloads](http://licensing.fixflyer.com/downloads)  
it redirects me to [http://licensing/licensing.fixflyer.com/downloads](http://licensing/licensing.fixflyer.com/downloads) and  
[http://licensing.fixflyer.com/licensing.fixflyer.com/downloads](http://licensing.fixflyer.com/licensing.fixflyer.com/downloads)  
(respectively depending on which request was made) - the same goes for  
the downloads domain as well.

I am thinking I need to add a location block for every directory that I  
want to proxy for but that seems a little wrong - shouldnt any request  
to [licensing.fixflyer.com](http://licensing.fixflyer.com) regardless of the directory path be  
automatically resolved and not auto-appended as such?

My configuration

worker\_processes 50;

events {  
worker\_connections 1024;  
}

http {

# Debugging M2 error

error\_log /var/log/nginx/debug.err.log debug;  
proxy\_buffer\_size 64k;  
proxy\_buffers 4 64k;  
proxy\_busy\_buffers\_size 128k;  
proxy\_temp\_file\_write\_size 128k;  
client\_body\_buffer\_size 1024m;  
keepalive\_timeout 500;

# 

include mime.types;  
default\_type application/octet-stream;  
sendfile on;

client\_max\_body\_size 500m;

server {  
listen 80;  
server\_name [licensing.fixflyer.com](http://licensing.fixflyer.com) licensing;

```
location / {
  proxy_pass 

```

[http://web.ny1.prod.fixflyer.com/licensing.fixflyer.com/](http://web.ny1.prod.fixflyer.com/licensing.fixflyer.com/);  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP  
$remote\_addr;  
proxy\_set\_header X-Forwarded-For  
$proxy\_add\_x\_forwarded\_for;  
}

}

# 

# Download portal

# 

server {  
listen 80;  
server\_name downloads [downloads.fixflyer.com](http://downloads.fixflyer.com);  
location / {  
proxy\_pass  
[http://web.ny1.prod.fixflyer.com/downloads.fixflyer.com/](http://web.ny1.prod.fixflyer.com/downloads.fixflyer.com/);  
#proxy\_set\_header Host $http\_host;  
proxy\_set\_header Host $Host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
}  
#location uploads {  
# proxy\_pass http://$http\_host/uploads;  
# proxy\_set\_header Host $http\_host;  
# proxy\_set\_header X-Real-IP $remote\_addr;  
#}  
}

}

Posted at Nginx Forum:

> **[Ngnix as Proxy with Multiple Directories Issue](https://forum.nginx.org/read.php?2,214049,214049#msg-214049)**
>
> Hi Everyone, I am having an odd issue here with Ngnix as a my proxy for my pages served up by Apache. This is a pretty vanilla proxy setup - the issues I am facing (and my respective config) are as follows: I have my DNS and everything setup properly...

---

<div class="post-metadata">

**Author:** ![ckozler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@ckozler](https://www.ruby-forum.com/u/ckozler)\
**Post date:** [August 19, 2011, 4:43pm UTC](https://www.ruby-forum.com/t/ngnix-as-proxy-with-multiple-directories-issue/210891/2 "2011-08-19T16:43:03Z")

</div>

On Fri, Aug 19, 2011 at 10:24:48AM -0400, ckozler wrote:

> I am thinking I need to add a location block for every directory that I  
> want to proxy for but that seems a little wrong - shouldnt any request  
> to [licensing.fixflyer.com](http://licensing.fixflyer.com) regardless of the directory path be  
> automatically resolved and not auto-appended as such?

It’s not clear what do you expect from this setup.  
When you said about “redriect”, you mean 302 or 301 redirect ?

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![ckozler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@ckozler](https://www.ruby-forum.com/u/ckozler)\
**Post date:** [August 19, 2011, 4:52pm UTC](https://www.ruby-forum.com/t/ngnix-as-proxy-with-multiple-directories-issue/210891/3 "2011-08-19T16:52:56Z")

</div>

Well isnt this interesting, if I do

[http://licensing/downloads](http://licensing/downloads)

It fails with the above issue

If I do

[http://licensing/downloads/](http://licensing/downloads/)

- note the trailing slash - it will work and give me a directory  
listing. Is there any workaround for auto-appending a trailing slash  
when it is a directory? Eg: I would like to request  
[http://licensing/downloads](http://licensing/downloads) and have it automatically detect it is a  
directory and therefore show me the directory listing rather than  
rewriting the URL to the  
[http://licensing/licensing.fixflyer.com/downloads](http://licensing/licensing.fixflyer.com/downloads)

Posted at Nginx Forum:

> **[Re: Ngnix as Proxy with Multiple Directories Issue](https://forum.nginx.org/read.php?2,214049,214053#msg-214053)**
>
> Hi Everyone, I am having an odd issue here with Ngnix as a my proxy for my pages served up by Apache. This is a pretty vanilla proxy setup - the issues I am facing (and my respective config) are as follows: I have my DNS and everything setup properly...

---

<div class="post-metadata">

**Author:** ![ckozler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@ckozler](https://www.ruby-forum.com/u/ckozler)\
**Post date:** [August 19, 2011, 4:57pm UTC](https://www.ruby-forum.com/t/ngnix-as-proxy-with-multiple-directories-issue/210891/4 "2011-08-19T16:57:15Z")

</div>

On Fri, Aug 19, 2011 at 10:51:10AM -0400, ckozler wrote:

> Now, what if I want to view the directory listing? I type:  
> [http://licensing.fixflyer.com/licensing.fixflyer.com/downloads](http://licensing.fixflyer.com/licensing.fixflyer.com/downloads)  
> May be  
> [http://licensing.fixflyer.com/licensing.fixflyer.com/downloads/](http://licensing.fixflyer.com/licensing.fixflyer.com/downloads/)  
> note the trailing “/”.

Try add these

proxy\_redirect [http://licensing.fixflyer.com/licensing.fixflyer.com/](http://licensing.fixflyer.com/licensing.fixflyer.com/)  
/;  
proxy\_redirect [http://licensing/licensing.fixflyer.com/](http://licensing/licensing.fixflyer.com/)  
/;

By default nginx detects only this redirect:  
proxy\_redirect [http://web.ny1.prod.fixflyer.com/licensing.fixflyer.com/](http://web.ny1.prod.fixflyer.com/licensing.fixflyer.com/)  
/;

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![ckozler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@ckozler](https://www.ruby-forum.com/u/ckozler)\
**Post date:** [August 19, 2011, 4:51pm UTC](https://www.ruby-forum.com/t/ngnix-as-proxy-with-multiple-directories-issue/210891/5 "2011-08-19T16:51:42Z")

</div>

I am not sure what the redirect code would be exactly though I can  
probably snoop and view the headers. What I mean is–

I go to my browser and I type

[http://licensing](http://licensing)

And it works - I use this to generate a license for our products and it  
generates a license and I can download it from the HTML link that is  
generated ([http://licensing/downloads/license-file.jar](http://licensing/downloads/license-file.jar) - as an example).  
Now, what if I want to view the directory listing? I type:

[http://licensing/downloads](http://licensing/downloads)

What it does then is it brings me to:

[http://licensing/licensing.fixflyer.com/downloads](http://licensing/licensing.fixflyer.com/downloads)

Or if I use the FQDN and the similar work flow with  
[licensing.fixflyer.com](http://licensing.fixflyer.com) it does the following

[http://licensing.fixflyer.com/licensing.fixflyer.com/downloads](http://licensing.fixflyer.com/licensing.fixflyer.com/downloads)

Posted at Nginx Forum:

> **[Re: Ngnix as Proxy with Multiple Directories Issue](https://forum.nginx.org/read.php?2,214049,214051#msg-214051)**
>
> Hi Everyone, I am having an odd issue here with Ngnix as a my proxy for my pages served up by Apache. This is a pretty vanilla proxy setup - the issues I am facing (and my respective config) are as follows: I have my DNS and everything setup properly...
