# Why is nginx returning a 301 redirect in my reverse-proxy to a REST service?

**URL:** <https://www.ruby-forum.com/t/why-is-nginx-returning-a-301-redirect-in-my-reverse-proxy-to-a-rest-service/244352>\
**Category:** NGINX\
**Created:** [March 26, 2016, 1:01am UTC](https://www.ruby-forum.com/t/why-is-nginx-returning-a-301-redirect-in-my-reverse-proxy-to-a-rest-service/244352 "2016-03-26T01:01:21Z")\
**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:** [March 26, 2016, 1:01am UTC](https://www.ruby-forum.com/t/why-is-nginx-returning-a-301-redirect-in-my-reverse-proxy-to-a-rest-service/244352/1 "2016-03-26T01:01:21Z")

</div>

I have a REST service with an endpoint ‘registrations’ running in a  
Docker container and it maps port 5000 to port 5001 on the Docker host.

My /etc/nginx/conf.d/default.conf contains:

upstream registration-api {  
server registration:5001 ;  
}

server {

```
listen 80;
server_name "";

# Registration Service

location /registrations/ {
    proxy_pass http://registration_api/;
}

```

}

—

I’m using Docker, so ‘registration-api’ is defined in the nginx  
container’s /etc/hosts file.

My Docker host is running at 192.168.99.100. I can run:

```
curl -v http://192.168.99.100:5001/registrations/

```

and I get the response I am expecting.

However, when I try to go through nginx reverse-proxy with the command:

```
 curl -v http://192.168.99.100/registrations/

```

I get the following redirect:

- Trying 192.168.99.100…
- Connected to 192.168.99.100 (192.168.99.100) port 80 (#0)

> GET /registrations/ HTTP/1.1  
> Host: 192.168.99.100  
> User-Agent: curl/7.43.0  
> Accept: _/_

\< HTTP/1.1 301 Moved Permanently  
\< Server: nginx/1.9.12  
\< Date: Fri, 25 Mar 2016 23:57:20 GMT  
\< Content-Type: text/html  
\< Transfer-Encoding: chunked  
\< Connection: keep-alive  
\< Location: [http://localhost](http://localhost)  
\< Expires: Fri, 25 Mar 2016 23:57:19 GMT  
\< Cache-Control: no-cache  
\<

301 Moved Permanently
# 301 Moved Permanently

* * *
nginx \* Connection #0 to host 192.168.99.100 left intact

Any help would be appreciated,  
Thanks,  
Rowlad

---

<div class="post-metadata">

**Author:** ![Rowland\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a5b964/32.png) [@Rowland\_Smith](https://www.ruby-forum.com/u/Rowland_Smith)\
**Post date:** [March 26, 2016, 4:10am UTC](https://www.ruby-forum.com/t/why-is-nginx-returning-a-301-redirect-in-my-reverse-proxy-to-a-rest-service/244352/2 "2016-03-26T04:10:02Z")

</div>

Hi  
I’m pretty new in NginX but the directives suggest you add  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
to your config

[http://nginx.org/en/docs/http/ngx\_http\_proxy\_module.html](http://nginx.org/en/docs/http/ngx_http_proxy_module.html)

Posted at Nginx Forum:

> **[Re: Why is nginx returning a 301 redirect in my reverse-proxy to a REST service?](https://forum.nginx.org/read.php?2,265660,265664#msg-265664)**
>
> I have a REST service with an endpoint ‘registrations' running in a Docker container and it maps port 5000 to port 5001 on the Docker host. My /etc/nginx/conf.d/default.conf contains: upstream registration-api { server registration:5001 ; } se
