<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged worker</title>
<link>https://coderlegion.com/tag/worker</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to Configure and Control Nginx?</title>
<link>https://coderlegion.com/14386/how-to-configure-and-control-nginx</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;In previous article I explinaed how nginx works and what is the architecture of nginx.&lt;/p&gt;

&lt;p&gt;Now let's configure it and controls nginx.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Nginx Controls
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Reload
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;nginx &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This signal is used to reload the configuration files of nginx. &lt;br&gt;
It will not stop the nginx processes. &lt;br&gt;
It will just reload the configuration files and start the new worker processes.&lt;br&gt;
If old worker process serving few clients it will be served by old worker process.&lt;/p&gt;

&lt;p&gt;Either master will stop old worker process or it will wait for the old worker process to finish serving the current requests. &lt;/p&gt;

&lt;p&gt;This way if anything has issues nginx will not apply new configuration files.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Quit
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;nginx &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; quit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This signal is used to quit the nginx processes. &lt;/p&gt;

&lt;p&gt;It will stop the nginx processes and wait for the worker processes to finish serving the current requests.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Stop
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;nginx &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This signal is used to stop the nginx processes.&lt;/p&gt;

&lt;p&gt;It will stop the nginx processes and wait for the worker processes to finish serving the current requests.&lt;/p&gt;

&lt;p&gt;To stop nginx with PID. We can use kill command.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;kill&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-QUIT&lt;/span&gt; &amp;lt;master_pid&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also find all PID&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;ps &lt;span class=&quot;nt&quot;&gt;-ax&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;grep &lt;/span&gt;nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure Nginx
&lt;/h2&gt;

&lt;p&gt;nginx consists of modules which are controlled by directives specified in the configuration file. &lt;/p&gt;

&lt;p&gt;These Directives are divided into simple directives and block directives.&lt;/p&gt;

&lt;p&gt;Similar to C language, simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;). &lt;/p&gt;

&lt;p&gt;A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces ({ and }). &lt;/p&gt;

&lt;p&gt;If a block directive can have other directives inside braces, it is called a context (examples: events, http, server, and location).&lt;/p&gt;

&lt;p&gt;Directives placed in the configuration file outside of any contexts are considered to be in the main context. The events and http directives reside in the main context, server in http, and location in server.&lt;/p&gt;

&lt;p&gt;The rest of a line after the # sign is considered a comment.&lt;/p&gt;

&lt;p&gt;Here is the simple example of nginx configuration file:&lt;/p&gt;

&lt;p&gt;Main context: worker_processes 1; &lt;/p&gt;

&lt;p&gt;events context: worker_connections 1024; &lt;/p&gt;

&lt;p&gt;http context: we define server context here.&lt;/p&gt;

&lt;p&gt;server context: In here we define this to listen port 80 which is http port.&lt;/p&gt;

&lt;p&gt;location context: In here we define the root directory of the website.&lt;/p&gt;

&lt;p&gt;So, any request coming to port 80 will be served by the worker process with the root directory of &lt;code&gt;/var/www/html&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight nginx&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# This is a comment in the Main Context&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;worker_processes&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 

&lt;span class=&quot;k&quot;&gt;events&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
    &lt;span class=&quot;c1&quot;&gt;# This is a simple directive inside the 'events' context&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;worker_connections&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1024&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;http&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
    &lt;span class=&quot;c1&quot;&gt;# We are now inside the 'http' context&lt;/span&gt;

    &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
        &lt;span class=&quot;c1&quot;&gt;# The 'server' context is nested inside 'http'&lt;/span&gt;
        &lt;span class=&quot;kn&quot;&gt;listen&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 

        &lt;span class=&quot;kn&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
            &lt;span class=&quot;c1&quot;&gt;# The 'location' context is nested inside 'server'&lt;/span&gt;
            &lt;span class=&quot;kn&quot;&gt;root&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;/var/www/html&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We understood how to control nginx and how to configure nginx.&lt;/p&gt;

&lt;p&gt;So, this makes solid foundation for us to understand how work with nginx.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/14386/how-to-configure-and-control-nginx</guid>
<pubDate>Tue, 21 Apr 2026 02:19:50 +0000</pubDate>
</item>
<item>
<title>How Nginx Architecture is Designed and How They Work</title>
<link>https://coderlegion.com/14073/how-nginx-architecture-is-designed-and-how-they-work</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;In the previous article, We have seen how to setup nginx on ubuntu and enable the site. It was more into basic where anyone one who wants to configure domain or any other thing can follow it.&lt;/p&gt;

&lt;p&gt;Now in this article we will explore a how nginx works.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Nginx Architecture and How they Works?
&lt;/h2&gt;

&lt;p&gt;Before we go into how nginx works, we need to understand the architecture of nginx.&lt;/p&gt;

&lt;p&gt;Nginx has two main components: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Master Process&lt;/li&gt;
&lt;li&gt;Worker Process&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Master process is to read, evaluate configuration files and maintain worker process.&lt;/p&gt;

&lt;p&gt;Worker Process will do all the processing of client requests. &lt;/p&gt;

&lt;p&gt;Nginx works on principle of event-based and OS-dependent mechanisms to efficiently distribute requests among worker processes.&lt;/p&gt;

&lt;p&gt;The number of worker process can be configured in the nginx.conf file and this can also be automatically set based on the number of CPU cores available on the system.&lt;/p&gt;

&lt;p&gt;For more information on how to configure the number of worker process, please refer to the official documentation &lt;a href=&quot;https://nginx.org/en/docs/ngx_core_module.html#worker_processes&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Worker Processes&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By default, the configuration file is named &lt;code&gt;nginx.conf&lt;/code&gt; and placed in the directory &lt;code&gt;/usr/local/nginx/conf&lt;/code&gt;, &lt;code&gt;/etc/nginx&lt;/code&gt;, or &lt;code&gt;/usr/local/etc/nginx&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Start, Stop and Reload Nginx?
&lt;/h2&gt;

&lt;p&gt;To Control any operation of nginx, we need to use the executable file. &lt;/p&gt;

&lt;p&gt;This will be having this syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;nginx &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; signal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where signal may be one of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;stop &amp;mdash; fast shutdown&lt;/li&gt;
&lt;li&gt;quit &amp;mdash; graceful shutdown&lt;/li&gt;
&lt;li&gt;reload &amp;mdash; reloading the configuration file&lt;/li&gt;
&lt;li&gt;reopen &amp;mdash; reopening the log files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, to stop nginx processes with waiting for the worker processes to finish serving current requests, the following command can be executed:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;nginx &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; quit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As of now we understand how Nginx architecture works and how to control Nginx. &lt;/p&gt;

&lt;p&gt;In the next article, we will go in-depth on how to use these signals to control Nginx.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;373&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/14073/how-nginx-architecture-is-designed-and-how-they-work</guid>
<pubDate>Thu, 09 Apr 2026 02:36:18 +0000</pubDate>
</item>
</channel>
</rss>