Ngnix as Proxy with Multiple Directories Issue

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 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
it redirects me to http://licensing/licensing.fixflyer.com/downloads and
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 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 licensing;

location / {
  proxy_pass 

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;
location / {
proxy_pass
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:

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 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.

Well isnt this interesting, if I do

http://licensing/downloads

It fails with the above issue

If I do

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 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

Posted at Nginx Forum:

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
May be
http://licensing.fixflyer.com/licensing.fixflyer.com/downloads/
note the trailing “/”.

Try add these

proxy_redirect http://licensing.fixflyer.com/licensing.fixflyer.com/
/;
proxy_redirect http://licensing/licensing.fixflyer.com/
/;

By default nginx detects only this redirect:
proxy_redirect http://web.ny1.prod.fixflyer.com/licensing.fixflyer.com/
/;


Igor S.

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

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 - as an example).
Now, what if I want to view the directory listing? I type:

http://licensing/downloads

What it does then is it brings me to:

http://licensing/licensing.fixflyer.com/downloads

Or if I use the FQDN and the similar work flow with
licensing.fixflyer.com it does the following

http://licensing.fixflyer.com/licensing.fixflyer.com/downloads

Posted at Nginx Forum: