We're working on chat app project using RubyOnRails. The app we developed working on local without any issue. However, it gives an error while trying to connect the web socket from outside. Our requirement is to use these chat app apis from an Android app.
We're using following technologies/frameworks
/etc/nginx/sites-enabled/chatroom_demo
server {
listen 80 default_server;
server_name xx.xxx.xxx.xxx;
passenger_enabled on;
passenger_app_env production;
root /home/projects/chatroom_demo/public;
location /cable {
passenger_app_group_name chatroom_demo_action_cable;
passenger_force_max_concurrent_requests_per_process 0;
proxy_pass http://xx.xxx.xxx.xxx;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
/etc/nginx/nginx.conf
user www-data;
worker_processes auto;
worker_rlimit_nofile 16384;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 20000;
# multi_accept on;
}
config/cable.yml
production:
adapter: redis
url: redis://localhost:6379
config/environments/production.rb
config.action_cable.url = [/ws:\/\/*/, /wss:\/\/*/]
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
Client side we're tying to connect using following code:
let socket = new WebSocket("ws://XX.XXX.XXX.XXX/cable");
socket.onopen = function(e) {
alert("[open] Connection established");
};
socket.onerror = function(error) {
alert(`[error] ${error.message}`);
};
Client side error: Undefined
Server side error:
*32764 socket() failed (24: Too many open files) while connecting to upstream, client: XX.XXX.XXX.XXX, server: XX.XXX.XXX.XXX, request: "GET /cable HTTP/1.1", upstream: "http://XX.XXX.XXX.XXX:80/cable", host: "XX.XXX.XXX.XXX"
We have tried many different ways to fix this issue but couldn't find any potential fix.
Did you also update your sysd nolimitfile settings to be something > worker_rlimit_nofile 16384? More info in this solution.