# Nginx reverse proxy odd 301 redirect

**URL:** <https://www.ruby-forum.com/t/nginx-reverse-proxy-odd-301-redirect/246367>\
**Category:** NGINX\
**Created:** [October 6, 2013, 12:17am UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-odd-301-redirect/246367 "2013-10-06T00:17:09Z")\
**Posts on this page:** 3\
**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:** [October 6, 2013, 12:17am UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-odd-301-redirect/246367/1 "2013-10-06T00:17:09Z")

</div>

Hi,

I have latest nginx which I am using as a reverse proxy for an  
application  
of mine running on apache on another server. The nginx config is like  
this:  
upstream upstreamname {  
server ip:port;  
}

…

location / {  
proxy\_pass [http://upstreamname](http://upstreamname);  
proxy\_redirect off;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
}

…

So my problem appears with a certain change password script new users  
must  
use when they login first time after their username was created.

If I use apache directly then the change password script works fine. If  
I do  
it using nginx as reverse proxy then at the point where I press the  
submit  
button and the POST should happen, I can’t see the POST hitting the  
apache  
backend(no entry in access log) but I can see an odd 301 redirect with  
the  
POST request to the script in the nginx access log.

Any idea of what could be the cause? Anything I am doing wrong?

Please help  
Thanks

Posted at Nginx Forum:

> **[nginx reverse proxy odd 301 redirect](https://forum.nginx.org/read.php?2,243458,243458#msg-243458)**
>
> Hi, I have latest nginx which I am using as a reverse proxy for an application of mine running on apache on another server. The nginx config is like this: upstream upstreamname { server ip:port; } .... location / { pr

---

<div class="post-metadata">

**Author:** ![izghitu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/cc9497/32.png) [@izghitu](https://www.ruby-forum.com/u/izghitu)\
**Post date:** [October 6, 2013, 11:32am UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-odd-301-redirect/246367/2 "2013-10-06T11:32:34Z")

</div>

Hello!

On Sat, Oct 05, 2013 at 06:16:24PM -0400, izghitu wrote:

> location / {  
> use when they login first time after their username was created.
> 
> If I use apache directly then the change password script works fine. If I do  
> it using nginx as reverse proxy then at the point where I press the submit  
> button and the POST should happen, I can’t see the POST hitting the apache  
> backend(no entry in access log) but I can see an odd 301 redirect with the  
> POST request to the script in the nginx access log.
> 
> Any idea of what could be the cause? Anything I am doing wrong?

As long as the above configuration is a _full_ configuration of a  
server{} block, there shouldn’t be any 301 redirects returned  
directly by nginx. Most likely what you observe is a result of  
incorrect configuration of server{} blocks and/or wrong hostname  
used in request.

If it’s not a full configuration - there isn’t enough information  
to provide any help. See here for some tips what can be useful:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![izghitu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/cc9497/32.png) [@izghitu](https://www.ruby-forum.com/u/izghitu)\
**Post date:** [October 7, 2013, 12:04am UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-odd-301-redirect/246367/3 "2013-10-07T00:04:34Z")

</div>

Hi,

The problem was hostname related.

Thanks for your help

> incorrect configuration of server{} blocks and/or wrong hostname  
> used in request.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,243458,243466#msg-243466](http://forum.nginx.org/read.php?2,243458,243466#msg-243466)
