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'
        image: nginx:latest
        container_name: "proxy"
        restart: always
        - blah:/etc/nginx
        - 80:80
        - 443:443

        image: "webservice:latest"
        container_name: "webservice"
        restart: always
        - 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;


Related Questions

Sponsored Content

38 Answered Questions

[SOLVED] Copying files from host to Docker container

50 Answered Questions

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

  • 2013-06-17 22:10:22
  • Murali Allada
  • 1114646 View
  • 1241 Score
  • 50 Answer
  • Tags:   docker

22 Answered Questions

16 Answered Questions

[SOLVED] Copying files from Docker container to host

57 Answered Questions

[SOLVED] How to remove old Docker containers

  • 2013-06-21 13:41:42
  • qkrijger
  • 695555 View
  • 1171 Score
  • 57 Answer
  • Tags:   docker

27 Answered Questions

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

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

58 Answered Questions

[SOLVED] How do I redirect to another webpage?

2 Answered Questions

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

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

Sponsored Content