NGINX-Getting Started-Five (Access Control)

One: Based on the host (ip)

1.module: ngx_http_access_module
2.Directives
(1): allow: allow certain hosts
(2): deny: deny certain hosts
3.
Syntax: (1): Syntax: allow address | CIDR | unix: | all;
(2 ): Context: http, server, location, limit_except
4. Start control:
(1): Limit host access: vim /etc/nginx/conf.d/default.conf
server {
allow 10.18.45.7;
deny all;
}
NGINX-Getting Started-Five (Access Control)
(2 ): systemctl restart nginx
(3): Test to use the 10.8.162.7 host to access your website
NGINX-Getting Started-Five (Access Control)


Two, based on user (username&password)

1.module: ngx_http_auth_basic_module
2.Syntax:
(1): Method 1:
①: Syntax: auth_basic string | off;
②: Context: http, server, location, limit_except
(2): Method 2:
①: Syntax: auth_basic_user_file file;
②: Context: http, server, location, limit_except
3. Establish authentication file:
(1): yum install -y httpd-tools //The tool for generating the secret key is provided by apache
(2): htpasswd -cm /etc/nginx /conf.d/passwd xiaoliu //Session password
NGINX-Getting Started-Five (Access Control)
(3): cat /etc/nginx/conf.d/passwd //Observe whether the password file is generated.
NGINX-Getting Started-Five (Access Control)
4. Start authentication has been generated :
(1): vim /etc/nginx/conf.d/default.conf
server {
auth_basic "nginx access test!"; //Prompt information
auth_basic_user_file /etc/nginx/conf.d/passwd; //Cite certification documents

NGINX-Getting Started-Five (Access Control)

5. Restart the service: ystemctl restart nginx
6. Access verification:
NGINX-Getting Started-Five (Access Control)

Guess you like

Origin blog.51cto.com/14881339/2540112