{"id":2819,"date":"2020-12-29T04:21:11","date_gmt":"2020-12-29T04:21:11","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=2819"},"modified":"2024-06-04T11:55:50","modified_gmt":"2024-06-04T11:55:50","slug":"how-to-password-protect-directory-in-nginx","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/","title":{"rendered":"How to Password Protect Directory in Nginx"},"content":{"rendered":"\n<p>Sometimes you may need to prevent unauthorized access to specific files and directories on your website. This is commonly required if you have sensitive information on your website that you do not want unauthorized users to access. For this, you can easily set up basic authentication for those directories in NGINX. It allows you to quickly password protect one or more files, URLs or directories without changing any code of your site. In this article, we will look at how to password protect directory in NGINX.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#How_to_Password_Protect_Directory_in_Nginx\" >How to Password Protect Directory in Nginx<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#1_Install_Apache_Utils\" >1. Install Apache Utils<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#2_Create_UserPassword\" >2. Create User\/Password<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#4_Enter_Password\" >4. Enter Password<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#5_Open_NGINX_configuration_file\" >5. Open NGINX configuration file<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#6_Password_Protect_NGINX\" >6. Password Protect NGINX<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#Password_Protect_All_Websites\" >Password Protect All Websites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#Password_Protect_Single_Website_or_Domain\" >Password Protect Single Website or Domain<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#Password_Protect_Directory_or_Subdirectory\" >Password Protect Directory or Subdirectory<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#7_Restart_NGINX_Server\" >7. Restart NGINX Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#8_Verify_basic_authentication\" >8. Verify basic authentication<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Password_Protect_Directory_in_Nginx\"><\/span>How to Password Protect Directory in Nginx<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the steps to password protect directory in NGINX. We will require htpasswd utility to generate username-password pairs that will be used for user authentication. Although it is available in Apache server by default, we will need to install an add-on for this purpose in NGINX.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Install_Apache_Utils\"><\/span>1. Install Apache Utils<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We need to install apache2-utils\u00a0(Ubuntu\/Debian) or\u00a0httpd-tools (RHEL\/CentOS) that provide htpasswd utility. Open terminal and run the following command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># yum install httpd-tools [RHEL\/CentOS] \n$ sudo apt install apache2-utils [Debian\/Ubuntu]<\/pre>\n\n\n\n<p>Also read : <a href=\"https:\/\/ubiq.co\/tech-blog\/nginx-restrict-access-to-directory-and-subdirectories\/\">NGINX Restrict Access to Directory and Subdirectories<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Create_UserPassword\"><\/span>2. Create User\/Password<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Next, run\u00a0<em>htpasswd<\/em>\u00a0command to create a user that you want to give access to your website. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">htpasswd -c \/path\/to\/password\/file username<\/pre>\n\n\n\n<p>Replace <em>developer<\/em> below with your choice of username and \/etc\/nginx\/conf.d\/.htpasswd with the path to password file where you want to store user credentials.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># htpasswd -c \/etc\/nginx\/conf.d\/.htpasswd developer<\/pre>\n\n\n\n<p>We use -c option to specify password file location for the first user. <\/p>\n\n\n\n<p>Please note, when we create another user, we don\u2019t specify password file location.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># htpasswd \/etc\/nginx\/conf.d\/.htpasswd developer2<\/pre>\n\n\n\n<p>Also read : <a href=\"https:\/\/ubiq.co\/tech-blog\/nginx-restrict-access-to-url\/\">NGINX Restrict Access to URL<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Enter_Password\"><\/span>4. Enter Password<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>After you enter htpasswd command, you will be asked to enter password and confirm it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">New password: <br>Re-type new password: <br>Adding password for user developer<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Open_NGINX_configuration_file\"><\/span>5. Open NGINX configuration file<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can make changes to either the NGINX configuration file or virtual host file to password protect data in NGINX. Run the following command to open NGINX server configuration file in vi editor.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo vi \/etc\/nginx\/nginx.conf<\/pre>\n\n\n\n<p>If you have configured separate virtual hosts for your website (e.g&nbsp;<em>www.example.com<\/em>), such as \/etc\/nginx\/sites-enabled\/website.conf then open its configuration with the following command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo vi&nbsp;\/etc\/nginx\/sites-enabled\/website.conf<\/pre>\n\n\n\n<p>Alternatively, you can also open the default virtual host configuration file.<\/p>\n\n\n\n<pre id=\"block-d47a260a-a7b7-47b1-8b8d-d4e8e0c49519\" class=\"wp-block-preformatted\">$ sudo vi&nbsp;\/etc\/nginx\/sites-enabled\/default<\/pre>\n\n\n\n<p>Also read : <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-configure-nginx-log-rotation\/\">How to Configure NGINX Log rotation<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Password_Protect_NGINX\"><\/span>6. Password Protect NGINX<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In order to password protect your directory, or certain web pages or even your entire website, we need to use\u00a0<em>auth_basic<\/em>\u00a0and\u00a0<em>auth_basic_user_file<\/em>\u00a0directives in NGINX server configuration. auth_basic is the title of the prompt window displayed to user during authentication. auth_basic_user_file is the location of password file that is used to authenticate user credentials.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Password_Protect_All_Websites\"><\/span>Password Protect All Websites<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>For example, if you want to configure basic authentication for all virtual hosts (an entire http block) on server, add the above two directives as shown below in http block.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http{\n   ...\n   auth_basic \"Restricted Access!\"; \n   auth_basic_user_file \/etc\/nginx\/conf.d\/.htpasswd;\n   ...\n}<\/pre>\n\n\n\n<p>In the above code, we specify the path of password file in\u00a0<em>auth_basic_user_file<\/em>\u00a0directive and message to be displayed in\u00a0<em>auth_basic<\/em>\u00a0directive.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Password_Protect_Single_Website_or_Domain\"><\/span>Password Protect Single Website or Domain<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Similarly, here\u2019s the code to protect\u00a0<em>server<\/em>\u00a0block. It will implement basic authentication for website or domain.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">server{\n    ...\n    auth_basic \"Restricted Access!\";\n    auth_basic_user_file \/etc\/nginx\/conf.d\/.htpasswd;\n    ...\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Password_Protect_Directory_or_Subdirectory\"><\/span>Password Protect Directory or Subdirectory<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You can also configure basic authentication for specific web directories\/subdirectories (e.g \/admin) by adding\u00a0<em>auth_basic<\/em>\u00a0and\u00a0<em>auth_basic_user_file<\/em>\u00a0directives in a location block for that directory.<\/p>\n\n\n\n<pre id=\"block-83d3cdd4-ec9a-4640-8c41-34d89cb9ac6b\" class=\"wp-block-preformatted\">location \/admin\/ {\n    ...\n    auth_basic \"Restricted Access!\";\n    auth_basic_user_file \/etc\/nginx\/conf.d\/.htpasswd;\n    ...\n}<\/pre>\n\n\n\n<p>The above code will enable password protection only for \/admin directory. If you want to add authentication for more folders, add auth_basic and auth_basic_user_file directives to their location blocks also. <\/p>\n\n\n\n<p>Also read : <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-fix-nginx-worker-connections-are-not-enough\/\">How to Fix NGINX Worker Connections Not Enough<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_Restart_NGINX_Server\"><\/span>7. Restart NGINX Server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Run the following command to check syntax of your updated config file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo nginx -t<\/pre>\n\n\n\n<p>If there are no errors, run the following command to restart NGINX server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo service nginx reload #debian\/ubuntu\n$ systemctl restart nginx #redhat\/centos<\/pre>\n\n\n\n<p>Also read : <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-disable-etag-in-nginx\/\">How to Disable ETag in NGINX<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_Verify_basic_authentication\"><\/span>8. Verify basic authentication<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Open browser and visit the URL (e.g www.example.com\/admin) that you have protected. You should see an authentication screen as the one below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"431\" src=\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/11\/Nginx-Basic-Authentication.png?resize=730%2C431&#038;ssl=1\" alt=\"\" class=\"wp-image-2382\" srcset=\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/11\/Nginx-Basic-Authentication.png?w=793&amp;ssl=1 793w, https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/11\/Nginx-Basic-Authentication.png?resize=768%2C453&amp;ssl=1 768w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt how to password protect directory in NGINX. The key is to generate a password file using utility such as htpasswd. Then add auth_basic and auth_basic_user_file directives in the location, server or http blocks where you want the authentication to be done. It is a good practice to protect sensitive files, documents, URLs and directives on your website using this method. It allows website administrators to control access by changing server configuration, without any coding.<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/\">Ubiq<\/a>\u00a0makes it easy to visualize data, and monitor them in real-time dashboards.\u00a0<a href=\"https:\/\/ubiq.co\/accounts\/register\">Try Ubiq<\/a>\u00a0for free.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to secure directories and files in NGINX. Here is how to password protect directory in NGINX.<\/p>\n","protected":false},"author":1,"featured_media":2823,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[14],"class_list":["post-2819","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nginx","tag-password-protect"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Password Protect Directory in Nginx - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to secure directories and files in NGINX. Here is how to password protect directory in NGINX.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Password Protect Directory in Nginx - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to secure directories and files in NGINX. Here is how to password protect directory in NGINX.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-29T04:21:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-04T11:55:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Password Protect Directory in Nginx\",\"datePublished\":\"2020-12-29T04:21:11+00:00\",\"dateModified\":\"2024-06-04T11:55:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/\"},\"wordCount\":768,\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png?fit=1200%2C900&ssl=1\",\"keywords\":[\"password protect\"],\"articleSection\":[\"Nginx\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/\",\"name\":\"How to Password Protect Directory in Nginx - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png?fit=1200%2C900&ssl=1\",\"datePublished\":\"2020-12-29T04:21:11+00:00\",\"dateModified\":\"2024-06-04T11:55:50+00:00\",\"author\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to secure directories and files in NGINX. Here is how to password protect directory in NGINX.\",\"breadcrumb\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png?fit=1200%2C900&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png?fit=1200%2C900&ssl=1\",\"width\":1200,\"height\":900,\"caption\":\"NGINX password protect directory\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ubiq.co\/tech-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Password Protect Directory in Nginx\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/\"],\"url\":\"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Password Protect Directory in Nginx - Ubiq BI","description":"Sometimes you may need to secure directories and files in NGINX. Here is how to password protect directory in NGINX.","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:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/","og_locale":"en_US","og_type":"article","og_title":"How to Password Protect Directory in Nginx - Ubiq BI","og_description":"Sometimes you may need to secure directories and files in NGINX. Here is how to password protect directory in NGINX.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2020-12-29T04:21:11+00:00","article_modified_time":"2024-06-04T11:55:50+00:00","og_image":[{"width":1200,"height":900,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png","type":"image\/png"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Password Protect Directory in Nginx","datePublished":"2020-12-29T04:21:11+00:00","dateModified":"2024-06-04T11:55:50+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/"},"wordCount":768,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png?fit=1200%2C900&ssl=1","keywords":["password protect"],"articleSection":["Nginx"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/","name":"How to Password Protect Directory in Nginx - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png?fit=1200%2C900&ssl=1","datePublished":"2020-12-29T04:21:11+00:00","dateModified":"2024-06-04T11:55:50+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to secure directories and files in NGINX. Here is how to password protect directory in NGINX.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png?fit=1200%2C900&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png?fit=1200%2C900&ssl=1","width":1200,"height":900,"caption":"NGINX password protect directory"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Password Protect Directory in Nginx"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/12\/nginx-password-protect-directory.png?fit=1200%2C900&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-Jt","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/2819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=2819"}],"version-history":[{"count":14,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/2819\/revisions"}],"predecessor-version":[{"id":3302,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/2819\/revisions\/3302"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/2823"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=2819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=2819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=2819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}