# "port\_in\_redirect off" not working

**URL:** <https://www.ruby-forum.com/t/port-in-redirect-off-not-working/211671>\
**Category:** NGINX\
**Created:** [September 10, 2011, 1:41pm UTC](https://www.ruby-forum.com/t/port-in-redirect-off-not-working/211671 "2011-09-10T13:41:01Z")\
**Posts on this page:** 3\
**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:** [September 10, 2011, 1:41pm UTC](https://www.ruby-forum.com/t/port-in-redirect-off-not-working/211671/1 "2011-09-10T13:41:01Z")

</div>

Hello,

I’m running nginx/1.0.5 behing Varnish and serving up static html.  
Whenever I visit a URL which is a directory but without a trailing  
slash, e.g. /blah, it redirects to the non-80 port which nginx is  
running on, e.g. server:5000/blah/. The config is as follows:

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

```
server {
    listen 5000;
    server_name server.com;
    root /path/html;

    location / {
        index index.html index.htm;
        port_in_redirect off;
   }
}

```

}

I’ve tried moving “port\_in\_redirect off” to http and server contexts,  
and setting “server\_name\_in\_redirect off”, to no avail. The Varnish  
configuration is as simple as can be and just looks for the request  
hostname and forwards to the nginx backend.

Regards,

Andrew

Posted at Nginx Forum:

> **["port\_in\_redirect off" not working.](https://forum.nginx.org/read.php?2,215059,215059#msg-215059)**
>
> Hello, I'm running nginx/1.0.5 behing Varnish and serving up static html. Whenever I visit a URL which is a directory but without a trailing slash, e.g. /blah, it redirects to the non-80 port which nginx is running on, e.g. server:5000/blah/. The...

---

<div class="post-metadata">

**Author:** ![carrierdetect](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f8ce5/32.png) [@carrierdetect](https://www.ruby-forum.com/u/carrierdetect)\
**Post date:** [September 10, 2011, 2:08pm UTC](https://www.ruby-forum.com/t/port-in-redirect-off-not-working/211671/2 "2011-09-10T14:08:51Z")

</div>

Hello!

On Sat, Sep 10, 2011 at 07:40:31AM -0400, carrierdetect wrote:

> ```
> sendfile on;
> }
> 
> ```
> 
> }

Works ok here.

> I’ve tried moving “port\_in\_redirect off” to http and server contexts,  
> and setting “server\_name\_in\_redirect off”, to no avail. The Varnish  
> configuration is as simple as can be and just looks for the request  
> hostname and forwards to the nginx backend.

Try connecting nginx directly or looking though tcpdump to see  
what actually nginx returns.

I suspect it’s actually caching issue, either Varnish cached the  
redirect from your previous nginx config without “port\_in\_redirect  
off;” or your browser did.

Maxim D.

---

<div class="post-metadata">

**Author:** ![carrierdetect](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f8ce5/32.png) [@carrierdetect](https://www.ruby-forum.com/u/carrierdetect)\
**Post date:** [September 10, 2011, 3:13pm UTC](https://www.ruby-forum.com/t/port-in-redirect-off-not-working/211671/3 "2011-09-10T15:13:10Z")

</div>

Hi Maxim,

## Maxim D. Wrote:

> I suspect it’s actually caching issue, either  
> Varnish cached the  
> redirect from your previous nginx config without  
> “port\_in\_redirect  
> off;” or your browser did.

Ah, so it appears that my browser had cached the redirect (and I feel  
silly for not having checked this).

Many thanks for your help!

Regards,

Andrew

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,215059,215066#msg-215066](http://forum.nginx.org/read.php?2,215059,215066#msg-215066)
