Nginx is a very popular and commonly used open-source web server that can run on both Linux and Windows operating systems. In this blog, we will build a very basic static Nginx website
Lab Server Setup:
Hostname: nginx01.ash.local
Operating System: Redhat 9.2
Packages and Config files required for the Nginx server
- nginx – The package installs the Nginx web server.
- links – Optional package for text-based web browser
Default ports: 80 and 443 (SSL)
These are the main folders storing Nginx config files
Purpose | Location |
Version | nginx -v |
Check if config is correct | nginx -t |
Default Parent Directory | /usr/share/ |
Main Nginx root configuration directory. | /etc/nginx |
Additional Nginx configuration files or directives( additional website config file ) | /etc/nginx/conf.d |
Main Configuration file | /etc/nginx/nginx.conf |
Contains log files ( SymLink to /etc/httpd/logs) | /etc/log/nginx |
Main web document root directory | /var/www |
Access Logs | /var/log/nginx/access.log |
Error Logs | /var/log/nginx/error.log |
Concept of Master and Worker Process
Master Process | Evaluates the Config files |
Worker Process | Responsible for serving web content |
Step 1 – Set up the host file
1 2 3 4 5 6 7 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">hostname</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #E4F0FB">lnx03</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">hosts</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost4</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost4</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain4</span></span> <span class="line"><span style="color: #A6ACCD">::</span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost6</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost6</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain6</span></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span></span> |
Step 2– Check the Nginx daemon(httpd) install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">dnf</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">list</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #E4F0FB">Updating</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Subscription</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Management</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">repositories</span><span style="color: #A6ACCD">.</span></span> <span class="line"><span style="color: #E4F0FB">Last</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">metadata</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">expiration</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">check</span><span style="color: #A6ACCD">: </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">02</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">48</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ago</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">on</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Mon</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">30</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Oct</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2023</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">06</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">24</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">38</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">GMT</span><span style="color: #A6ACCD">.</span></span> <span class="line"><span style="color: #E4F0FB">Installed</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Packages</span></span> <span class="line"><span style="color: #E4F0FB">httpd</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">x86_64</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2.4</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">53</span><span style="color: #91B4D5">-</span><span style="color: #A6ACCD">11.</span><span style="color: #E4F0FB">el9_2</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">5</span><span style="color: #A6ACCD"> @</span><span style="color: #E4F0FB">rhel</span><span style="color: #91B4D5">-</span><span style="color: #5DE4C7">9</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">for</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">x86_64</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">appstream</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">rpms</span></span> <span class="line"></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">yum</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">list</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">nginx</span></span> <span class="line"><span style="color: #E4F0FB">Updating</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Subscription</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Management</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">repositories</span><span style="color: #A6ACCD">.</span></span> <span class="line"><span style="color: #E4F0FB">Last</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">metadata</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">expiration</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">check</span><span style="color: #A6ACCD">: </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">03</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">15</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ago</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">on</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Mon</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">30</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Oct</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2023</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">06</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">24</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">38</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">GMT</span><span style="color: #A6ACCD">.</span></span> <span class="line"><span style="color: #E4F0FB">Installed</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Packages</span></span> <span class="line"><span style="color: #E4F0FB">httpd</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">x86_64</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2.4</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">53</span><span style="color: #91B4D5">-</span><span style="color: #A6ACCD">11.</span><span style="color: #E4F0FB">el9_2</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">5</span><span style="color: #A6ACCD"> @</span><span style="color: #E4F0FB">rhel</span><span style="color: #91B4D5">-</span><span style="color: #5DE4C7">9</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">for</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">x86_64</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">appstream</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">rpm</span></span> <span class="line"></span> |
Step 3– Install Nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<span class="line"><span style="color: #F6F6F4">[root@nginx01 </span><span style="color: #F286C4">~</span><span style="color: #F6F6F4">]# </span></span> <span class="line"><span style="color: #F6F6F4">[root@nginx01 </span><span style="color: #F286C4">~</span><span style="color: #F6F6F4">]# yum install nginx </span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">y</span></span> <span class="line"><span style="color: #F6F6F4">Updating Subscription Management repositories.</span></span> <span class="line"><span style="color: #F6F6F4">Last metadata expiration check: </span><span style="color: #BF9EEE">0</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">13</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">04</span><span style="color: #F6F6F4"> ago on Sun </span><span style="color: #BF9EEE">12</span><span style="color: #F6F6F4"> Nov </span><span style="color: #BF9EEE">2023</span><span style="color: #F6F6F4"> </span><span style="color: #BF9EEE">11</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">00</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">21</span><span style="color: #F6F6F4"> GMT.</span></span> <span class="line"><span style="color: #F6F6F4">Dependencies resolved.</span></span> <span class="line"><span style="color: #F286C4">==============================================================================================================================================================</span></span> <span class="line"><span style="color: #F6F6F4"> Package Architecture Version Repository Size</span></span> <span class="line"><span style="color: #F286C4">==============================================================================================================================================================</span></span> <span class="line"><span style="color: #F6F6F4">Installing:</span></span> <span class="line"><span style="color: #F6F6F4"> nginx x86_64 </span><span style="color: #BF9EEE">1</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">1.20</span><span style="color: #F6F6F4">.</span><span style="color: #BF9EEE">1</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">14.el9_2.</span><span style="color: #BF9EEE">1</span><span style="color: #F6F6F4"> rhel</span><span style="color: #F286C4">-</span><span style="color: #BF9EEE">9</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">for</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">x86_64</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">appstream</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">rpms </span><span style="color: #BF9EEE">40</span><span style="color: #F6F6F4"> k</span></span> <span class="line"><span style="color: #F6F6F4">Installing dependencies:</span></span> <span class="line"><span style="color: #F6F6F4"> nginx</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">core x86_64 </span><span style="color: #BF9EEE">1</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">1.20</span><span style="color: #F6F6F4">.</span><span style="color: #BF9EEE">1</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">14.el9_2.</span><span style="color: #BF9EEE">1</span><span style="color: #F6F6F4"> rhel</span><span style="color: #F286C4">-</span><span style="color: #BF9EEE">9</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">for</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">x86_64</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">appstream</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">rpms </span><span style="color: #BF9EEE">574</span><span style="color: #F6F6F4"> k</span></span> <span class="line"><span style="color: #F6F6F4"> nginx</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">filesystem noarch </span><span style="color: #BF9EEE">1</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">1.20</span><span style="color: #F6F6F4">.</span><span style="color: #BF9EEE">1</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">14.el9_2.</span><span style="color: #BF9EEE">1</span><span style="color: #F6F6F4"> rhel</span><span style="color: #F286C4">-</span><span style="color: #BF9EEE">9</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">for</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">x86_64</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">appstream</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">rpms </span><span style="color: #BF9EEE">11</span><span style="color: #F6F6F4"> k</span></span> <span class="line"><span style="color: #F6F6F4"> redhat</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">logos</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">httpd noarch </span><span style="color: #BF9EEE">90.4</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">2.el9 rhel</span><span style="color: #F286C4">-</span><span style="color: #BF9EEE">9</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">for</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">x86_64</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">appstream</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">rpms </span><span style="color: #BF9EEE">18</span><span style="color: #F6F6F4"> k</span></span> <span class="line"></span> <span class="line"><span style="color: #F6F6F4">Transaction Summary</span></span> <span class="line"></span> |
Step 4 – Enable the Nginx service with either nginx using the below command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<span class="line"><span style="color: #F8F8F2"># To Manage httpd deamon</span></span> <span class="line"><span style="color: #F8F8F2"># systemctl start</span><span style="color: #F92672">|</span><span style="color: #F8F8F2">stop</span><span style="color: #F92672">|</span><span style="color: #F8F8F2">status nginx</span></span> <span class="line"></span> <span class="line"><span style="color: #F8F8F2"># To Stop and Disable Service</span></span> <span class="line"><span style="color: #F8F8F2">systemctl enable </span><span style="color: #F92672">|</span><span style="color: #F8F8F2">disable nginx</span></span> <span class="line"></span> <span class="line"><span style="color: #F8F8F2"># To Ensure service stays peristant during reboots</span></span> <span class="line"><span style="color: #F8F8F2">chkconfig nginx on</span></span> <span class="line"></span> <span class="line"><span style="color: #F8F8F2"># To Show status </span><span style="color: #F92672">of</span><span style="color: #F8F8F2"> httpd</span></span> <span class="line"><span style="color: #F8F8F2">systemctl list</span><span style="color: #F92672">-</span><span style="color: #F8F8F2">unit</span><span style="color: #F92672">-</span><span style="color: #F8F8F2">files </span><span style="color: #F92672">|</span><span style="color: #F8F8F2"> grep nginx</span></span> <span class="line"></span> <span class="line"><span style="color: #F8F8F2">Optionally, services can be restarted </span><span style="color: #F92672">as</span><span style="color: #F8F8F2"> </span></span> <span class="line"><span style="color: #F92672">/</span><span style="color: #F8F8F2">etc</span><span style="color: #F92672">/</span><span style="color: #F8F8F2">init.d</span><span style="color: #F92672">/</span><span style="color: #F8F8F2">nginx </span><span style="color: #F92672">|</span><span style="color: #F8F8F2"> stop </span><span style="color: #F92672">|</span><span style="color: #F8F8F2"> start</span></span> <span class="line"></span> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<span class="line"><span style="color: #F6F6F4">[root@nginx01 </span><span style="color: #F286C4">~</span><span style="color: #F6F6F4">]# systemctl start nginx.service</span></span> <span class="line"><span style="color: #F6F6F4">[root@nginx01 </span><span style="color: #F286C4">~</span><span style="color: #F6F6F4">]# systemctl enable nginx.service</span></span> <span class="line"><span style="color: #F6F6F4">[root@nginx01 </span><span style="color: #F286C4">~</span><span style="color: #F6F6F4">]# systemctl status nginx.service</span></span> <span class="line"><span style="color: #F6F6F4">● nginx.service </span><span style="color: #F286C4">-</span><span style="color: #F6F6F4"> The nginx HTTP and reverse proxy server</span></span> <span class="line"><span style="color: #F6F6F4"> Loaded: </span><span style="color: #62E884">loaded</span><span style="color: #F6F6F4"> (</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">usr</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">lib</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">systemd</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">system</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">nginx.service; enabled; preset: disabled)</span></span> <span class="line"><span style="color: #F6F6F4"> Active: </span><span style="color: #62E884">active</span><span style="color: #F6F6F4"> (running) since Sun </span><span style="color: #BF9EEE">2023</span><span style="color: #F286C4">-</span><span style="color: #BF9EEE">11</span><span style="color: #F286C4">-</span><span style="color: #BF9EEE">12</span><span style="color: #F6F6F4"> </span><span style="color: #BF9EEE">11</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">17</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">40</span><span style="color: #F6F6F4"> GMT; 1min 42s ago</span></span> <span class="line"><span style="color: #F6F6F4"> Main PID: </span><span style="color: #BF9EEE">9516</span><span style="color: #F6F6F4"> (nginx)</span></span> <span class="line"><span style="color: #F6F6F4"> Tasks: </span><span style="color: #BF9EEE">2</span><span style="color: #F6F6F4"> (</span><span style="color: #FFB86C; font-style: italic">limit</span><span style="color: #F286C4">:</span><span style="color: #F6F6F4"> </span><span style="color: #BF9EEE">10930</span><span style="color: #F6F6F4">)</span></span> <span class="line"><span style="color: #F6F6F4"> Memory: 2.0M</span></span> <span class="line"><span style="color: #F6F6F4"> CPU: 1.785s</span></span> <span class="line"><span style="color: #F6F6F4"> CGroup: /system.slice/nginx.service</span></span> <span class="line"><span style="color: #F6F6F4"> ├─9516 "nginx: master process /usr/sbin/nginx"</span></span> <span class="line"><span style="color: #F6F6F4"> └─9517 "nginx: worker process"</span></span> <span class="line"></span> <span class="line"><span style="color: #F6F6F4">Nov 12 11:17:36 nginx01 systemd[1]: Starting The nginx HTTP and reverse proxy server...</span></span> <span class="line"><span style="color: #F6F6F4">Nov 12 11:17:38 nginx01 nginx[9492]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok</span></span> <span class="line"><span style="color: #F6F6F4">Nov 12 11:17:38 nginx01 nginx[9492]: nginx: configuration file /etc/nginx/nginx.conf test is successful</span></span> <span class="line"><span style="color: #F6F6F4">Nov 12 11:17:40 nginx01 systemd[1]: Started The nginx HTTP and reverse proxy server.</span></span> |
Step 5 – Check the version of Nginx installed.
1 2 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">v</span></span> <span class="line"><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">version</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #5DE4C7">1.20</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">1</span></span> |
Step 6 –Verify that port 80 is open
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<span class="line"><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">version</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #5DE4C7">1.20</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">1</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">netstat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">tulpn</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">|</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">grep</span><span style="color: #A6ACCD"> :</span><span style="color: #5DE4C7">80</span></span> <span class="line"><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.0</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.0</span><span style="color: #A6ACCD">:</span><span style="color: #91B4D5">*</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">LISTEN</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">9516</span><span style="color: #91B4D5">/nginx</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">master</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #E4F0FB">tcp6</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> :::</span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> :::</span><span style="color: #91B4D5">*</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">LISTEN</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">9516</span><span style="color: #91B4D5">/nginx</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">master</span></span> <span class="line"></span> <span class="line"><span style="color: #E4F0FB">As</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">shown</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">below</span><span style="color: #A6ACCD">,</span><span style="color: #E4F0FB">master</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">process</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">runs</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">as</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">root</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">and</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">worker</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">process</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">runs</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">as</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">nginx</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">user</span></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">ps</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">ef</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">forest</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">|</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">grep</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">nginx</span></span> <span class="line"><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">18506</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2102</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">11</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">22</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">pts</span><span style="color: #91B4D5">/</span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD"> \</span><span style="color: #E4F0FB">_</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">grep</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">color</span><span style="color: #91B4D5">=</span><span style="color: #E4F0FB">auto</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">nginx</span></span> <span class="line"><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">9516</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">11</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">17</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">?</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">00</span><span style="color: #91B4D5">:</span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">nginx</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">master</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">process</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">usr</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">sbin</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span></span> <span class="line"><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">9517</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">9516</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">11</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">17</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">?</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">00</span><span style="color: #91B4D5">:</span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD"> \</span><span style="color: #E4F0FB">_</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">nginx</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">worker</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">process</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span></span> <span class="line"><span style="color: #A6ACCD"> </span></span> |
Step 7 –Allow HTTP and HTTPS traffic in our firewall if enabled.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<span class="line"><span style="color: #E4F0FB">Configure</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Firewall</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">for</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Port</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">and</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">443</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #E4F0FB">firewall</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">cmd</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">permanent</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">add</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">service</span><span style="color: #91B4D5">=</span><span style="color: #E4F0FB">http</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">add</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">service</span><span style="color: #91B4D5">=</span><span style="color: #E4F0FB">http</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #E4F0FB">firewall</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">cmd</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">permanent</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">add</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">service</span><span style="color: #91B4D5">=</span><span style="color: #E4F0FB">http</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">add</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">service</span><span style="color: #91B4D5">=</span><span style="color: #E4F0FB">https</span></span> <span class="line"><span style="color: #A6ACCD"># </span><span style="color: #E4F0FB">firewall</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">cmd</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">reload</span></span> <span class="line"></span> <span class="line"><span style="color: #E4F0FB">On</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">the</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">old</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">RHEL</span><span style="color: #A6ACCD">, </span><span style="color: #E4F0FB">we</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">would</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">use</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">to</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">set</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">the</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">config</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">as</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">shown</span></span> <span class="line"></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD"># </span><span style="color: #E4F0FB">Allow</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">a</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">subnet</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">to</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">pass</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">port</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">A</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">INPUT</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">NEW</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">s</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">192.168</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">1.0</span><span style="color: #91B4D5">/</span><span style="color: #5DE4C7">24</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">dport</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">j</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ACCEPT</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">A</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">INPUT</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">NEW</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">dport</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">j</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ACCEPT</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">A</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">INPUT</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">NEW</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">dport</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">443</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">j</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ACCEPT</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">service</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">save</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">service</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">restart</span></span> <span class="line"></span> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<span class="line"><span style="color: #ADBAC7">[root@nginx01 </span><span style="color: #F47067">~</span><span style="color: #ADBAC7">]# firewall</span><span style="color: #F47067">-</span><span style="color: #ADBAC7">cmd </span><span style="color: #F47067">--</span><span style="color: #ADBAC7">permanent </span><span style="color: #F47067">--</span><span style="color: #ADBAC7">add</span><span style="color: #F47067">-</span><span style="color: #ADBAC7">service</span><span style="color: #F47067">=</span><span style="color: #ADBAC7">http </span><span style="color: #F47067">--</span><span style="color: #ADBAC7">add</span><span style="color: #F47067">-</span><span style="color: #ADBAC7">service</span><span style="color: #F47067">=</span><span style="color: #ADBAC7">https</span></span> <span class="line"></span> <span class="line"><span style="color: #ADBAC7">success</span></span> <span class="line"><span style="color: #ADBAC7">[root@nginx01 </span><span style="color: #F47067">~</span><span style="color: #ADBAC7">]# </span></span> <span class="line"><span style="color: #ADBAC7">[root@nginx01 </span><span style="color: #F47067">~</span><span style="color: #ADBAC7">]# systemctl status firewalld</span></span> <span class="line"><span style="color: #ADBAC7">● firewalld.service </span><span style="color: #F47067">-</span><span style="color: #ADBAC7"> firewalld </span><span style="color: #F47067">-</span><span style="color: #ADBAC7"> dynamic firewall daemon</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Loaded</span><span style="color: #ADBAC7">: </span><span style="color: #DCBDFB">loaded</span><span style="color: #ADBAC7"> (</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">usr</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">lib</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">systemd</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">system</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">firewalld.service; enabled; preset: enabled)</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Active</span><span style="color: #ADBAC7">: </span><span style="color: #DCBDFB">active</span><span style="color: #ADBAC7"> (running) since Sun </span><span style="color: #6CB6FF">2023</span><span style="color: #F47067">-</span><span style="color: #6CB6FF">11</span><span style="color: #F47067">-</span><span style="color: #6CB6FF">12</span><span style="color: #ADBAC7"> </span><span style="color: #6CB6FF">10</span><span style="color: #ADBAC7">:</span><span style="color: #6CB6FF">39</span><span style="color: #ADBAC7">:</span><span style="color: #6CB6FF">14</span><span style="color: #ADBAC7"> </span><span style="color: #6CB6FF">GMT</span><span style="color: #ADBAC7">; 41min ago</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Docs</span><span style="color: #ADBAC7">: </span><span style="color: #F69D50">man</span><span style="color: #ADBAC7">:</span><span style="color: #DCBDFB">firewalld</span><span style="color: #ADBAC7">(</span><span style="color: #6CB6FF">1</span><span style="color: #ADBAC7">)</span></span> <span class="line"><span style="color: #ADBAC7"> Main </span><span style="color: #F69D50">PID</span><span style="color: #ADBAC7">: </span><span style="color: #6CB6FF">820</span><span style="color: #ADBAC7"> (firewalld)</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Tasks</span><span style="color: #ADBAC7">: </span><span style="color: #6CB6FF">2</span><span style="color: #ADBAC7"> (</span><span style="color: #F69D50">limit</span><span style="color: #F47067">:</span><span style="color: #ADBAC7"> </span><span style="color: #6CB6FF">10930</span><span style="color: #ADBAC7">)</span></span> <span class="line"><span style="color: #ADBAC7"> Memory: 40.1M</span></span> <span class="line"><span style="color: #ADBAC7"> CPU: 4.956s</span></span> <span class="line"><span style="color: #ADBAC7"> CGroup: /system.slice/firewalld.service</span></span> <span class="line"><span style="color: #ADBAC7"> └─820 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid</span></span> <span class="line"></span> <span class="line"><span style="color: #ADBAC7">Nov 12 10:39:12 nginx01 systemd[1]: Starting firewalld - dynamic firewall daemon...</span></span> <span class="line"><span style="color: #ADBAC7">Nov 12 10:39:14 nginx01 systemd[1]: Started firewalld - dynamic firewall daemon.</span></span> <span class="line"><span style="color: #ADBAC7">[root@nginx01 ~]# </span></span> <span class="line"><span style="color: #ADBAC7">[root@nginx01 ~]# </span></span> <span class="line"><span style="color: #ADBAC7">[root@nginx01 ~]# firewall-cmd --reload</span></span> <span class="line"><span style="color: #ADBAC7">success</span></span> <span class="line"><span style="color: #ADBAC7">[root@nginx01 ~]# firewall-cmd --list-all</span></span> <span class="line"><span style="color: #ADBAC7">public (</span><span style="color: #F69D50">active</span><span style="color: #ADBAC7">)</span></span> <span class="line"><span style="color: #ADBAC7"> target: default</span></span> <span class="line"><span style="color: #ADBAC7"> icmp-block-inversion: no</span></span> <span class="line"><span style="color: #ADBAC7"> interfaces: ens160</span></span> <span class="line"><span style="color: #ADBAC7"> sources: </span></span> <span class="line"><span style="color: #ADBAC7"> services: cockpit dhcpv6-client http https ssh</span></span> <span class="line"><span style="color: #ADBAC7"> ports: </span></span> <span class="line"><span style="color: #ADBAC7"> protocols: </span></span> <span class="line"><span style="color: #ADBAC7"> forward: yes</span></span> <span class="line"><span style="color: #ADBAC7"> masquerade: no</span></span> <span class="line"><span style="color: #ADBAC7"> forward-ports: </span></span> <span class="line"><span style="color: #ADBAC7"> source-ports: </span></span> <span class="line"><span style="color: #ADBAC7"> icmp-blocks: </span></span> <span class="line"><span style="color: #ADBAC7"> rich rules: </span></span> <span class="line"><span style="color: #ADBAC7">[root@nginx01 ~]# </span></span> <span class="line"></span> <span class="line"></span> <span class="line"></span> |
Step 8 – The main Nginx configuration file is located at /etc/nginx/nginx.conf
. This file contains directives that affect the entire Nginx server. Directives are used to link a file to this config file when we have multiple websites or config’s that need to be loaded are defined under /etc/nginx/
conf.d directory
- The user that runs is Nginx
- The error_log is located in /var/log/nginx/error.log
- The worker connections would imply the max amount of connections the web server can take at a time
- The Access_log is located in /var/log/nginx/access.log
Our web store is in this path. Additional config files are kept in the /etc/nginx/default.d/ directory.
Step 8 – Let’s create some web content under /usr/share/nginx folder for RHEL.
1 2 3 4 5 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">echo</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">$HOSTNAME</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">></span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">usr</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">share</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">html</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">]# </span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">usr</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">share</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">html</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">nginx01</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">]# </span></span> |
Step 9 – Test the config file
1 2 3 4 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">t</span></span> <span class="line"><span style="color: #91B4D5">nginx</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">the</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">configuration</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">file</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">syntax</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ok</span></span> <span class="line"><span style="color: #91B4D5">nginx</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">configuration</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">file</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">test</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">successful</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">]# </span></span> |
Step 10 – Verify the webpage
1 2 3 4 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">curl</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span></span> <span class="line"><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">nginx01</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">]# </span></span> <span class="line"></span> |
Configure Multiple Websites on Nginx
Nginx uses multiple server block configurations to run multiple websites – ie: Shared Website Hosting.
The default server block is good for single website hosting but if we need multiple websites needs to be hoisted from the same server, we use multiple server blocks which are also known as Virtual Servers.
The objective of a server block host entry in Nginx config is to handle multiple websites from a single IP address on our Nginx VM so that a single massive VM can serve a ton of websites from it which is the principle of Shared Website Hoisting.
We will aim to set up our two hotel websites running from a single web server as shown below – www.east.ash.local and www.west.ash.local from our single server which has a single IP address of 192.168.0.17, so we must have DNS names resolving to this machine IP address or make an entry in /etc/hosts file. Each hotel branch will have its own URL as shown.
Set up the host file
1 2 3 4 5 |
<span class="line"><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">hosts</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost4</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost4</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain4</span></span> <span class="line"><span style="color: #A6ACCD">::</span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost6</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost6</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain6</span></span> <span class="line"><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">ash</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">local</span></span> <span class="line"><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">west</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">west</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">ash</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">local</span></span> |
For multiple websites, to be hoisted, create a dedicated directory for each website file and keep all the website content on those directories respectively as shown below. In this example, my east and west website files are kept separately.
For East Website, we will create the following
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<span class="line"></span> <span class="line"><span style="color: #A6ACCD"># </span><span style="color: #E4F0FB">Configure</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Directory</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">and</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">files</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">for</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">East</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Website</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">usr</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">share</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">html</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">east</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">html</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">echo</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">$HOSTNAME</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">></span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">usr</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">share</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">html</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">east</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">html</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/nginx/east/error_log</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/nginx/east/access.log</span></span> <span class="line"></span> <span class="line"></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD"># </span><span style="color: #E4F0FB">Configure</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Directory</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">and</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">files</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">for</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">West</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Website</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">usr</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">share</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">html</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">west</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">html</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">echo</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">$HOSTNAME</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">></span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">usr</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">share</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">html</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">west</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">html</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/nginx/west/error_log</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/nginx/west/access.log</span></span> <span class="line"></span> |
Open the main configuration file /etc/nginx/conf.d, we will now create two directives one for west and east and make the below changes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">d</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">ls</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">l</span></span> <span class="line"><span style="color: #E4F0FB">total</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">12</span></span> <span class="line"><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">rw</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">r</span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">r</span><span style="color: #91B4D5">--</span><span style="color: #A6ACCD">. </span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">310</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Nov</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">11</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">16</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">conf</span></span> <span class="line"><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">rw</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">r</span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">r</span><span style="color: #91B4D5">--</span><span style="color: #A6ACCD">. </span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2656</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Nov</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">11</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">12</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">45</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">default</span></span> <span class="line"><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">rw</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">r</span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">r</span><span style="color: #91B4D5">--</span><span style="color: #A6ACCD">. </span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">310</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Nov</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">11</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">16</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">west</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">conf</span></span> <span class="line"></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD"># </span><span style="color: #E4F0FB">Configuration</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">file</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">for</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">East</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Website</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">d</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">pwd</span></span> <span class="line"></span> <span class="line"><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">d</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">d</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">server</span><span style="color: #A6ACCD"> {</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">listen</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">listen</span><span style="color: #A6ACCD"> [::]:</span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">server_name</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">ash</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">local</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">location</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">=</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD"> {</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">usr</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">share</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">html</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">access_log</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/nginx/east/access.log;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">error_log</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/nginx/east/error.log;</span></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD"> }</span></span> <span class="line"><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #A6ACCD"># </span><span style="color: #E4F0FB">Configuration</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">file</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">for</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">West</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Website</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">d</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">west</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">server</span><span style="color: #A6ACCD"> {</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">listen</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">listen</span><span style="color: #A6ACCD"> [::]:</span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">server_name</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">west</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">ash</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">local</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">location</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">=</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD"> {</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">usr</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">share</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">html</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">west</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">index</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">html</span><span style="color: #A6ACCD">;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">access_log</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/nginx/west/access.log;</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">error_log</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/nginx/west/error.log;</span></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD"> }</span></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD"> }</span></span> <span class="line"></span> |
Test the config file
123 <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">nginx01</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">d</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">t</span></span><span class="line"><span style="color: #91B4D5">nginx</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">the</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">configuration</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">file</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">syntax</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ok</span></span><span class="line"><span style="color: #91B4D5">nginx</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">configuration</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">file</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">nginx</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">test</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">successfulSyntax</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">OK</span></span>Test the east and west website page
123456 <span class="line"><span style="color: #ADBAC7">[root@nginx01 conf.d]# curl east.nginx01.ash.local</span></span><span class="line"><span style="color: #ADBAC7">This is my east webserver nginx01</span></span><span class="line"><span style="color: #ADBAC7">[root@nginx01 conf.d]</span></span><span class="line"><span style="color: #ADBAC7">[root@nginx01 conf.d]# curl west.nginx01.ash.local</span></span><span class="line"><span style="color: #ADBAC7">This is my west webserver nginx01</span></span><span class="line"><span style="color: #ADBAC7">[root@nginx01 conf.d] </span></span>