{"id":111,"date":"2024-10-03T20:17:06","date_gmt":"2024-10-03T20:17:06","guid":{"rendered":"https:\/\/gratisvps.net\/blog\/?p=111"},"modified":"2024-10-03T20:26:28","modified_gmt":"2024-10-03T20:26:28","slug":"how-to-install-nginx-on-ubuntu","status":"publish","type":"post","link":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/","title":{"rendered":"How to install Nginx on Ubuntu"},"content":{"rendered":"\r\n\r\nMost lightweight web servers, such as NGINX, are popular because they have performance with low resource consumption. In this post, I will walk you through how to install and configure NGINX on Ubuntu 22.04 at its most basic form.\r\n\r\n \r\n\r\nIt is always good to update the package list before installing NGINX.\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>Step 1: Update Your System\r\n\r\nsudo apt update\r\nsudo apt upgrade -y<\/code><\/pre>\r\n \r\n\r\nStep 2: Install NGINX\r\nThe following command will install NGINX:\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo apt install nginx -y<\/code><\/pre>\r\n \r\n\r\nOnce installed, you can verify the status of NGINX, which should be active and running:\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo systemctl status nginx<\/code><\/pre>\r\n \r\n\r\nStep 3: Configure Firewall Rules\r\n\r\n \r\n\r\nIf you have enabled a firewall-like UFW-you will want to let through HTTP and HTTPS traffic.\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo ufw allow 'Nginx Full'<\/code><\/pre>\r\n \r\n\r\nYou can verify the status of UFW using:\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo ufw status<\/code><\/pre>\r\n \r\n\r\nStep 4: Test NGINX\r\n\r\n \r\n\r\nTo confirm that NGINX is running, fire up a browser and go to http:\/\/your_server_ip. You should be presented with the NGINX welcome page.\r\n\r\n \r\n\r\nStep 5: Configure NGINX\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>Create New Server Block\r\nCreate directory for your website:\r\n\r\nsudo mkdir -p \/var\/www\/mywebsite.com\/html\r\n\r\nSet permissions:\r\nsudo chown -R $USER:$USER \/var\/www\/mywebsite.com\/html\r\nCreate an HTML file:<\/code><\/pre>\r\n \r\n<pre class=\"wp-block-code\"><code>echo \"&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Welcome to My Website&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h1&gt;Hello, NGINX!&lt;\/h1&gt;\r\n&lt;\/body&gt;\r\nhtml&gt; |  \r\n\r\nsudo tee \/var\/www\/mywebsite.com\/html\/index.html<\/code><\/pre>\r\n \r\n\r\nCreate a New Server Block Configuration\r\nCreate a new configuration file:\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/nginx\/sites-available\/mywebsite.com\r\n\r\nAdd the following configuration:\r\nserver {\r\nlisten 80;\r\nserver_name mywebsite.com www.mywebsite.com;\r\nroot \/var\/www\/mywebsite.com\/html;\r\nindex index.html;<\/code><\/pre>\r\n \r\n\r\nlocation \/ {\r\ntry_files $uri $uri\/ =404;\r\n}\r\n}\r\n\r\n \r\n\r\nEnable the new server block:\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo ln -s \/etc\/nginx\/sites-available\/mywebsite.com \/etc\/nginx\/sites-enabled\/<\/code><\/pre>\r\n \r\n\r\nTesting the NGINX configuration:\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo nginx -t<\/code><\/pre>\r\n \r\n\r\nIf all is well, you can restart NGINX to reflect the changes:\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo systemctl restart nginx<\/code><\/pre>\r\n \r\n\r\nStep 6: Configure Domain Name\r\n\r\n \r\n\r\nIf you have registered a domain name, you will need to forward it to your server IP. You can confirm it using a DNS checker .\r\n\r\n \r\n\r\nStep 7: Setup SSL (Optional)\r\n\r\n \r\n\r\nTo operate securely under HTTPS, you can obtain SSL certificates using Certbot .\r\n\r\n \r\n\r\nInstall Certbot:\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo apt install certbot python3-certbot-nginx -y<\/code><\/pre>\r\n \r\n\r\nObtain and Configure SSL Certificate:\r\n\r\n \r\n<pre class=\"wp-block-code\"><code>sudo certbot --nginx -d mywebsite.com -d www.mywebsite.com<\/code><\/pre>\r\n \r\n\r\nYou will find some prompts that you need to respond to finish the installation of the SSL.\r\n\r\n \r\n\r\nCongratulations! You have set up and configured NGINX on Ubuntu 22.04! You are well capable of hosting your websites with ease. If you wish to have more configurations, you can go ahead and explore some other advanced features of NGINX documentation-such as reverse proxying, load balancing, and much more.\r\n\r\n \r\n\r\nFeel free to get in touch if you have any questions or need any further assistance!\r\n\r\n","protected":false},"excerpt":{"rendered":"<p>Most lightweight web servers, such as NGINX, are popular because they have performance with low resource consumption. In this post, I will walk you through how to install and configure NGINX on Ubuntu 22.04 at its most basic form. It is always good to update the package list before installing&hellip;<\/p>\n","protected":false},"author":1,"featured_media":112,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2],"tags":[38,37],"class_list":["post-111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","category-linux","tag-how-to-install-nginx","tag-ubuntu-nginx"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v23.6 (Yoast SEO v23.6) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to install Nginx on Ubuntu - Gratisvps.net | Blog Daily Tech Info<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to install Nginx on Ubuntu\" \/>\n<meta property=\"og:description\" content=\"Most lightweight web servers, such as NGINX, are popular because they have performance with low resource consumption. In this post, I will walk you through how to install and configure NGINX on Ubuntu 22.04 at its most basic form. It is always good to update the package list before installing&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/\" \/>\n<meta property=\"og:site_name\" content=\"Gratisvps.net | Blog Daily Tech Info\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-03T20:17:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-03T20:26:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"ariete\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ariete\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/\"},\"author\":{\"name\":\"ariete\",\"@id\":\"https:\/\/gratisvps.net\/blog\/#\/schema\/person\/cddcf8cb5192d0713c19b79425c77fc4\"},\"headline\":\"How to install Nginx on Ubuntu\",\"datePublished\":\"2024-10-03T20:17:06+00:00\",\"dateModified\":\"2024-10-03T20:26:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/\"},\"wordCount\":310,\"publisher\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg\",\"keywords\":[\"how to install nginx\",\"ubuntu nginx\"],\"articleSection\":[\"How To\",\"Linux\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/\",\"url\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/\",\"name\":\"How to install Nginx on Ubuntu - Gratisvps.net | Blog Daily Tech Info\",\"isPartOf\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg\",\"datePublished\":\"2024-10-03T20:17:06+00:00\",\"dateModified\":\"2024-10-03T20:26:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#primaryimage\",\"url\":\"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg\",\"contentUrl\":\"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg\",\"width\":1920,\"height\":1080,\"caption\":\"How to install nginx on ubuntu\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/gratisvps.net\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to install Nginx on Ubuntu\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/gratisvps.net\/blog\/#website\",\"url\":\"https:\/\/gratisvps.net\/blog\/\",\"name\":\"Gratisvps.net | Blog Daily Tech Info\",\"description\":\"Discover reliable VPS server solutions\",\"publisher\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/gratisvps.net\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/gratisvps.net\/blog\/#organization\",\"name\":\"Gratisvps.net | Blog Daily Tech Info\",\"url\":\"https:\/\/gratisvps.net\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/gratisvps.net\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/logo.png\",\"contentUrl\":\"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/logo.png\",\"width\":250,\"height\":67,\"caption\":\"Gratisvps.net | Blog Daily Tech Info\"},\"image\":{\"@id\":\"https:\/\/gratisvps.net\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/gratisvps.net\/blog\/#\/schema\/person\/cddcf8cb5192d0713c19b79425c77fc4\",\"name\":\"ariete\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/gratisvps.net\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ca385b636b0c0fe0e98479594ff50902?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ca385b636b0c0fe0e98479594ff50902?s=96&d=mm&r=g\",\"caption\":\"ariete\"},\"sameAs\":[\"https:\/\/gratisvps.net\/blog\"],\"url\":\"https:\/\/gratisvps.net\/blog\/author\/ariete\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to install Nginx on Ubuntu - Gratisvps.net | Blog Daily Tech Info","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/","og_locale":"en_US","og_type":"article","og_title":"How to install Nginx on Ubuntu","og_description":"Most lightweight web servers, such as NGINX, are popular because they have performance with low resource consumption. In this post, I will walk you through how to install and configure NGINX on Ubuntu 22.04 at its most basic form. It is always good to update the package list before installing&hellip;","og_url":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/","og_site_name":"Gratisvps.net | Blog Daily Tech Info","article_published_time":"2024-10-03T20:17:06+00:00","article_modified_time":"2024-10-03T20:26:28+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg","type":"image\/jpeg"}],"author":"ariete","twitter_card":"summary_large_image","twitter_misc":{"Written by":"ariete","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#article","isPartOf":{"@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/"},"author":{"name":"ariete","@id":"https:\/\/gratisvps.net\/blog\/#\/schema\/person\/cddcf8cb5192d0713c19b79425c77fc4"},"headline":"How to install Nginx on Ubuntu","datePublished":"2024-10-03T20:17:06+00:00","dateModified":"2024-10-03T20:26:28+00:00","mainEntityOfPage":{"@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/"},"wordCount":310,"publisher":{"@id":"https:\/\/gratisvps.net\/blog\/#organization"},"image":{"@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#primaryimage"},"thumbnailUrl":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg","keywords":["how to install nginx","ubuntu nginx"],"articleSection":["How To","Linux"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/","url":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/","name":"How to install Nginx on Ubuntu - Gratisvps.net | Blog Daily Tech Info","isPartOf":{"@id":"https:\/\/gratisvps.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#primaryimage"},"image":{"@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#primaryimage"},"thumbnailUrl":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg","datePublished":"2024-10-03T20:17:06+00:00","dateModified":"2024-10-03T20:26:28+00:00","breadcrumb":{"@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#primaryimage","url":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg","contentUrl":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/how-to-install-nginx-on-ubuntu.jpg","width":1920,"height":1080,"caption":"How to install nginx on ubuntu"},{"@type":"BreadcrumbList","@id":"https:\/\/gratisvps.net\/blog\/how-to-install-nginx-on-ubuntu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gratisvps.net\/blog\/"},{"@type":"ListItem","position":2,"name":"How to install Nginx on Ubuntu"}]},{"@type":"WebSite","@id":"https:\/\/gratisvps.net\/blog\/#website","url":"https:\/\/gratisvps.net\/blog\/","name":"Gratisvps.net | Blog Daily Tech Info","description":"Discover reliable VPS server solutions","publisher":{"@id":"https:\/\/gratisvps.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gratisvps.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/gratisvps.net\/blog\/#organization","name":"Gratisvps.net | Blog Daily Tech Info","url":"https:\/\/gratisvps.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gratisvps.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/logo.png","contentUrl":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/logo.png","width":250,"height":67,"caption":"Gratisvps.net | Blog Daily Tech Info"},"image":{"@id":"https:\/\/gratisvps.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/gratisvps.net\/blog\/#\/schema\/person\/cddcf8cb5192d0713c19b79425c77fc4","name":"ariete","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gratisvps.net\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ca385b636b0c0fe0e98479594ff50902?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ca385b636b0c0fe0e98479594ff50902?s=96&d=mm&r=g","caption":"ariete"},"sameAs":["https:\/\/gratisvps.net\/blog"],"url":"https:\/\/gratisvps.net\/blog\/author\/ariete\/"}]}},"_links":{"self":[{"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/posts\/111"}],"collection":[{"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":4,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":125,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions\/125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}