Nginx redirecting to wrong port

hi,

nginx runs behind a big-ip loadbalancer. the load-balancer accepts
connections on port 80, but connects to nginx on port 8080.
whenever i request a directory without trailing slash, nginx redirects
to the directory with slash, but on the wrong port.

http://www.mysite.com/directoryhttp://www.mysite.com:8080/directory.

any idea how to tell nginx, that the port is 80?

thanks

jodok batlogg

“Beautiful is better than ugly.”
– The Zen of Python, by Tim Peters

Jodok B., Lovely Systems GmbH
Schmelzhütterstraße 26a, 6850 Dornbirn, Austria
mobile: +43 664 9636963, phone: +43 5572 908060

On 04.04.2008, at 15:39, Roxis wrote:

any idea how to tell nginx, that the port is 80?

http://wiki.codemongers.com/NginxHttpCoreModule#port_in_redirect

syntax: port_in_redirect [ on|off ]
default: port_in_redirect on
context: http, server, location

Directive allows or prevents port indication in redirects handled by
nginx.

thanks i misinterpreted the docs before :slight_smile:

jodok


“Beautiful is better than ugly.”
– The Zen of Python, by Tim Peters

Jodok B., Lovely Systems GmbH
Schmelzhütterstraße 26a, 6850 Dornbirn, Austria
mobile: +43 664 9636963, phone: +43 5572 908060

On Friday 04 April 2008, Jodok B. wrote:

nginx runs behind a big-ip loadbalancer. the load-balancer accepts
connections on port 80, but connects to nginx on port 8080.
whenever i request a directory without trailing slash, nginx redirects
to the directory with slash, but on the wrong port.

http://www.mysite.com/directoryhttp://www.mysite.com:8080/directory.

any idea how to tell nginx, that the port is 80?

http://wiki.codemongers.com/NginxHttpCoreModule#port_in_redirect

syntax: port_in_redirect [ on|off ]
default: port_in_redirect on
context: http, server, location

Directive allows or prevents port indication in redirects handled by
nginx.

Hello,

I have the same problem. Did you find any solution?

I have 2 servers, one with nginx+apache1.3 and second with
nginx+apache2.
The problem is by apache1.3 only, so it must be problem of apache1.3 and
it should be set up in apache1.3 config file.

I tryed port_in_redirect on in nginx.conf, but with no sucsess.

I am sure it does apache1.3, but how to fix it I have no idea?

Thanks for any help:)

Dusan

On Tue, May 27, 2008 at 10:08:52AM +0200, Dusan Turko wrote:

I have the same problem. Did you find any solution?

I have 2 servers, one with nginx+apache1.3 and second with
nginx+apache2.
The problem is by apache1.3 only, so it must be problem of apache1.3 and
it should be set up in apache1.3 config file.

I tryed port_in_redirect on in nginx.conf, but with no sucsess.

I am sure it does apache1.3, but how to fix it I have no idea?

Could you show your proxied location ?

On Tue, May 27, 2008 at 10:55:23AM +0200, Dusan Turko wrote:

        proxy_temp_file_write_size 64k;
}

I use the same settings with apache2 on the other machine and there is
no problem. As I told, the problem occurs with apache1.3

If I type in a browser http://www.mysite.com/test/ is ok but when i type
http://www.mysite.com/test then it redirect to
http://www.mysite.com:8080/test/

This is because you set
proxy_redirect off;
and Apache 1.3 is configured to use www.mysite.com:8080 in redirects.

You may either fix Apache configuration or set in nginx:

  •      proxy_redirect     off;
    
  •      proxy_redirect     http://www.mysite.com:8080/  /;
    

Could you show your proxied location ?

   location / {
            proxy_pass         http://localhost:8080/;
            proxy_redirect     off;
    port_in_redirect off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For 
$proxy_add_x_forwarded_for;

            client_max_body_size       10m;
            client_body_buffer_size    128k;

            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;

            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
      proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
    }

I use the same settings with apache2 on the other machine and there is
no problem. As I told, the problem occurs with apache1.3

If I type in a browser http://www.mysite.com/test/ is ok but when i type
http://www.mysite.com/test then it redirect to
http://www.mysite.com:8080/test/

You may either fix Apache configuration or set in nginx:

  •      proxy_redirect     off;
    
  •      proxy_redirect     http://www.mysite.com:8080/  /;
    

Thanks for your reply

1.)It helped just when I type http://www.mysite.com/test it shows a
blank site (page does not exist) instead of redirect to
http://www.mysite.com/test/

2.) I use more virtual hosts on the server so I tryed to set up
proxy_redirect *:8080/ /;
and it does not work.

Any idea how to set it up in apache?

On Tue, May 27, 2008 at 01:29:23PM +0200, Dusan Turko wrote:

You may either fix Apache configuration or set in nginx:

  •      proxy_redirect     off;
    
  •      proxy_redirect     http://www.mysite.com:8080/  /;
    

Thanks for your reply

1.)It helped just when I type http://www.mysite.com/test it shows a
blank site (page does not exist) instead of redirect to
http://www.mysite.com/test/

Could you create debug log of this request ?

2.) I use more virtual hosts on the server so I tryed to set up
proxy_redirect *:8080/ /;
and it does not work.

nginx does not support variables in left part of proxy_redirect,
therefore
you should configure Apache.

Any idea how to set it up in apache?

Look
http://httpd.apache.org/docs/1.3/mod/core.html#usecanonicalname
http://httpd.apache.org/docs/1.3/mod/core.html#port

Try to set
UseCanonicalName on

and replace
Port 8080
with
Listen 8080

Try to set
UseCanonicalName on

and replace
Port 8080
with
Listen 8080

I just changed Listen 8080 instead of Port 8080 and it wors fine now:)
I left UseCanonicalName off

Thanks a lot!!!