# Proxy\_redirect not working with https, redirect to http instead of https

**URL:** <https://www.ruby-forum.com/t/proxy-redirect-not-working-with-https-redirect-to-http-instead-of-https/120166>\
**Category:** NGINX\
**Created:** [November 14, 2007, 1:02pm UTC](https://www.ruby-forum.com/t/proxy-redirect-not-working-with-https-redirect-to-http-instead-of-https/120166 "2007-11-14T13:02:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alain\_Spineux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@Alain\_Spineux](https://www.ruby-forum.com/u/Alain_Spineux)\
**Post date:** [November 14, 2007, 1:02pm UTC](https://www.ruby-forum.com/t/proxy-redirect-not-working-with-https-redirect-to-http-instead-of-https/120166/1 "2007-11-14T13:02:38Z")

</div>

Hi

I have a turbogears application running on [http://localhost:8080/eg/](http://localhost:8080/eg/)  
I use nginx to provide an HTTPS access.  
Everything works except when my apps make redirection, the url is well  
rewritten  
but the http is not rewrittent into https, ginving  
[http://eg01.emailgency.loc/eg/addr/](http://eg01.emailgency.loc/eg/addr/)  
instead of  
[https://eg01.emailgency.loc/eg/addr/](https://eg01.emailgency.loc/eg/addr/)

I installed nginx 6.16 to test last “mail” features,  
but expect to downgrade to stable version.

```
server {
    listen 443;
    server_name eg01.emailgency.loc;
    ssl on;
    ssl_certificate /kolab/etc/kolab/cert.pem;
    ssl_certificate_key /kolab/etc/kolab/key.pem;

    location /eg/ {
        proxy_pass http://localhost:8080/eg/;
        proxy_redirect default;
        #proxy_redirect http://localhost:8080/eg/

```

[https://eg01.emailgency.loc/eg/](https://eg01.emailgency.loc/eg/); # don’t work !  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
}

```
}

```

If I add this

```
server {
    listen 80;
    rewrite ^(.*) https://eg01.emailgency.loc$1 redirect;
}

```

then its works but with one more redirection

Any idea ?

Regards.

---

<div class="post-metadata">

**Author:** ![Alain\_Spineux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@Alain\_Spineux](https://www.ruby-forum.com/u/Alain_Spineux)\
**Post date:** [November 14, 2007, 1:09pm UTC](https://www.ruby-forum.com/t/proxy-redirect-not-working-with-https-redirect-to-http-instead-of-https/120166/2 "2007-11-14T13:09:05Z")

</div>

On Wed, Nov 14, 2007 at 12:54:20PM +0100, Alain Spineux wrote:

> ```
> #proxy_redirect http://localhost:8080/eg/
> listen 80;
> rewrite ^(.*) https://eg01.emailgency.loc$1 redirect;
> }
> 
> ```
> 
> then its works but with one more redirection

Try

- 

```
        proxy_redirect default;

```

- 

```
        proxy_redirect http://eg01.emailgency.loc/ /;
```

---

<div class="post-metadata">

**Author:** ![Alain\_Spineux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@Alain\_Spineux](https://www.ruby-forum.com/u/Alain_Spineux)\
**Post date:** [November 14, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/proxy-redirect-not-working-with-https-redirect-to-http-instead-of-https/120166/3 "2007-11-14T20:48:18Z")

</div>

On Nov 14, 2007 1:03 PM, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > location /eg/ {
> > 
> > ```
> > 
> > If I add this
> 
> - 
> 
> ```
> proxy_redirect default;
> 
> ```
> 
> - 
> 
> ```
> proxy_redirect http://eg01.emailgency.loc/ /;
> 
> ```

Right, it works tanks Igor.

For the other (and me later :-), here is the explanations :

When I request :

[https://eg01.emailgency.loc/eg/welcome/](https://eg01.emailgency.loc/eg/welcome/)  
My browser build the reques as :

GET /eg/welcome/ HTTPS  
Host: eg01.emailgency.loc

Nginx replace /eg/ by /eg/ 🙂  
and send the identical request using a different protocol “http” to a  
different port, but this port is not  
updated in “Host:” field because of

proxy\_set\_header Host $host;

The request become :

GET /eg/welcome/ HTTP (here it lost the S)  
Host: eg01.emailgency.loc

My application when building a “redirect” use Host field and return

Location: [http://eg01.emailgency.loc/eg/login/](http://eg01.emailgency.loc/eg/login/)

then  
proxy\_redirect [http://eg01.emailgency.loc/](http://eg01.emailgency.loc/) /;

just adjust the protocol ‘https’ the default host  
‘eg01.emailgency.loc’ and return

Location: [httpS://eg01.emailgency.loc/eg/login/](httpS://eg01.emailgency.loc/eg/login/)

BUT if I want to use

```
         proxy_redirect default;

```

I must remove

```
        proxy_set_header Host $host;

```

or replace it by

```
        proxy_set_header Host localhost:8080;

```

Then the “proxy\_redirect default” match and works.

Thanks

---

<div class="post-metadata">

**Author:** ![Alain\_Spineux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@Alain\_Spineux](https://www.ruby-forum.com/u/Alain_Spineux)\
**Post date:** [November 14, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/proxy-redirect-not-working-with-https-redirect-to-http-instead-of-https/120166/4 "2007-11-14T20:48:53Z")

</div>

On Wed, Nov 14, 2007 at 08:32:17PM +0100, Alain Spineux wrote:

> > > [https://eg01.emailgency.loc/eg/addr/](https://eg01.emailgency.loc/eg/addr/)
> 
> My browser build the reques as :
> 
> ```
> proxy_redirect http://eg01.emailgency.loc/ /;
> 
> ```
> 
> I must remove
> 
> ```
> proxy_set_header Host $host;
> 
> ```
> 
> or replace it by
> 
> ```
> proxy_set_header Host localhost:8080;
> 
> ```
> 
> Then the “proxy\_redirect default” match and works.

You are right. Some comments:

1. to not replace /eg/ by /eg/, you may omit URI part:

- 

```
     proxy_pass http://localhost:8080/eg/;

```

- 

```
     proxy_pass http://localhost:8080;

```

1. there is no HTTPS in browser request line:

---

<div class="post-metadata">

**Author:** ![Alain\_Spineux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@Alain\_Spineux](https://www.ruby-forum.com/u/Alain_Spineux)\
**Post date:** [November 15, 2007, 12:23am UTC](https://www.ruby-forum.com/t/proxy-redirect-not-working-with-https-redirect-to-http-instead-of-https/120166/5 "2007-11-15T00:23:16Z")

</div>

On Nov 14, 2007 8:42 PM, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > but the http is not rewrittent into https, ginving  
> > > > ssl on;  
> > > > }  
> > > > then its works but with one more redirection  
> > > > When I request :  
> > > > updated in “Host:” field because of  
> > > > Location: [http://eg01.emailgency.loc/eg/login/](http://eg01.emailgency.loc/eg/login/)
> > 
> > Then the “proxy\_redirect default” match and works.
> 
> You are right. Some comments:
> 
> 1. to not replace /eg/ by /eg/, you may omit URI part:
> 
> - 
> 
> ```
> proxy_pass http://localhost:8080/eg/;
> 
> ```
> 
> - 
> 
> ```
> proxy_pass http://localhost:8080;
> 
> ```

Yes, without the “/”

> 1. there is no HTTPS in browser request line:

hummm

GET /eg/welcome/ HTTP/1.1

🙂

Thanks for the great soft and your help.
