<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nikunj Tandel</title>
    <description>The latest articles on DEV Community by Nikunj Tandel (@nikunj2612).</description>
    <link>https://dev.to/nikunj2612</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F700113%2Ffc0762eb-201c-4235-b518-5f3741bef82e.jpeg</url>
      <title>DEV Community: Nikunj Tandel</title>
      <link>https://dev.to/nikunj2612</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nikunj2612"/>
    <language>en</language>
    <item>
      <title>Nginx Tweaks AND Tricks</title>
      <dc:creator>Nikunj Tandel</dc:creator>
      <pubDate>Thu, 01 May 2025 06:37:17 +0000</pubDate>
      <link>https://dev.to/nikunj2612/nginx-tweaks-and-tricks-5fia</link>
      <guid>https://dev.to/nikunj2612/nginx-tweaks-and-tricks-5fia</guid>
      <description>&lt;p&gt;We encountered an issue while working with WebSockets behind Nginx as our web server — the server crashed after reaching approximately 786 active connections. After investigating, we discovered that Nginx has default limits on the number of simultaneous connections it can handle.&lt;/p&gt;

&lt;p&gt;To resolve this, we applied specific configuration tweaks to Nginx, which allowed us to increase the limit and support more active connections. These changes helped us stabilise the system and ensure smoother real-time communication.&lt;/p&gt;

&lt;h1&gt;
  
  
  maximum capability of system
&lt;/h1&gt;

&lt;p&gt;user@ubuntu:~$ cat /proc/sys/fs/file-max&lt;br&gt;
708444&lt;/p&gt;

&lt;h1&gt;
  
  
  available limit
&lt;/h1&gt;

&lt;p&gt;user@ubuntu:~$ ulimit -n&lt;br&gt;
1024&lt;/p&gt;

&lt;h1&gt;
  
  
  To increase the available limit to 200000
&lt;/h1&gt;

&lt;p&gt;user@ubuntu:~$ sudo nano /etc/sysctl.conf&lt;/p&gt;

&lt;h1&gt;
  
  
  Add the following line to it
&lt;/h1&gt;

&lt;p&gt;fs.file-max = 200000&lt;/p&gt;

&lt;h1&gt;
  
  
  run this to refresh with the new config
&lt;/h1&gt;

&lt;p&gt;user@ubuntu:~$ sudo sysctl -p&lt;/p&gt;

&lt;h1&gt;
  
  
  edit the following file
&lt;/h1&gt;

&lt;p&gt;user@ubuntu:~$ sudo nano /etc/security/limits.conf&lt;/p&gt;

&lt;h1&gt;
  
  
  Add the following lines to it
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;soft     nproc          200000

&lt;ul&gt;
&lt;li&gt;hard     nproc          200000
&lt;/li&gt;
&lt;li&gt;soft     nofile         200000
&lt;/li&gt;
&lt;li&gt;hard     nofile         200000
root soft     nproc          200000
root hard     nproc          200000
root soft     nofile         200000
root hard     nofile         200000
#update root based on your user i.e ubuntu&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h1&gt;
  
  
  edit the following file
&lt;/h1&gt;

&lt;p&gt;user@ubuntu:~$ sudo nano /etc/pam.d/common-session&lt;/p&gt;

&lt;h1&gt;
  
  
  add this line to it
&lt;/h1&gt;

&lt;p&gt;session required pam_limits.so&lt;/p&gt;

&lt;h1&gt;
  
  
  logout and login and try the following command
&lt;/h1&gt;

&lt;p&gt;user@ubuntu:~$ ulimit -n&lt;br&gt;
200000&lt;/p&gt;

&lt;h1&gt;
  
  
  now you can increase no.of.connections per Nginx worker and worker_rlimit_nofile
&lt;/h1&gt;

&lt;h1&gt;
  
  
  in Nginx main config /etc/nginx/nginx.conf
&lt;/h1&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;worker_rlimit_nofile 200000;
worker_connections 200000;#(inside event object)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>nginx</category>
      <category>webserver</category>
    </item>
  </channel>
</rss>
