{"id":330,"date":"2024-10-26T10:17:55","date_gmt":"2024-10-26T10:17:55","guid":{"rendered":"https:\/\/host2day.in\/blog\/?p=330"},"modified":"2024-10-26T10:17:55","modified_gmt":"2024-10-26T10:17:55","slug":"nginx-on-a-vps-a-beginners-installation-guide","status":"publish","type":"post","link":"https:\/\/host2day.in\/blog\/nginx-on-a-vps-a-beginners-installation-guide\/","title":{"rendered":"Nginx on a VPS: A Beginner&#8217;s Installation Guide"},"content":{"rendered":"<figure style=\"width: 1024px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1024\/1*CUJLcVrBP73sPMuL05AM9w.png\" alt=\"Nginx on a VPS\" width=\"1024\" height=\"1024\" \/><figcaption class=\"wp-caption-text\">Nginx on a VPS<\/figcaption><\/figure>\n<h1>Nginx on a VPS: A Beginner&#8217;s Installation Guide<\/h1>\n<p>If you\u2019re looking to <a href=\"https:\/\/www.host2day.in\/linux-hosting\/\">host your website<\/a> or application with speed and efficiency, Nginx is one of the best web servers to consider. This guide will walk you through the process of installing Nginx on a <a href=\"https:\/\/www.host2day.in\/linux-vps-hosting\/\">Virtual Private Server (VPS)<\/a>, making it easy even for beginners. Let\u2019s get started!<\/p>\n<h4>Prerequisites<\/h4>\n<p>Before you begin, make sure you have the following:<\/p>\n<ol>\n<li><strong>VPS Access<\/strong>: You need a VPS with SSH access. Providers like <a href=\"https:\/\/www.squarebrothers.com\/vps-hosting-india\/\" target=\"_blank\" rel=\"noopener\">Squarebrothers<\/a>, Linode, or AWS are popular choices.<\/li>\n<li><strong>Basic Knowledge of Command Line<\/strong>: Familiarity with terminal commands will be helpful.<\/li>\n<li><strong>Operating System<\/strong>: This guide assumes you are using a Linux distribution, such as <a href=\"https:\/\/www.squarebrothers.com\/cloudlinux-vps-hosting-india\/\" target=\"_blank\" rel=\"noopener\">Ubuntu<\/a>.<\/li>\n<\/ol>\n<h4>Step 1: Connect to Your VPS<\/h4>\n<p>First, you\u2019ll need to connect to your VPS via SSH. Open your terminal and run:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">ssh username@your_vps_ip<br \/>\n<\/code><\/div>\n<\/div>\n<p>Replace <code>username<\/code> with your actual username and <code>your_vps_ip<\/code> with the IP address of your VPS.<\/p>\n<h4>Step 2: Update Your System<\/h4>\n<p>Before installing Nginx, it\u2019s good practice to update your system packages. Run the following commands:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo apt update<br \/>\nsudo apt upgrade -y<br \/>\n<\/code><\/div>\n<\/div>\n<h4>Step 3: Install Nginx<\/h4>\n<p>Now, it\u2019s time to install Nginx. You can do this with a simple command:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo apt install nginx -y<br \/>\n<\/code><\/div>\n<\/div>\n<p>This command will download and install Nginx and its dependencies.<\/p>\n<h4>Step 4: Start and Enable Nginx<\/h4>\n<p>After installation, you\u2019ll want to start the Nginx service and ensure it runs on boot:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo systemctl start nginx<br \/>\nsudo systemctl <span class=\"hljs-built_in\">enable<\/span> nginx<br \/>\n<\/code><\/div>\n<\/div>\n<h4>Step 5: Check Nginx Status<\/h4>\n<p>To verify that Nginx is running, check its status with:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo systemctl status nginx<br \/>\n<\/code><\/div>\n<\/div>\n<p>You should see a message indicating that Nginx is active (running).<\/p>\n<h4>Step 6: Configure Firewall<\/h4>\n<p>If you have a firewall running (like UFW), you\u2019ll need to allow Nginx traffic. You can do this with:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo ufw allow <span class=\"hljs-string\">'Nginx Full'<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>This command opens the necessary ports for HTTP and HTTPS traffic.<\/p>\n<h4>Step 7: Access Nginx in Your Browser<\/h4>\n<p>Now that Nginx is installed and running, you can check it from your web browser. Simply enter your VPS\u2019s IP address in the address bar:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">arduino<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-arduino\">http:<span class=\"hljs-comment\">\/\/your_vps_ip<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>If everything is set up correctly, you should see the Nginx welcome page.<\/p>\n<h4>Step 8: Basic Configuration (Optional)<\/h4>\n<p>To configure Nginx for your specific site, you\u2019ll need to edit the default configuration file. Use your preferred text editor (like <code>nano<\/code> or <code>vim<\/code>):<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo nano \/etc\/nginx\/sites-available\/default<br \/>\n<\/code><\/div>\n<\/div>\n<p>In this file, you can change the server block settings to point to your website files. After making changes, save the file and exit.<\/p>\n<h4>Step 9: Test Configuration and Restart Nginx<\/h4>\n<p>Before applying the changes, test the configuration for any syntax errors:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo nginx -t<br \/>\n<\/code><\/div>\n<\/div>\n<p>If there are no errors, restart Nginx to apply the changes:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo systemctl restart nginx<br \/>\n<\/code><\/div>\n<\/div>\n<h4>Conclusion<\/h4>\n<figure style=\"width: 800px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/media.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyb5qth5nbw3oyflmr0tm.png\" alt=\"Nginx on a VPS\" width=\"800\" height=\"344\" \/><figcaption class=\"wp-caption-text\">Nginx on a VPS<\/figcaption><\/figure>\n<div class=\"WaaZC\">\n<div class=\"RJPOee EIJn2\">\n<div class=\"rPeykc uP58nb PZPZlf\" data-attrid=\"SGEParagraphFeedback\" data-hveid=\"CCwQAQ\" data-ved=\"2ahUKEwj36pbB6KuJAxW8-TgGHXyQGr0Qo_EKegQILBAB\">\n<p><span role=\"heading\" aria-level=\"2\">Here are some additional tips for installing Nginx:<\/span><span class=\"UV3uM\">\u00a0<\/span><\/p>\n<div class=\"NPrrbc\" data-cid=\"_icEcZ7eCJLzz4-EP_KDq6As_45\">\n<div class=\"BMebGe btku5b k0Jjg fCrZyc LwdV0e FR7ZSc OJeuxf\" tabindex=\"0\" role=\"button\" aria-label=\"Expand\" data-hveid=\"CCoQAQ\" data-ved=\"2ahUKEwj36pbB6KuJAxW8-TgGHXyQGr0Q3fYKegQIKhAB\">\n<div class=\"niO4u\">\n<div class=\"kHtcsd\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"WaaZC\">\n<div class=\"RJPOee EIJn2\">\n<ul data-hveid=\"CDYQAQ\" data-ved=\"2ahUKEwj36pbB6KuJAxW8-TgGHXyQGr0Qm_YKegQINhAB\">\n<li class=\"PZPZlf\" data-attrid=\"SGEListItem\">You can install Nginx Open Source directly from nginx.org.<span class=\"UV3uM\">\u00a0<\/span>\n<div class=\"NPrrbc\" data-cid=\"_icEcZ7eCJLzz4-EP_KDq6As_48\">\n<div class=\"BMebGe btku5b k0Jjg fCrZyc LwdV0e FR7ZSc OJeuxf\" tabindex=\"0\" role=\"button\" aria-label=\"Expand\" data-hveid=\"CC0QAQ\" data-ved=\"2ahUKEwj36pbB6KuJAxW8-TgGHXyQGr0Q3fYKegQILRAB\">\n<div class=\"niO4u\">\n<div class=\"kHtcsd\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li class=\"PZPZlf\" data-attrid=\"SGEListItem\">To configure Nginx to serve files from different directories, you can create a server block inside the http block with two location blocks.<span class=\"UV3uM\">\u00a0<\/span>\n<div class=\"NPrrbc\" data-cid=\"_icEcZ7eCJLzz4-EP_KDq6As_50\">\n<div class=\"BMebGe btku5b k0Jjg fCrZyc LwdV0e FR7ZSc OJeuxf\" tabindex=\"0\" role=\"button\" aria-label=\"Expand\" data-hveid=\"CDQQAQ\" data-ved=\"2ahUKEwj36pbB6KuJAxW8-TgGHXyQGr0Q3fYKegQINBAB\">\n<div class=\"niO4u\">\n<div class=\"kHtcsd\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li class=\"PZPZlf\" data-attrid=\"SGEListItem\">To set up a virtual host, you can create a file in the \/etc\/nginx\/sites-enabled\/ directory.<span class=\"UV3uM\">\u00a0<\/span>\n<div class=\"NPrrbc\" data-cid=\"_icEcZ7eCJLzz4-EP_KDq6As_49\">\n<div class=\"BMebGe btku5b k0Jjg fCrZyc LwdV0e FR7ZSc OJeuxf\" tabindex=\"0\" role=\"button\" aria-label=\"Expand\" data-hveid=\"CDMQAQ\" data-ved=\"2ahUKEwj36pbB6KuJAxW8-TgGHXyQGr0Q3fYKegQIMxAB\"><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"WaaZC\">\n<div class=\"RJPOee EIJn2\">\n<div class=\"rPeykc PZPZlf\" data-attrid=\"SGEParagraphFeedback\" data-hveid=\"CDkQAQ\" data-ved=\"2ahUKEwj36pbB6KuJAxW8-TgGHXyQGr0Qo_EKegQIORAB\">\n<p>Nginx is an open-source web server that&#8217;s good for load balancing, caching, and acting as a reverse proxy.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>Congratulations! You\u2019ve successfully installed Nginx on your VPS. You can now host websites, manage traffic, and explore the many features Nginx has to offer. As you grow more comfortable, consider diving deeper into configuration and optimization to make the most out of your <a href=\"https:\/\/www.squarebrothers.com\/dedicated-server-india\/\" target=\"_blank\" rel=\"noopener\">server<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx on a VPS: A Beginner&#8217;s Installation Guide If you\u2019re looking to host your website or application with speed and efficiency, Nginx is one of the best web servers to consider. This guide will walk you through the process of installing Nginx on a Virtual Private Server (VPS), making it easy even for beginners. Let\u2019s&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"default","_kad_post_title":"default","_kad_post_layout":"default","_kad_post_sidebar_id":"","_kad_post_content_style":"default","_kad_post_vertical_padding":"default","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-330","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/posts\/330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/comments?post=330"}],"version-history":[{"count":5,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/posts\/330\/revisions"}],"predecessor-version":[{"id":335,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/posts\/330\/revisions\/335"}],"wp:attachment":[{"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/media?parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/categories?post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/tags?post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}