1

I have deployed the flask socketio application in docker. But when I move it to ssl secured domain (from http to https) My socket connection started to throw that error "Error during WebSocket handshake: Unexpected response code: 400" I have no idea how to fix it.

My docker-compose yml

version: '3'
services:

  rirlit-chat-server:
    build:
      context: ./docker/rirlit-chat-server
      dockerfile: Dockerfile
      args:
        git_ssh_key_path: /root/.ssh/id_rsa
        git_host: gitlab.com
        git_branch: dev
    container_name: rirlit-chat-server
    restart: always
    tty: true
    expose:
      - "7000"
    networks:
      - rirlit-network

  rirlit-nginx:
    build:
      context: ./docker/rirlit-nginx
      dockerfile: Dockerfile
      args:
        git_ssh_key_path: /root/.ssh/id_rsa
        git_host: gitlab.com
        git_branch: dev
    container_name: rirlit-nginx
    image: nginx:stable
    restart: always
    tty: true
    ports:
      - "80:80"
      - "443:443"
   networks:
      - rirlit-network

# Networks and volumes definition
networks:
  lirlit-network:
    driver: bridge

Here is my nginx default

server {

    root /var/www/html;

    index index.html index.php index.htm index.nginx-debian.html;

    server_name lirlit.com;

    location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;

                root /var/www/lirlit-front-prod;
    }


  location /lirlit/api {
          rewrite ^/api/?(.*)$ /$1 break;
          include proxy_params;
          proxy_pass http://lirlit-chat-server:7000;
  }

  location /socket.io {
        include proxy_params;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass http://lirlit-chat-server:7000/socket.io;
  }


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/lirlit.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/lirlit.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = lirlit.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    listen [::]:80;

    server_name lirlit.com;
    return 404; # managed by Certbot


}

1 Answer 1

1

You don't need to pass the path on the proxy_pass, the correct proxy configuration on the location is:

location /socket.io {
        include proxy_params;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass http://lirlit-chat-server:7000;
  }
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.