# Proxy problem

**URL:** <https://www.ruby-forum.com/t/proxy-problem/189769>\
**Category:** NGINX\
**Created:** [June 7, 2010, 12:28pm UTC](https://www.ruby-forum.com/t/proxy-problem/189769 "2010-06-07T12:28:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 7, 2010, 12:28pm UTC](https://www.ruby-forum.com/t/proxy-problem/189769/1 "2010-06-07T12:28:39Z")

</div>

Hi,

We had nginx/0.6.33 and we migrated to nginx/0.7.65.  
We use nginx as frontend for our webmail, that it is in another machine  
(nginx+apache).  
But in the new scenario, squirrelmail loss session (I guess) and force  
me  
to relogin again.  
Compile options and config files are the same (except for  
proxy\_redirect)

This is:  
location / {  
proxy\_pass [http://mailmachine:80](http://mailmachine:80);  
proxy\_redirect default; // for nginx 0.7.65  
proxy\_redirect on; // for nginx 0.6.33

```
            proxy_set_header Host $host;
            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 https;  
client\_max\_body\_size 10m;  
client\_body\_buffer\_size 128k;  
proxy\_connect\_timeout 90;  
proxy\_send\_timeout 90;  
proxy\_read\_timeout 90;  
proxy\_buffering on;  
proxy\_buffers 8 8k;  
proxy\_buffer\_size 8k;  
proxy\_busy\_buffers\_size 16k;  
proxy\_temp\_file\_write\_size 1024m;  
}

What changes are in version 0.7 that I should consider?

Thank you in advance,  
Lucas

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 7, 2010, 4:32pm UTC](https://www.ruby-forum.com/t/proxy-problem/189769/2 "2010-06-07T16:32:46Z")

</div>

Hi,

Sorry, it was because rewrite was doing its jobs unexpected.  
We solved with this code:

```
    location / {
            rewrite ^(.*) https://webmail.landm.net$1 permanent;
    }

```

Regards,  
Lucas

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 7, 2010, 4:46pm UTC](https://www.ruby-forum.com/t/proxy-problem/189769/3 "2010-06-07T16:46:50Z")

</div>

On Mon, Jun 07, 2010 at 04:33:18PM +0200, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> Sorry, it was because rewrite was doing its jobs unexpected.  
> We solved with this code:
> 
> ```
> location / {
> rewrite ^(.*) https://webmail.landm.net$1 permanent;
> }
> 
> ```

I do not see how this rewrite may resolve the issue.  
BTW,

```
     proxy_redirect on; // for nginx 0.6.33

```

is wrong for 0.6.x as well as 0.7.x.

> > Compile options and config files are the same (except for proxy\_redirect)  
> > $proxy\_add\_x\_forwarded\_for;  
> > proxy\_temp\_file\_write\_size 1024m;  
> > nginx mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 7, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/proxy-problem/189769/4 "2010-06-07T16:54:26Z")

</div>

Hi Igor,

> > We solved with this code:
> > 
> > ```
> > location / {
> > rewrite ^(.*) https://server$1 permanent;
> > }
> > 
> > ```
> 
> I do not see how this rewrite may resolve the issue.

The problem was an internal redirection from squirrelmail. Doing some  
operation, it redirects to [http://server/](http://server/) [no SSL] and the previous  
code:

```
     location / {
             rewrite ^(.*) https://server/ last;
     }

```

lost the session.

Regards,  
Lucas

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 7, 2010, 5:03pm UTC](https://www.ruby-forum.com/t/proxy-problem/189769/5 "2010-06-07T17:03:14Z")

</div>

On Mon, Jun 07, 2010 at 04:55:04PM +0200, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem was an internal redirection from squirrelmail. Doing some  
> operation, it redirects to [http://server/](http://server/) [no SSL] and the previous  
> code:
> 
> ```
> location / {
> rewrite ^(.*) https://server/ last;
> }
> 
> ```
> 
> lost the session.

You may fix this using proper proxy\_redirect’s, e.g.:

```
 location / {
     proxy_pass http://mailmachine:80;
     proxy_redirect http://server/ https://server/;

```

> > > Regards,
> > > 
> > > > to relogin again.  
> > > > proxy\_set\_header X-Real-IP $remote\_addr;  
> > > > proxy\_buffer\_size 8k;
> > > 
> > > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 7, 2010, 5:19pm UTC](https://www.ruby-forum.com/t/proxy-problem/189769/6 "2010-06-07T17:19:02Z")

</div>

On 07.06.2010 17:55, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem was an internal redirection from squirrelmail. Doing some  
> operation, it redirects to [http://server/](http://server/) [no SSL]

you need

SetEnv HTTPS on

in apache config for squirrelmail virtual host.

or more advanced code in nginx and apache config:

========================================================================

# nginx config:

proxy\_set\_header X-Nginx-Scheme $scheme;

# nginx variable $scheme will be ‘http’ or ‘https’.

# apache config:

SetEnvIf X-Nginx-Scheme “^https$” HTTPS=on

# Apache environment variable HTTPS will be ‘on’ or not defined.

# PHP code:

$scheme = getenv(‘HTTPS’) && strtolower(getenv(‘HTTPS’)) != ‘off’  
? ‘https’  
: ‘http’;

# PHP variable $scheme will be ‘http’ or ‘https’.

========================================================================

check for HTTPS environment variable already implemented inside  
squirrelmail: function is\_ssl\_secured\_connection() in  
functions\global.php.

P.S. also you need something like

proxy\_redirect [https://mail.example.com:80/](https://mail.example.com:80/) /;

in nginx config, because squirrelmail can make redirects  
to 80 port instead of default for HTTPS, 443 port.

–  
Best regards,  
Gena
