nginx访问控制

最近部署consul服务,发现consul认证配置比较麻烦,于是上网查询发现nginx支持路由认证,在此做个记录。

1.Nginx访问控制模块类型

  • 基于IP的访问控制:http_access_module
  • 基于用户的信任登录:http_auth_basic_module

2.建立口令文件

[root@monitor12011 conf]# yum -y install httpd-tools
[root@monitor12011 conf]# htpasswd -cm /usr/local/nginx/conf/auth_conf admin //第一次创建用户
New password: 
Re-type new password: 
Adding password for user admin
# 第二次创建用: htpasswd -m  /usr/local/nginx/conf/auth_conf user2

3.用户信用设置

server {
     listen 80;
     server_name localhost;
     # consul注册、注销、页面显示详情
     location ~ ^/(v1/agent/service|v1/health/service|v1/discovery-chain){
         proxy_pass http://xx.xx.xx.xx:8500;
         auth_basic "Auth access test!";
         auth_basic_user_file /usr/local/nginx/conf/auth_conf;
    }
}

4.python访问权限路由

requests.put(f"xxxx/v1/agent/service/register",
json=json.loads(params), auth=("admin", "xxx"), verify=False)

5.页面显示效果

在这里插入图片描述

相关推荐

  1. Nginx访问控制

    2024-07-11 06:06:05       50 阅读
  2. nginx访问控制

    2024-07-11 06:06:05       35 阅读
  3. nginx访问控制

    2024-07-11 06:06:05       27 阅读
  4. Nginx访问控制模块详解

    2024-07-11 06:06:05       44 阅读
  5. 用Lua控制Nginx静态文件的url访问权限

    2024-07-11 06:06:05       30 阅读
  6. ACL访问控制列表

    2024-07-11 06:06:05       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 06:06:05       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 06:06:05       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 06:06:05       57 阅读
  4. Python语言-面向对象

    2024-07-11 06:06:05       68 阅读

热门阅读

  1. Sqlmap中文使用手册 - Target模块参数使用

    2024-07-11 06:06:05       27 阅读
  2. Grind 75 - Leetcode146 LRU缓存

    2024-07-11 06:06:05       25 阅读
  3. vue3 学习笔记02 -- 配置路由router+导航守卫

    2024-07-11 06:06:05       26 阅读
  4. Win11安装WSL2在非系统盘(非C盘)+图形化界面

    2024-07-11 06:06:05       24 阅读
  5. c语言指针

    2024-07-11 06:06:05       20 阅读
  6. Mojo模板引擎:释放Web开发的无限潜能

    2024-07-11 06:06:05       19 阅读
  7. ffmpeg 文档 - 未完

    2024-07-11 06:06:05       20 阅读