{"id":15182,"date":"2024-12-12T11:20:05","date_gmt":"2024-12-12T11:20:05","guid":{"rendered":"https:\/\/cloudkul.com\/blog\/?p=15182"},"modified":"2024-12-12T11:20:07","modified_gmt":"2024-12-12T11:20:07","slug":"set-up-password-authentication-with-apache-nginx","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/","title":{"rendered":"Set Up Password Authentication with Apache\/Nginx"},"content":{"rendered":"\n<p>In this article, we will learn how to protect your website using a <a href=\"https:\/\/cloudkul.com\/blog\/what-is-broken-authentication-broken-access-control\/\">password authentication <\/a>feature, so that only authorized users can access the website.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<p>To complete this tutorial, you will need:<\/p>\n\n\n\n<ul>\n<li><a href=\"https:\/\/cloudkul.com\/blog\/apache-virtual-hosting-with-different-users\/\">Apache<\/a>\/<a href=\"https:\/\/cloudkul.com\/features\/nginx-integration\/\">Nginx<\/a><\/li>\n\n\n\n<li>Ubuntu OS<\/li>\n\n\n\n<li>sudo access<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CASE 1: If you are using an Apache webserver<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1 &#8211;  <\/strong>Install the Apache server and the required packages.<\/h3>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\"><div class=\"wp-block-group__inner-container\">\n<pre class=\"wp-block-preformatted\">apt-get update -y\n\napt-get install apache2 apache2-utils<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2. Creating the Password File<\/strong><\/h3>\n\n\n\n<p>The htpasswd command will allow us to create a password file that Apache can use to authenticate users. <\/p>\n\n\n\n<p>We will create a hidden file for this purpose called .htpasswd within our \/etc\/apache2 configuration directory.<\/p>\n\n\n\n<p>The first time we use this utility, we need to add the -c option to create the specified passwdfile. <\/p>\n\n\n\n<p>We specify a username (webkul in this example) at the end of the command to create a new entry within the file:<\/p>\n\n\n\n<p><\/p>\n<\/div><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo htpasswd -c \/etc\/apache2\/.htpasswd webkul<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_12-57.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"79\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_12-57-1024x79.png\" alt=\"sudo\" class=\"wp-image-15213\" style=\"width:840px;height:64px\"\/><\/a><\/figure>\n\n\n\n<p>it will ask you to set the New Password and just press enter and retype your Password<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3. Add another user<\/h3>\n\n\n\n<p> Leave out the -c argument for any additional users you wish to add so you don\u2019t overwrite the file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo htpasswd \/etc\/apache2\/.htpasswd test<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_13-15.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"58\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_13-15-1024x58.png\" alt=\"user\" class=\"wp-image-15222\"\/><\/a><\/figure>\n\n\n\n<p><strong>Now, We can see the username and encrypted password for each record: <\/strong><\/p>\n\n\n\n<p>Using below command <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cat \/etc\/apache2\/.htpasswd\nhtpascat \/etc\/apache2\/.htpasswd\n<\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_14-01.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"48\" data-id=\"15233\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_14-01-1024x48.png\" alt=\"name\" class=\"wp-image-15233\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4. Configuring Apache Password Authentication<\/h3>\n\n\n\n<p>Edit the Apache configuration and add password protection to the virtual host file<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi \/etc\/apache2\/sites-enabled\/default-ssl.conf <\/pre>\n\n\n\n<p>Copy the below lines and paste your vhost file <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;Directory \"\/var\/www\/html\"&gt;\n      AuthType Basic\n      AuthName \"Restricted Content\"\n      AuthUserFile \/etc\/apache2\/.htpasswd\n      Require valid-user\n  &lt;\/Directory&gt;\n<\/pre>\n\n\n\n<p><strong><em><mark class=\"has-inline-color has-black-color\">Just Like this<\/mark><\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-27_10-06.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1022\" height=\"489\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-27_10-06.png\" alt=\"file\" class=\"wp-image-15381\"\/><\/a><\/figure>\n\n\n\n<p><strong>Save and close the file using Press &#8220;Esc&#8221; and<\/strong> <strong>:wq<\/strong><\/p>\n\n\n\n<p>Before restarting the web server, you can check the configuration with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> apachectl -t<\/pre>\n\n\n\n<p>If everything checks out and you get Syntax OK as output, you can restart the server<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">service apache2 restart<\/pre>\n\n\n\n<p><strong>Now, Go to the browser and hit your domain, your page will be protected with a username and password.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_14-12.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"231\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_14-12-1024x231.png\" alt=\"url\" class=\"wp-image-15249\"\/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CASE 2: If you are using Nginx <\/h2>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">You need to follow<strong> Steps 2<\/strong> and <strong>Step 3<\/strong> as mentioned above and then follow the below-mentioned steps &#8211; <\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3 &#8211;  Just copy the below content and paste it into your nginx vhost file<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">auth_basic \"Administrator\u2019s Area\";\nauth_basic_user_file \/etc\/apache2\/.htpasswd;\n\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4 &#8211; Open your nginx vhost file using the command &#8211; <\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">\/etc\/nginx\/sites-enabled\/default<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/image-81.png\"><img loading=\"lazy\" decoding=\"async\" width=\"934\" height=\"307\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/image-81.png\" alt=\"nginx\" class=\"wp-image-15260\"\/><\/a><\/figure>\n\n\n\n<p><strong>Save and close the file using Press \u201cEsc\u201d and<\/strong>&nbsp;<strong>:wq<\/strong><\/p>\n\n\n\n<p>Before restarting the web server, you can check the configuration with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nginx -t<\/pre>\n\n\n\n<p>If everything checks out and you get Syntax OK as output, you can restart the server<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">service nginx restart <\/pre>\n\n\n\n<p>Now, Go to the browser and hit your domain <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_14-12-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"231\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_14-12-1-1024x231.png\" alt=\"url\" class=\"wp-image-15263\"\/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this way, you can either project your site or you can provide limited access to the site when you are in the development phase.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Need Support?<\/h2>\n\n\n\n<p>Thank You for reading this Blog!<\/p>\n\n\n\n<p>For further more interesting blogs, keep in touch with us. If you need any kind of support, simply raise a ticket at\u00a0<strong><a href=\"https:\/\/webkul.uvdesk.com\/en\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/webkul.uvdesk.com\/en\/<\/a>.<\/strong><\/p>\n\n\n\n<p><strong>For further help or queries, please\u00a0<a href=\"https:\/\/cloudkul.com\/contact\/\" target=\"_blank\" rel=\"noreferrer noopener\">contact<\/a>\u00a0us or raise a\u00a0<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\" target=\"_blank\" rel=\"noreferrer noopener\">ticket<\/a>.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will learn how to protect your website using a password authentication <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,87,341,340],"tags":[834,358,832,829,835,833,836],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Set Up Password Authentication with Apache\/Nginx - Cloudkul<\/title>\n<meta name=\"description\" content=\"In this article, we will learn how to protect your website using a password authentication feature, so that only authorized users can access the website.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Set Up Password Authentication with Apache\/Nginx - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"In this article, we will learn how to protect your website using a password authentication feature, so that only authorized users can access the website.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-12T11:20:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-12T11:20:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_12-57-1024x79.png\" \/>\n<meta name=\"author\" content=\"Mohit Tiwari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/\",\"name\":\"Set Up Password Authentication with Apache\/Nginx - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2024-12-12T11:20:05+00:00\",\"dateModified\":\"2024-12-12T11:20:07+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/d65bf252186a357da67ead26747e47b7\"},\"description\":\"In this article, we will learn how to protect your website using a password authentication feature, so that only authorized users can access the website.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Set Up Password Authentication with Apache\/Nginx\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/d65bf252186a357da67ead26747e47b7\",\"name\":\"Mohit Tiwari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d958ee0f8ad4fe891d737cc821536709?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d958ee0f8ad4fe891d737cc821536709?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"Mohit Tiwari\"},\"url\":\"https:\/\/cloudkul.com\/blog\/author\/mohitkrtiwari-cloud767\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Set Up Password Authentication with Apache\/Nginx - Cloudkul","description":"In this article, we will learn how to protect your website using a password authentication feature, so that only authorized users can access the website.","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:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/","og_locale":"en_US","og_type":"article","og_title":"Set Up Password Authentication with Apache\/Nginx - Cloudkul","og_description":"In this article, we will learn how to protect your website using a password authentication feature, so that only authorized users can access the website.","og_url":"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/","og_site_name":"Cloudkul","article_published_time":"2024-12-12T11:20:05+00:00","article_modified_time":"2024-12-12T11:20:07+00:00","og_image":[{"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/02\/2023-02-23_12-57-1024x79.png"}],"author":"Mohit Tiwari","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/","url":"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/","name":"Set Up Password Authentication with Apache\/Nginx - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2024-12-12T11:20:05+00:00","dateModified":"2024-12-12T11:20:07+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/d65bf252186a357da67ead26747e47b7"},"description":"In this article, we will learn how to protect your website using a password authentication feature, so that only authorized users can access the website.","breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/set-up-password-authentication-with-apache-nginx\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Set Up Password Authentication with Apache\/Nginx"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/d65bf252186a357da67ead26747e47b7","name":"Mohit Tiwari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d958ee0f8ad4fe891d737cc821536709?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d958ee0f8ad4fe891d737cc821536709?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"Mohit Tiwari"},"url":"https:\/\/cloudkul.com\/blog\/author\/mohitkrtiwari-cloud767\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/15182"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=15182"}],"version-history":[{"count":56,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/15182\/revisions"}],"predecessor-version":[{"id":19011,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/15182\/revisions\/19011"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=15182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=15182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=15182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}