nginx – insecure http server is redirecting wrongly to an https server

I’ve got a small website that I’m running on docker, with the ‘dev’ version on port 9090 and the ‘master’ version running on port 8080.

I’m using Nginx on the host (not running on docker) to handle the proxying on port 80/443 for requests coming from the internet.

  • BadRequestException: HTTP 400 Bad Request when try to start a docker container with spotify docker-client
  • Dockerizing PostgreSQL - psql Connection refused
  • Ubuntu docker image doesn't contain any /dev/sdX block devices?
  • networking options for a docker image in minikube
  • Can i use watch in nodemon or pm2 in docker with file in shard drive?
  • Using host filesystem as a read-only base in docker
  • The port 80/443 proxying works perfectly. No problems there.

    Problem: When try and create a server running on port 90 (to show the dev version of the site) which is intended to be insecure, this seems to attempt a redirect back to the SSL version of the site, which is confirmed by the browser redirecting to SSL, and i get an error on the page : ERR_SSL_PROTOCOL_ERROR

    If i comment out the server running on port 80, this problem goes away, but then i lose my port 80 redirects on the live/master site.

    Can anyone see what might be the problem in how i’m setting up the config – thanks! Config below :

    server {
    listen       443 ssl;
        server_name  xxxxxxxxxxxxx.co.uk www.xxxxxxxxxxxxx.co.uk;
        {some ssl config here}
        add_header Strict-Transport-Security max-age=15768000;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
            auth_basic "Restricted Content";
            auth_basic_user_file /etc/nginx/.htpasswd;
        proxy_pass http://localhost:8080;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    
    server {
        listen 80;
        server_name xxxxxxxxxxxxx.co.uk www.xxxxxxxxxxxxx.co.uk;
        return 301 https://$host$request_uri;
    }
    
    server {
    listen 90;
    server_name xxxxxxxxxxxxx.co.uk www.xxxxxxxxxxxxx.co.uk;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
            auth_basic "Restricted Content";
            auth_basic_user_file /etc/nginx/.htpasswd;
        proxy_pass http://localhost:9090;
        proxy_redirect off;
        }
    }
    

  • Docker - connection between containers in different hosts within the same overlay network
  • Docker container doesn't start, showing as 'Exited n seconds ago'
  • Why log settings don't work without setting --log-driver option while service creation?
  • How do I serve Kinto via https from a docker container?
  • With commited DOCKER container, the new container failed to run TOMCAT9 in Raspberry PI 3
  • Laravel: TokenMismatchException
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.