# Port redirect in URL

**URL:** <https://www.ruby-forum.com/t/port-redirect-in-url/244496>\
**Category:** NGINX\
**Created:** [April 21, 2016, 4:10pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496 "2016-04-21T16:10:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [April 21, 2016, 4:10pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496/1 "2016-04-21T16:10:06Z")

</div>

Hello,

I’m going a bit crazy here and hoping for some help. I’ve set up a new  
Mailman installation on FreeBSD. The system is set as follows:

Web ↔ nginx SSL termination and reverse proxy ↔ nginx + fcgiwrap +  
Mailman

When I try to access [https://lists.mydomain.com](https://lists.mydomain.com) or  
[https://lists.mydomain.com/](https://lists.mydomain.com/) it redirects me to  
[https://lists.mydomain.com:8000/mailman/listinfo](https://lists.mydomain.com:8000/mailman/listinfo) which of course fails.

If I access [https://lists.mydomain.com/mailman/listinfo](https://lists.mydomain.com/mailman/listinfo) directly or any  
URL except the main one, it works as expected.

I have tried multiple options including:

port\_in\_redirect off;  
proxy\_bind $host:443;  
proxy\_redirect off;

Nothing seems to be working.  
Proxy settings for nginx front end: server

```
 location / {
     proxy_pass http://10.0.250.37:8000;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

```

proxy\_set\_header X-Forwarded-Proto $scheme;  
proxy\_http\_version 1.1;  
proxy\_set\_header Connection “”;  
proxy\_redirect off;  
proxy\_set\_header Host $host;

[snip]  
}

Backend server uses fastcgi for Python via fcgiwrap. Any help would be  
appreciated.

–  
Jim O.

“Never argue with a fool, onlookers may not be able to tell the  
difference.” - Mark Twain

---

<div class="post-metadata">

**Author:** ![joviyach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@joviyach](https://www.ruby-forum.com/u/joviyach)\
**Post date:** [April 21, 2016, 4:15pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496/2 "2016-04-21T16:15:21Z")

</div>

On 21 Apr 2016, at 17:09, Jim O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have tried multiple options including:  
> proxy\_set\_header X-Real-IP $remote\_addr;  
> Backend server uses fastcgi for Python via fcgiwrap. Any help would be  
> appreciated.  
> proxy\_redirect on;

–  
Igor S.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![joviyach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@joviyach](https://www.ruby-forum.com/u/joviyach)\
**Post date:** [April 21, 2016, 4:17pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496/3 "2016-04-21T16:17:42Z")

</div>

On 21 Apr 2016, at 17:14, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > If I access [https://lists.mydomain.com/mailman/listinfo](https://lists.mydomain.com/mailman/listinfo) directly or any URL  
> > except the main one, it works as expected.  
> > location / {  
> > }
> > 
> > Backend server uses fastcgi for Python via fcgiwrap. Any help would be  
> > appreciated.
> 
> proxy\_redirect on;

Sorry, no.

proxy\_redirect [https://lists.mydomain.com:8000/](https://lists.mydomain.com:8000/) /;

–  
Igor S.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![joviyach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@joviyach](https://www.ruby-forum.com/u/joviyach)\
**Post date:** [April 21, 2016, 4:42pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496/4 "2016-04-21T16:42:14Z")

</div>

Hello,

On 4/21/16 10:17 AM, Igor S. wrote:

> > > When I try to access [https://lists.mydomain.com](https://lists.mydomain.com) or [https://lists.mydomain.com/](https://lists.mydomain.com/)  
> > > it redirects me to [https://lists.mydomain.com:8000/mailman/listinfo](https://lists.mydomain.com:8000/mailman/listinfo) which of  
> > > course fails.  
> > > Proxy settings for nginx front end: server

Same result. I believe I had tried it already. To make certain I wasn’t  
seeing a cached response I checked with curl:

curl -I [https://lists.mydomain.com](https://lists.mydomain.com)  
HTTP/1.1 301 Moved Permanently  
Server: nginx/1.9.14  
Date: Thu, 21 Apr 2016 14:34:27 GMT  
Content-Type: text/html  
Content-Length: 185  
Connection: keep-alive  
Location: [http://lists.mydomain.com:8000/mailman/listinfo](http://lists.mydomain.com:8000/mailman/listinfo)  
Strict-Transport-Security: max-age=31536000

So it’s actually redirecting to http. I have

fastcgi\_param HTTPS on;  
fastcgi\_param HTTP\_SCHEME https;

set on the backend server so this is puzzling.

–  
Jim O.

“Never argue with a fool, onlookers may not be able to tell the  
difference.” - Mark Twain

---

<div class="post-metadata">

**Author:** ![joviyach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@joviyach](https://www.ruby-forum.com/u/joviyach)\
**Post date:** [April 21, 2016, 4:52pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496/5 "2016-04-21T16:52:10Z")

</div>

On 21 Apr 2016, at 17:41, Jim O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > proxy\_redirect off;  
> > > > proxy\_set\_header Connection “”;  
> > > > Sorry, no.  
> > > > Date: Thu, 21 Apr 2016 14:34:27 GMT
> 
> set on the backend server so this is puzzling.

Then you need:

-proxy\_redirect [https://lists.mydomain.com:8000/](https://lists.mydomain.com:8000/) /;  
+proxy\_redirect [http://lists.mydomain.com:8000/](http://lists.mydomain.com:8000/) /;

The first parameter should be equal to the beginning  
of string in Location header. Also you can specify several  
proxy\_redirect directives.

–  
Igor S.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![joviyach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@joviyach](https://www.ruby-forum.com/u/joviyach)\
**Post date:** [April 21, 2016, 4:25pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496/6 "2016-04-21T16:25:52Z")

</div>

Hello,

On 4/21/16 10:14 AM, Igor S. wrote:

> > If I access [https://lists.mydomain.com/mailman/listinfo](https://lists.mydomain.com/mailman/listinfo) directly or any URL  
> > except the main one, it works as expected.  
> > location / {  
> > }
> > 
> > Backend server uses fastcgi for Python via fcgiwrap. Any help would be  
> > appreciated.
> 
> proxy\_redirect on;

Thanks, Igor. Now I am getting this error:

nginx: [emerg] invalid parameter “on” in  
/usr/local/etc/nginx/sites-enabled/lists.mydomain.com:67

–  
Jim O.

“Never argue with a fool, onlookers may not be able to tell the  
difference.” - Mark Twain

---

<div class="post-metadata">

**Author:** ![joviyach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@joviyach](https://www.ruby-forum.com/u/joviyach)\
**Post date:** [April 21, 2016, 5:04pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496/7 "2016-04-21T17:04:26Z")

</div>

Hello,

On 4/21/16 10:51 AM, Igor S. wrote:

> > > > > port\_in\_redirect off;  
> > > > > proxy\_set\_header X-Forwarded-Proto $scheme;  
> > > > > proxy\_redirect on;  
> > > > > HTTP/1.1 301 Moved Permanently  
> > > > > fastcgi\_param HTTPS on;  
> > > > > of string in Location header. Also you can specify several  
> > > > > proxy\_redirect directives.

That worked. Thank you, Igor! It’s good to see you on the English list.  
Reminds me of the old days of 0.6.x (OK, not as old as some, but it’s  
been awhile).

–  
Jim O.

“Never argue with a fool, onlookers may not be able to tell the  
difference.” - Mark Twain

---

<div class="post-metadata">

**Author:** ![joviyach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@joviyach](https://www.ruby-forum.com/u/joviyach)\
**Post date:** [April 21, 2016, 4:56pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496/8 "2016-04-21T16:56:15Z")

</div>

On Thu, Apr 21, 2016 at 10:41:24AM -0400, Jim O. wrote:

> On 4/21/16 10:17 AM, Igor S. wrote:
> 
> > > On 21 Apr 2016, at 17:09, Jim O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Hi there,

> > > > location / {  
> > > > proxy\_pass [http://10.0.250.37:8000](http://10.0.250.37:8000);  
> > > > proxy\_set\_header Host $host;

> > proxy\_redirect [https://lists.mydomain.com:8000/](https://lists.mydomain.com:8000/) /;
> 
> Same result. I believe I had tried it already. To make certain I  
> wasn’t seeing a cached response I checked with curl:
> 
> curl -I [https://lists.mydomain.com](https://lists.mydomain.com)

> Location: [http://lists.mydomain.com:8000/mailman/listinfo](http://lists.mydomain.com:8000/mailman/listinfo)

If that is the line that comes back from the proxy\_pass’ed server to  
nginx, then you want

proxy\_redirect [http://lists.mydomain.com:8000/](http://lists.mydomain.com:8000/) /;

(where the first argument to proxy\_redirect is the string that you want  
to replace with the second argument, allowing for scheme://host to be  
added later.)

If you can do without the “proxy\_set\_header Host” line, then you can  
possibly do without proxy\_redirect altogether (as in: use  
“proxy\_redirect  
default;” implicitly).

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![joviyach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@joviyach](https://www.ruby-forum.com/u/joviyach)\
**Post date:** [April 21, 2016, 5:07pm UTC](https://www.ruby-forum.com/t/port-redirect-in-url/244496/9 "2016-04-21T17:07:22Z")

</div>

Hello,

On 4/21/16 10:55 AM, Francis D. wrote:

> > > proxy\_redirect [https://lists.mydomain.com:8000/](https://lists.mydomain.com:8000/) /;
> 
> f

Thanks, Francis. That did work.

–  
Jim O.

“Never argue with a fool, onlookers may not be able to tell the  
difference.” - Mark Twain
