# How to preserve nginx url from being redirected (302) from back end tomcat server?

**URL:** <https://www.ruby-forum.com/t/how-to-preserve-nginx-url-from-being-redirected-302-from-back-end-tomcat-server/243627>\
**Category:** NGINX\
**Created:** [December 12, 2015, 8:46pm UTC](https://www.ruby-forum.com/t/how-to-preserve-nginx-url-from-being-redirected-302-from-back-end-tomcat-server/243627 "2015-12-12T20:46:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 12, 2015, 8:46pm UTC](https://www.ruby-forum.com/t/how-to-preserve-nginx-url-from-being-redirected-302-from-back-end-tomcat-server/243627/1 "2015-12-12T20:46:01Z")

</div>

Newby working for a couple weeks. Any guidance really appreciated.

Nginx is not preserving the url from redirected backend tomcat server.

Nginx url: [//develop-application.example.com/](https://develop-application.example.com/)

Backend tomcat url: [//application.example.com/](https://application.example.com/)

tomcat redirects url: [//application.example.com/application](https://application.example.com/application)

I want the client browser url to always remain  
[https://develop-application.example.com/application](https://develop-application.example.com/application) no matter what  
returns  
from tomcat.

Config:

server {  
listen 443 proxy\_protocol;  
set\_real\_ip\_from 0.0.0.0/0;  
real\_ip\_header proxy\_protocol;  
access\_log  
/var/log/nginx/develop-application.example.com.https.access.log elb\_log;

```
    server_name develop-application.example.com;

    ssl on;
    ssl_certificate /etc/nginx/ssl/example.com.crt.chained;
    ssl_certificate_key /etc/nginx/ssl/example.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;

    location / {

        proxy_pass https://application.example.com/;
        proxy_redirect https://application.example.com/

```

[https://develop-application.example.com/](https://develop-application.example.com/);  
proxy\_set\_header Host $http\_host;

```
        }

```

}

Posted at Nginx Forum:

> **[How to preserve nginx url from being redirected (302) from back end tomcat...](https://forum.nginx.org/read.php?2,263441,263441#msg-263441)**
>
> Newby working for a couple weeks. Any guidance really appreciated. Nginx is not preserving the url from redirected backend tomcat server. Nginx url: //develop-application.example.com/ Backend tomcat url: //application.example.com/ tomcat r

---

<div class="post-metadata">

**Author:** ![pjudt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e0b2c6/32.png) [@pjudt](https://www.ruby-forum.com/u/pjudt)\
**Post date:** [December 12, 2015, 8:57pm UTC](https://www.ruby-forum.com/t/how-to-preserve-nginx-url-from-being-redirected-302-from-back-end-tomcat-server/243627/2 "2015-12-12T20:57:07Z")

</div>

Your proxy\_redirect rule does not match what is returned from your  
backend.  
Remove the “https” prefix maybe?  
Since you want to redirect to the current hostname, you could also use  
the  
$host variable.  
Then, since your server block is configured to only listen on SSL port,  
you  
could also take advantage of the $scheme variable.

## proxy\_redirect [//application.example.com/](https://application.example.com/) $scheme://$host/;

_B. R._
