Vietnam

    Nodejs.vn

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Groups
    • Search

    kết nối socket.io từ https

    Hỏi Đáp
    0
    12
    3459
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Lâm Tùng Nguyễn
      Lâm Tùng Nguyễn last edited by

      Xin chào
      Mình có viết 1 ứng dụng nho nhỏ để chat bằng socket.io. Khi emit từ http thì ok không sao cả nhưng khi mình emit https thì soket io ko ho he gì luôn.
      he page at 'https://abc.com' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://xxx.xxx.xxx.xx:3001/socket.io/?EIO=3&transport=polling&t=LkoP3bV'. This request has been blocked; the content must be served over HTTPS.

      Thanh Php 1 Reply Last reply Reply Quote 0
      • N
        nvs2394 last edited by

        bạn thử set
        io.set('match origin protocol', true);

        io.set('origins', ':');

        io.set('log level', 1);

        1 Reply Last reply Reply Quote 0
        • Lâm Tùng Nguyễn
          Lâm Tùng Nguyễn last edited by

          tks bạn để mình thử xem sao 😃

          1 Reply Last reply Reply Quote 0
          • Lâm Tùng Nguyễn
            Lâm Tùng Nguyễn last edited by

            Option match origin protocol is not valid. Please refer to the README.
            Option log level is not valid. Please refer to the README.
            Nó báo thế này là sao nhỉ bạn có thể giải thích rõ hơn cho mình về các dòng lệnh đó k mình cảm ơn

            1 Reply Last reply Reply Quote 0
            • N
              nvs2394 last edited by

              Bạn đang dùng cloud app hay là VPS
              nếu dùng VPS có dùng nginx hay ko

              1 Reply Last reply Reply Quote 0
              • Lâm Tùng Nguyễn
                Lâm Tùng Nguyễn last edited by

                Mình dùng vps nhưng chạy console thôi vì đang thử nghiệm phải cài nginx lên ak bạn

                1 Reply Last reply Reply Quote 0
                • N
                  nvs2394 last edited by

                  ở đây 'http://xxx.xxx.xxx.xx:3001 của bạn là http vì vậy nó bị mixed content với thằng HTTPS của https://abc.com
                  Bạn cần phải chuyển http://xxx thành https

                  1 Reply Last reply Reply Quote 0
                  • K
                    kiddev29 Sailor last edited by

                    Muốn emit được từ https thì bạn cần chuyển socket sang chạy https để không bị block, ngoài ra khi khai báo ở client cũng thêm khai báo hỗ trợ ssl nữa là được nhé

                    socket = io.connect('https://[socket server của bạn] ', {secure: true});

                    Lâm Tùng Nguyễn 1 Reply Last reply Reply Quote 1
                    • Tung Nguyen215
                      Tung Nguyen215 last edited by

                      Với socket và SSL (dùng letsenscrypt) và nginx

                      # API
                      server {
                         listen 80;
                         server_name [DOMAIN];
                         location / {
                           return 301 [DOMAIN]$request_uri;
                         }
                      }
                      
                      server {
                              listen 443 ssl;
                              server_name [DOMAIN];
                              ssl_certificate /etc/letsencrypt/live/[DOMAIn]/fullchain.pem;
                              ssl_certificate_key /etc/letsencrypt/live/[DOMAIN]/privkey.pem;
                              ssl_session_timeout 5m;
                              ssl_session_cache  shared:SSL:10m;
                              ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                              ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-$
                              ssl_prefer_server_ciphers on;
                              add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
                              ssl_stapling on;
                      
                              location / {
                                      proxy_pass http://127.0.0.1:3000;   #NODE.JS SERVER
                                      proxy_http_version 1.1;
                                      proxy_set_header Upgrade $http_upgrade;
                                      proxy_set_header Connection 'upgrade';
                                      proxy_set_header Host $host;
                                      proxy_cache_bypass $http_upgrade;
                              }
                      }
                      
                      1 Reply Last reply Reply Quote 0
                      • Lâm Tùng Nguyễn
                        Lâm Tùng Nguyễn @kiddev29 last edited by

                        @kiddev29 said in kết nối socket.io từ https:

                        Muốn emit được từ https thì bạn cần chuyển socket sang chạy https để không bị block, ngoài ra khi khai báo ở client cũng thêm khai báo hỗ trợ ssl nữa là được nhé

                        Tks a em chuyển qua https đc rồi 😃

                        1 Reply Last reply Reply Quote 0
                        • Thanh Php
                          Thanh Php @Lâm Tùng Nguyễn last edited by

                          @Lâm-Tùng-Nguyễn Bạn ơi chuyển sang https kiểu j thế, có thế chia sẻ kinh nghiệm được k? Mình mới tập tành server.

                          1 Reply Last reply Reply Quote 0
                          • Hà Lan Hr
                            Hà Lan Hr last edited by

                            VP9 VIỆT NAM CHIÊU MỘ SENIOR DEV LƯƠNG 1000$- 3000$.
                            Công ty Cổ phần VP9 Việt Nam cần chiêu mộ nhân tài lập trình viên, siêu nhân code thành thạo 1 trong các ngôn ngữ: PHP, Android, Node Js, C, C++, Java.
                            Lương tỉ lệ thuận theo năng lực 1000$-3000$. Làm việc tại 72 Trần Đăng Ninh, Cầu Giấy, Hà Nội.
                            Làm việc trong môi trường thoải mái, cơ hội thăng tiến rõ ràng.
                            Gửi CV trực tiếp: [email protected]
                            Hoặc liên hệ hotline: 0919822986. Skype: vuminhhai99

                            1 Reply Last reply Reply Quote -1
                            • First post
                              Last post