Socket.io io.emit (broadcase to all clients) working in local but not working in remote server

server.js

require('dotenv').config({ path: '.env/.env' });
var express      = require('express'),
  fileUpload     = require('express-fileupload');
  app            = express(),
  appPort        = process.env.APP_RESTPORT || 3000,
  bodyParser     = require('body-parser'),
  cors           = require('cors'),
  os             = require("os"),
  fs             = require('fs'),
  socketioJwt   = require('socketio-jwt');

const { Server } = require("socket.io");
const { setupSocketController } = require('./api/controllers/socketController');
var httpOptions  = {}

if(process.env.APP_SSL_ENABLED == 1){
  var http    = require('https');
  httpOptions = {
    key: fs.readFileSync('init_scripts/ssl-certs/output/private/server.key'),
    cert: fs.readFileSync('init_scripts/ssl-certs/output/certs/server.crt')
  };
}else{
  var http = require('http');
}

const server = http.createServer(httpOptions, app).listen(appPort, function (req, res) { 
  console.log(`Server started at port ${appPort}`); 
});

// Create & Init Socket App
const io = new Server(server, {
  transports: ['websocket'], //required nginx proxy
  cors: {
    origin: '*',
  },
  allowEIO3: true
});

// Setup socket controller
setupSocketController(io);

api/controllers/socketController.js

// socketController.js
var socketioJwt = require('socketio-jwt');

const privateKey    = fs.readFileSync(process.env.APP_PRIVATE_KEY, "utf8");
// const publicKey     = fs.readFileSync(process.env.APP_PUBLIC_KEY, "utf8");

module.exports.setupSocketController = (io) => {
  io.use(socketioJwt.authorize({
    secret: privateKey,
    handshake: true
  }));

  io.on('connection', (socket) => {
      // const clientSourceIp  = socket.request.headers['x-forwarded-for'] || socket.request.socket.remoteAddress || null;
      // console.log(`${socket.id} => ${clientSourceIp} is connected`);
      let __createdtime__ = Date.now(); // Current timestamp

      // Add a user to a room
      socket.on('ping', (data) => {
        socket.emit('pong', {
          __createdtime__
        });
      });

      socket.on('disconnect', (data) => {
      // console.log(`${socket.id} => ${clientSourceIp} is disconnected`);
      let __createdtime__  = Date.now(); // Current timestamp
      const { room }       = data; // Data sent from client when join_room event emitted
      // Send message to all users currently in the room, apart from the user that just joined
        socket.to(room).emit('general_messages', {
          message: `${socket.id} disconnected`,
          __createdtime__,
        });
      });
  });

  // Emit broadcast from outside the connection block
  const broadcastMessage = (event, message) => {
    io.emit(event, message);
  };

  // Export the function if needed elsewhere
  module.exports.broadcastMessage = broadcastMessage;
};

api/controllers/anothercontroller.js

const { broadcastMessage } = require('../controllers/socketController');

exports.retrieveAll = async function(req, res) {
  broadcastMessage('pong', {"pong-test": "test-pong-controller"});
}

The goal is when ever a controller completes a transaction it will send broadcast message to connected socket clients.

This works with local machine but in remote server no longer works..

Uses Nginx as web server.

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    upstream backends {
        ip_hash;
        server 127.0.0.1:3000;
    }

    server {
        listen       443 ssl http2;
        listen       [::]:443 ssl http2;
        server_name  example.com;
        client_max_body_size 1G;
        
        ssl_certificate "/etc/letsencrypt/live/example.com/fullchain.pem";
        ssl_certificate_key "/etc/letsencrypt/live/example.com/privkey.pem";
        include /etc/letsencrypt/options-ssl-nginx.conf;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

        location /socket.io/ {
            proxy_pass https://backends;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_cache_bypass $http_upgrade;
            proxy_read_timeout 60s;

            proxy_ssl_verify off;
            proxy_ssl_server_name on;
        }

        location / {
            proxy_pass https://backends;
            # Ensure HTTP/2 is properly handled
            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;

            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_ssl_verify off;
            proxy_ssl_server_name on;

            proxy_set_header X-Client-Proto $scheme;
            proxy_set_header X-Client-Proto-Ver $server_protocol;
            proxy_set_header X-Real-IP $remote_addr;

            proxy_pass_request_headers on;
            proxy_set_header Cookie $http_cookie;

            # Change Set-Cookie headers if necessary
            proxy_cookie_domain example.com .example.com;

            # Handle path rewriting for cookies
            # proxy_cookie_path /backend/ /;
        }
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật