基于主机(IP)
  1. module ngx_http_access_module
  2. directiver allow #允许 deny #拒接
  3. syntax #allow address |CIDR |UNIX: |ALL;
  4. Context: http,server,location,limit_except
  5. 案例:
  6. server {
  7. allow 192.168.8.1;
  8. allow 192.168.7.*;
  9. deny all;
  10. }

基于用户 auth:认证 basic:基本
  1. module ngx_http_auth_basic_module
  2. syntax: auth_basic_user_file file;
  3. Context: http,server,location,limit_excep
  4. #案列
  5. htpasswd -cm /etc/nginx/conf.d/passwd user10
  6. -c 创造
  7. -m 加密
  8. /etc/nginx/conf.d/passwd 创建到那个文件,如果有这个文件就可以不加 - c
  9. 用那个网站就在那个网站创建
  10. #案例
  11. vim /etc/nginx/conf.d/default.conf
  12. server {
  13. auth_basic "欢迎来到身份验证页面:p"; #提示信息
  14. auth_basic_user_file /etc/nginx/conf.d/passwd ; #存密码
  15. }