# Help noob with redirection

**URL:** <https://www.ruby-forum.com/t/help-noob-with-redirection/189881>\
**Category:** NGINX\
**Created:** [June 9, 2010, 1:51pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881 "2010-06-09T13:51:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [June 9, 2010, 1:51pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881/1 "2010-06-09T13:51:31Z")

</div>

Hi,

I have installed my first NGINX proxy and having a real problem with  
redirects. As a example I have published externally:

[https://pm.domain.com/client1](https://pm.domain.com/client1)  
[https://pm.domain.com/client2](https://pm.domain.com/client2)

which should then redirect to the clustered back-end servers which are  
named [pm01.domain.com](http://pm01.domain.com) etc. What is happening is that when I try in the  
URL it comes back with the correct content but the URL in the browser  
shows the back-end server named; so how do I get it to be the externally  
published name ?

## Config

server {  
listen 443;  
server\_name [pm.domain.com](http://pm.domain.com);

```
ssl on;
ssl_certificate /etc/pki/tls/certs/proxy01c.pem;
ssl_certificate_key /etc/pki/tls/private/proxy01k.pem;

ssl_session_timeout 5m;

ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers 

```

ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;  
ssl\_prefer\_server\_ciphers on;

```
access_log /var/log/nginx/pm.domain.com-access.log main;
error_log /var/log/nginx/pm.domain.com-error.log info;

gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css 

```

application/x-javascript text/xml application/xml application/xml+rss  
text/javascript;

```
upstream projectmanagement {
   server pm01.domain.com:443;
   server pm02.domain.com:443;
}

location / {
    proxy_pass https://projectmanagement;
    proxy_redirect on;
    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;
}

```

}

## Look forward to your help.

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [June 9, 2010, 2:03pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881/2 "2010-06-09T14:03:13Z")

</div>

On Wed, Jun 09, 2010 at 12:50:30PM +0100, --[UxBoD]-- wrote:

> * * *
> 
> ```
> ssl_protocols SSLv2 SSLv3 TLSv1;
> gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
> 
> upstream projectmanagement {
> server pm01.domain.com:443;
> server pm02.domain.com:443;
> }
> 
> location / {
> proxy_pass https://projectmanagement;
> proxy_redirect on;
> 
> ```

- 

```
    proxy_redirect on;

```

- 

```
    proxy_redirect default;

```

> ```
> 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;
> }
> 
> ```
> 
> }

–  
Igor S.

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

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [June 9, 2010, 2:06pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881/3 "2010-06-09T14:06:44Z")

</div>

----- Original Message -----

> > which should then redirect to the clustered back-end servers which  
> > ssl on;  
> > access\_log /var/log/nginx/pm.domain.com-access.log main;  
> > upstream projectmanagement {
> 
> > ```
> > 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;
> > }
> > 
> > ```
> > 
> > }

Igor,

## I have switched it from on too default but after restarting NGINX I get the same result ?

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [June 9, 2010, 2:20pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881/4 "2010-06-09T14:20:12Z")

</div>

----- Original Message -----

> > > > ```
> > > > gzip_comp_level 2;
> > > > location / {
> > > > 
> > > > ```
> 
> Sorry, try the following proxy\_redirects:
> 
> proxy\_redirect [https://pm01.domain.com/](https://pm01.domain.com/) /;  
> proxy\_redirect [https://pm02.domain.com/](https://pm02.domain.com/) /;

## Igor, that works now using the above syntax 🙂 A question though is there anyway to tell NGINX to redirect based on the proxied hostname ? If we had pm01 … 100 then I would need to add 100 proxy\_redirect statements or can it be done with a clever single line ?

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [June 9, 2010, 2:27pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881/5 "2010-06-09T14:27:13Z")

</div>

On Wed, Jun 09, 2010 at 01:19:00PM +0100, --[UxBoD]-- wrote:

> > proxy\_redirect [https://pm01.domain.com/](https://pm01.domain.com/) /;  
> > proxy\_redirect [https://pm02.domain.com/](https://pm02.domain.com/) /;
> 
> Igor, that works now using the above syntax 🙂 A question though is there anyway to tell NGINX to redirect based on the proxied hostname ? If we had pm01 … 100 then I would need to add 100 proxy\_redirect statements or can it be done with a clever single line ?

Currently nginx does not support variables in the first parameter,  
so you have to add 100 proxy\_redirect statements.

The other way is to configure backends to use single name as main server  
name  
to use it in redirects.

–  
Igor S.

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

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [June 9, 2010, 2:10pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881/6 "2010-06-09T14:10:50Z")

</div>

On Wed, Jun 09, 2010 at 01:05:56PM +0100, --[UxBoD]-- wrote:

> > > 
> > 
> > - proxy\_redirect default;
> 
> Igor,
> 
> I have switched it from on too default but after restarting NGINX I get the same result ?

Sorry, try the following proxy\_redirects:

```
 proxy_redirect https://pm01.domain.com/ /;
 proxy_redirect https://pm02.domain.com/ /;

```

–  
Igor S.

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

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [June 9, 2010, 2:31pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881/7 "2010-06-09T14:31:55Z")

</div>

----- Original Message -----

> Currently nginx does not support variables in the first parameter,  
> so you have to add 100 proxy\_redirect statements.
> 
> The other way is to configure backends to use single name as main  
> server name  
> to use it in redirects.

## Sorry Igor, having a mind blank! Do you mean by using DNS eg. [pm.domain.com](http://pm.domain.com) IN A 1.2.3.4 IN A 5.6.7.8

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [June 9, 2010, 2:34pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881/8 "2010-06-09T14:34:15Z")

</div>

On Wed, Jun 09, 2010 at 01:30:47PM +0100, --[UxBoD]-- wrote:

> > > statements or can it be done with a clever single line ?  
> > > IN A 5.6.7.8  
> > > Not exactly this.  
> > > If you use Apache you should set  
> > > ServerName [pm.domain.com](http://pm.domain.com)  
> > > on every instance.

–  
Igor S.

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

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [June 9, 2010, 2:36pm UTC](https://www.ruby-forum.com/t/help-noob-with-redirection/189881/9 "2010-06-09T14:36:01Z")

</div>

----- Original Message -----

> > > > is there anyway to tell NGINX to redirect based on the proxied
> 
> on every instance.

## Ah, the lightbulb has been switched on 🙂 Thank you very much for your detailed responsse and help.

Thanks, Phil
