1 / 8

How To Configure Basic Authentication in NGINX

NGINX basic authentication allows you to protect servers, websites, virtual hosts and web pages. Here is how to configure basic authentication in NGINX. #nginx #security #authentication #apache #webdevelopment <br><br>Visit https://ubiq.co/tech-blog/how-to-configure-basic-authentication-in-nginx/

Download Presentation

How To Configure Basic Authentication 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 Configure Basic Authentication in NGINX

  2. Install Apache Utils We need to use htpasswd utility to set up basic authentication. For that, 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. # 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. For example, when we create another user, we don’t specify password file location. # htpasswd /etc/nginx/conf.d/.htpasswd developer2

  4. Open NGINX configuration file Open terminal and run the following command to open NGINX server configuration file. $ sudo vi /etc/nginx/nginx.conf

  5. Password Protect NGINX In order to password protect your website, or certain web pages, 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. You can also add it in server or location blocks. 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. Verify basic authentication Open browser and visit the URL (e.g www.example.com/admin) that you have protected. You should see an authentication screen asking for username and password.

  8. Thank You Visit for details https://ubiq.co/tech-blog/how-to-configure-basic-authentication-in-nginx/

More Related