By Alan Parry


2019-01-16 22:16:33 8 Comments

I'm having a particularly odd behaviour with my docker-compose and nginx setup. I am trying to have nginx proxy_pass requests to a backend web service. The web service is Spring Boot, but I don't believe that's relevant. My web service will issue a 302 redirect to users who are not authenticated, sending them to a /login page. This all seems to work as expected except for an indeterminate period of time when I bring the docker-compose up. Early requests to the service which result in 302 responses result in timeouts, whilst requests direct to the /login page return as expected immediately. After an indeterminate period of time, usually minutes, something seems to stabilise and everything works as expected. I've verified the behaviour using chrome from a client machine and curl directly on the host running the compose. I believe the 302 responses are somehow getting dropped but I'm not sure.

Can anyone spot a problem?

    version: '3.5'
    services:
      proxy:
        image: nginx:latest
        container_name: "proxy"
        restart: always
        volumes:
        - blah:/etc/nginx
        ports:
        - 80:80
        - 443:443

      webservice:
        image: "webservice:latest"
        container_name: "webservice"
        restart: always
        ports:
        - 8080:8080

Nginx Config:

    worker_processes auto;

    events { }

    http {

      server {

        listen 80 default_server;
        listen 443 default_server ssl;

        ssl_certificate /etc/nginx/cert;
        ssl_certificate_key /etc/nginx/key;

        if ($scheme = http) {
          return 301 https://$host:443$request_uri;
        }

        gzip on;
        gzip_types text/plain application/xml application/json     application/javascript;

        location / {
           proxy_http_version 1.1;
           proxy_pass http://webservice:8080/;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           proxy_set_header Host                 $host:$server_port;
           proxy_set_header X-Real-IP            $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $scheme;
           proxy_set_header X-Forwarded-Port $server_port;
           access_log /etc/nginx/log/access.log combined;
           error_log /etc/nginx/log/error.log warn;
        }
      }
    }

0 comments

Related Questions

Sponsored Content

53 Answered Questions

[SOLVED] How to remove old Docker containers

  • 2013-06-21 13:41:42
  • qkrijger
  • 653656 View
  • 1066 Score
  • 53 Answer
  • Tags:   docker

27 Answered Questions

[SOLVED] How do I make a redirect in PHP?

  • 2009-04-20 14:13:22
  • Sam
  • 2413910 View
  • 1086 Score
  • 27 Answer
  • Tags:   php redirect

2 Answered Questions

[SOLVED] Keycloak Redirect url with nginx is going to http rather than https

  • 2018-04-03 12:02:15
  • Atulya Nair
  • 750 View
  • 2 Score
  • 2 Answer
  • Tags:   nginx jboss

42 Answered Questions

[SOLVED] How to get a Docker container's IP address from the host?

  • 2013-06-17 22:10:22
  • Murali Allada
  • 835392 View
  • 964 Score
  • 42 Answer
  • Tags:   docker

58 Answered Questions

[SOLVED] How do I redirect to another webpage?

17 Answered Questions

34 Answered Questions

[SOLVED] Copying files from host to Docker container

10 Answered Questions

[SOLVED] Should I use Vagrant or Docker for creating an isolated environment?

  • 2013-05-20 10:05:25
  • murtaza52
  • 378329 View
  • 1954 Score
  • 10 Answer
  • Tags:   vagrant docker

19 Answered Questions

[SOLVED] How is Docker different from a virtual machine?

2 Answered Questions

[SOLVED] Express - req.ip returns 127.0.0.1

Sponsored Content