1 / 7

How to Password Protect Directory in NGINX

Sometimes you may need to secure directories and files in NGINX. Here is how to password protect directory in NGINX.<br><br>Visit https://ubiq.co/tech-blog/how-to-password-protect-directory-in-nginx/

Download Presentation

How to Password Protect Directory in NGINX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to Password Protect Directory in Nginx

  2. Install Apache Utils We need to use htpasswd utility to password protect files and directories in NGINX. So we need to install apache2-utils or httpd-tools. Open terminal and run the following command # yum install httpd-tools [RHEL/CentOS] $ sudo apt install apache2-utils [Debian/Ubuntu]

  3. Create User/Password Next, run htpasswd command to create a user that will be given access to your website. Replace developer below with your choice of username. # htpasswd -c /etc/nginx/conf.d/.htpasswd developer We use -c option to specify password file location. When you press enter, you will be prompted for a password.

  4. Open NGINX configuration file Open terminal and run the following command to open NGINX server configuration file. $ sudo vi /etc/nginx/nginx.conf If you have configured separate virtual hosts for your website (e.g www.example.com), such as /etc/nginx/sites-enabled/website.conf then open its configuration with the following command $ sudo vi /etc/nginx/sites-enabled/website.conf Alternatively, you can also open the default virtual host configuration file. $ sudo vi /etc/nginx/sites-enabled/default

  5. Password Protect NGINX In order to password protect your directory, or certain web pages or even your entire website, we need to use auth_basic and auth_basic_user_file directives in NGINX server configuration. For example, if you want to configure basic authentication for virtual hosts (an entire http block), add the above two directives as shown below in http block. http{ ... auth_basic "Restricted Access!"; auth_basic_user_file /etc/nginx/conf.d/.htpasswd; ... }

  6. Restart NGINX Server Run the following command to check syntax of your updated config file. $ sudo nginx -t If there are no errors, run the following command to restart NGINX server. $ sudo service nginx reload #debian/ubuntu $ systemctl restart nginx #redhat/centos

  7. Thank You Visit for details https://ubiq.co/tech-blog/how-to-password-protect-directory-in-nginx/

More Related