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

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 I can run:

curl -v

and I get the response I am expecting.

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

 curl -v

I get the following redirect:

  • Trying…
  • Connected to ( port 80 (#0)

GET /registrations/ HTTP/1.1
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
< Expires: Fri, 25 Mar 2016 23:57:19 GMT
< Cache-Control: no-cache

301 Moved Permanently

301 Moved Permanently

nginx * Connection #0 to host left intact

Any help would be appreciated,

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


Posted at Nginx Forum: