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 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
< 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

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

Posted at Nginx Forum:
https://forum.nginx.org/read.php?2,265660,265664#msg-265664

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs