{"id":837,"date":"2022-06-01T12:11:48","date_gmt":"2022-06-01T12:11:48","guid":{"rendered":"https:\/\/www.checkmateq.com\/blog\/?p=837"},"modified":"2023-08-07T09:06:34","modified_gmt":"2023-08-07T09:06:34","slug":"install-nginx","status":"publish","type":"post","link":"https:\/\/www.checkmateq.com\/blog\/install-nginx","title":{"rendered":"How to install nginx web server on linux"},"content":{"rendered":"<p><strong>Nginx<\/strong> is an open-source high-performance <strong><a href=\"https:\/\/www.checkmateq.com\/mean-stack-development\">web<\/a> server<\/strong> created by Igor Sysoev. It is also used for <strong>reverse proxy<\/strong>, <strong>mail proxy<\/strong>,\u00a0 <strong>load balancing<\/strong>, <strong>caching<\/strong>, and <strong>media streaming<\/strong>.<\/p>\n<p>Nginx is one of the most used web server because of its <strong>high performance<\/strong>, <strong>speed,<\/strong> and <strong>low memory consumption<\/strong>. It can handle around 10000 simultaneous connections with a very low memory input.<\/p>\n<h3>\u00a0\u00a0Steps to install Nginx :<\/h3>\n<ul>\n<li>Install EPEL repository on your server.<\/li>\n<\/ul>\n<pre>sudo yum install -y epel-release\r\n<\/pre>\n<ul>\n<li>Use yum command to install Nginx.<\/li>\n<\/ul>\n<pre>sudo yum install nginx\r\n<\/pre>\n<ul>\n<li>Start Nginx with systemctl command.<\/li>\n<\/ul>\n<pre>sudo systemctl start nginx\r\n<\/pre>\n<ul>\n<li>To check Nginx&#8217;s status, use systemctl status.<\/li>\n<\/ul>\n<pre>sudo systemctl status nginx\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-856\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151250-300x87.png\" alt=\" nginx \" width=\"741\" height=\"215\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151250-300x87.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151250-1024x297.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151250-768x223.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151250-1536x446.png 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151250-1200x348.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151250.png 1561w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li>Configure the firewall to allow HTTP and HTTPS traffic.<\/li>\n<\/ul>\n<pre>sudo firewall-cmd --permanent --zone=public --add-service=http\r\nsudo firewall-cmd --permanent --zone=public --add-service=https\r\nsudo firewall-cmd --reload\r\n<\/pre>\n<ul>\n<li>Go to your browser and verify if Nginx is running by visiting your server&#8217;s public IP. You would see the default Nginx webpage.<\/li>\n<\/ul>\n<pre>http:\/\/server-public-IP\/\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-860\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151752-300x94.png\" alt=\"\" width=\"744\" height=\"233\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151752-300x94.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151752-1024x320.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151752-768x240.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151752-1536x481.png 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151752-1200x375.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-151752.png 1873w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<h3>The following are the steps to deploy a web application on Nginx:<\/h3>\n<ul>\n<li>Navigate to the configuration file for Nginx.<\/li>\n<\/ul>\n<pre>sudo vi \/etc\/nginx\/nginx.conf\r\n<\/pre>\n<ul>\n<li>Look for server block in file.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-863\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-162159-300x165.png\" alt=\" nginx \" width=\"738\" height=\"406\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-162159-300x165.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-162159-768x423.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-162159.png 955w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li>In the root directive, specify the location of your HTML file. The default location is where Nginx webpage html file is present. The default listening port is 80 which can be changed according to the use case.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-865\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-163804-300x149.png\" alt=\"\" width=\"739\" height=\"367\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-163804-300x149.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-163804-768x381.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-163804.png 807w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li>We have changed the root location to \/var\/www\/html. Now restart Nginx.<\/li>\n<\/ul>\n<pre>sudo systemctl reload nginx\r\n\r\nsudo systemctl restart nginx\r\n<\/pre>\n<ul>\n<li>Now visit your server&#8217;s public IP from the browser. You will see your application.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-867\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-164642-300x108.png\" alt=\"\" width=\"714\" height=\"257\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-164642-300x108.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-164642-768x277.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-164642.png 1000w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<h3>Steps to enable password protection in Nginx:<\/h3>\n<ul>\n<li>Create a .htpasswd file with the command below.<\/li>\n<\/ul>\n<pre>sudo htpasswd -c \/etc\/nginx\/.htpasswd 'username'\r\n<\/pre>\n<ul>\n<li>Enter password when prompted.<\/li>\n<li>Open configuration file.<\/li>\n<\/ul>\n<pre>sudo vi \/etc\/nginx\/nginx.conf\r\n<\/pre>\n<ul>\n<li>Add following code in location directive in server block.<\/li>\n<\/ul>\n<pre> auth_basic \"Restricted Content\";\r\n auth_basic_user_file \/etc\/nginx\/.htpasswd;\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-872\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-184516-300x190.png\" alt=\" nginx \" width=\"744\" height=\"471\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-184516-300x190.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-184516-768x486.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-184516.png 919w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li>Restart Nginx.<\/li>\n<\/ul>\n<pre>sudo systemctl reload nginx\r\nsudo systemctl restart nginx\r\n<\/pre>\n<ul>\n<li>Go to your browser and visit your application, you will see a prompt asking for a username and password.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-876\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-185057-300x199.png\" alt=\" nginx \" width=\"742\" height=\"492\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-185057-300x199.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-01-185057.png 481w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><a href=\"https:\/\/www.checkmateq.com\/contact-us\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Call us<\/strong><\/a> to have a conversation with our technical consultant to talk about your infrastructure management optimization or offshore <a href=\"https:\/\/www.checkmateq.com\/cloud\">cloud<\/a> infrastructure support team.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx is an open-source high-performance web server created by Igor Sysoev. It is also used for reverse proxy, mail proxy,\u00a0 load balancing, caching, and media streaming. Nginx is one of the most used web server because of its high performance, speed, and low memory consumption. It can handle around 10000 simultaneous connections with a very &hellip; <a href=\"https:\/\/www.checkmateq.com\/blog\/install-nginx\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to install nginx web server on linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":869,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[3,2,11,8,14,6],"_links":{"self":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/837"}],"collection":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/comments?post=837"}],"version-history":[{"count":27,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/837\/revisions"}],"predecessor-version":[{"id":4332,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/837\/revisions\/4332"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media\/869"}],"wp:attachment":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media?parent=837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/categories?post=837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/tags?post=837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}