Nginx the tutorial on configuring Basic Authorization Login Service Certificate _nginx

Source: Internet
Author: User
Tags auth base64

About Basic Authorization
in HTTP, basic authorization authentication is a form of logon authentication that allows a Web browser or other client program to provide credentials in the form of a user name and password upon request.
Before sending, a colon is appended with the username and then the password is threaded, and the resulting string is then encoded with the BASE64 algorithm. For example, the user name provided is Aladdin, password is open sesame, then the result of stitching is aladdin:open sesame, and then use Base64 code, get qwxhzgrpbjpvcgvuihnlc2ftzq==. The BASE64 encoded string is eventually sent out, and the receiver decodes a string of user names and passwords separated by a colon.
Although the BASE64 algorithm encoding the user name and password is difficult to decode with the naked eye, it can be easily decoded by the computer, just as easily encoded. The purpose of encoding this step is not to be secure and private, but to convert incompatible characters in user names and passwords into character sets that are compatible with the HTTP protocol.
Advantages:

    • Very simple to use,
    • The development and debugging work is simple,
    • There is no complex page jump logic and interactive process;
    • More conducive to the initiator control.

Let's take a formal look at how to configure a basic AUTH certified download service on Nginx:

Building Users and folders
New User shareuser:
Build the Data folder and

Chown-r Shareuser:shareuser/path/to/data

Lists the files in the specified directory:
The required instruction is autoindex on, which lists all the files in the directory and can be counted recursively into subdirectories.
There are two additional instructions.

    • Autoindex_exact_size on | Off , that is, whether the file size is displayed in bytes or k/m/g
    • Autoindex_localtime on | Off Displays the file's modification time in local timezone or UTC.

Configure Basic Auth

Two instructions

    • Auth_basic "Restricted";
    • Auth_basic_user_file./passwd;

Auth_basic_user_file is a file that stores a username password. Requires HTPASSWD command to generate,

Password file generation
First you need to install

sudo apt-get install apache2-utils

Command

Htpasswd-c/path/to/passwd username

-C is to create a new file, if it is append to an existing file, do not use this option.
Follow the prompts to enter the password.
Config Sample
the test project file structure is as follows:

App
 conf
 nginx.conf
   passwd
 data

The final results are as follows:

 User Shareuser;

 server {
  listen 8011;

  root data;
  # index index.html index.htm; #关闭index, the index.html is displayed instead of listing the file

  location/{
   autoindex on;
   Autoindex_exact_size off;
   Autoindex_localtime on;

   Auth_basic "restricted";
   Auth_basic_user_file passwd
  }}
 }


Start

 

can be accessed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.