首页 > 系统相关 >nginx基于用户的访问控制

nginx基于用户的访问控制

时间:2024-08-29 09:07:29浏览次数:5  
标签:访问控制 用户 auth nginx location conf basic root admin

ngx_http_auth_basic_module模块

 

实现基于用户的访问控制,使用basic机制进行用户认证
  auth_basic string | off;
  auth_basic_user_file file;

  Default: —
  Context: http, server, location, limit_except


  location /admin/ {
    auth_basic "Admin Area";
    auth_basic_user_file /etc/nginx/.ngxpasswd;
  }
用户口令文件:
1、明文文本:格式name:password:comment
2、加密文本:由htpasswd命令实现,httpd-tools包所提供

示例:

修改配置:
[[email protected] conf.d]# vi /etc/nginx/con.d/test.conf
server {
        listen 80;
        server_name www.magedu.tech;
        root /opt/testdir/;
        limit_rate 2k;

        location / {
            limit_except GET {
                allow 10.0.0.126;
                deny all;
            }
        }

        location /admin {
                auth_basic "admin area";
                auth_basic_user_file /etc/nginx/conf.d/.nginxpasswd;
        }
        location /image {
        alias /opt/image/;
        try_files $uri $uri/tree.jpg =404;
        }
        error_page 404 =200 /404.html;
        location = /test.html {
        }
}
创建默认index
[[email protected] conf.d]# mkdir /opt/testdir/admin
[[email protected] conf.d]# echo /opt/testdir/admin/index.html >/opt/testdir/admin/index.html
htpasswd创建安全访问用户:
[[email protected] conf.d]# htpasswd -c .nginxpasswd bob                     #-c  第一次创建
New password: 
Re-type new password: 
Adding password for user bob
[[email protected] conf.d]# htpasswd -b .nginxpasswd alice centos            #-b  追加
Adding password for user alice

验证:

 

 

 

 

标签:访问控制,用户,auth,nginx,location,conf,basic,root,admin
From: https://www.cnblogs.com/cnblogsfc/p/14475300.html

相关文章

  • nginx日志格式
    ngx_http_log_modulengx_http_log_module模块指定日志格式记录请求log_formatnamestring...;string可以使用nginx核心模块及其它模块内嵌的变量Default:log_formatcombined"...";Context: httpaccess_logpath[format[buffer=size][gzip[=level]......
  • nginx第三方模块echo和变量
    第三方模块:echo第三模块是对nginx的功能扩展,第三方模块需要在编译安装nginx的时候使用参数--add-module=PATH指定路径添加,有的模块是由公司的开发人员针对业务需求定制开发的,有的模块是开源爱好者开发好之后上传到github进行开源的模块,nginx支持第三方模块,需要重新编译源码......
  • nginx输出nginx的基本状态信息
    输出nginx的基本状态信息模块:ngx_http_stub_status_module输出信息示例:Activeconnections:291server   accepts  handled  requests#下面三个数分别对应accepts,handled,requests      166309481663094831070465Reading:6Writing:179Wait......
  • nginx 压缩gzip
    ngx_http_gzip_modulengx_http_gzip_module用gzip方法压缩响应数据,节约带宽gzipon|off;启用或禁用gzip压缩Default: gzipoff;Context: http,server,location,ifinlocationgzip_comp_levellevel;消耗CPU 压缩比由低到高:1到9,默认:1 gzip_di......
  • nginx favicon.ico
    favicon.ico文件是浏览器收藏网址时显示的图标,当使用浏览器访问页面时,浏览器会自己主动发起请求获取页面的favicon.ico文件,但是当浏览器请求的favicon.ico文件不存在时,服务器会记录404日志,而且浏览器也会显示404报错(F12查看浏览器请求情况) 解决方案:1、不加favicon.ico......
  • nginx之ssl认证(https访问)
    ngx_http_ssl_modulengx_http_ssl_module模块:sslon|off;为指定虚拟机启用HTTPSprotocol,建议用listen指令代替ssl_certificatefile; 当前虚拟主机使用PEM格式的证书文件ssl_certificate_keyfile;......
  • nginx
    一、I/O模型二、nginx概述官网:http://nginx.org 2.1、nginx介绍nginx:engineX,是由1994年毕业于俄罗斯国立莫斯科鲍曼科技大学的同学为俄罗斯rambler.ru公司开发的,开发工作最早从2002年开始,第一次公开发布时间是2004年10月4日,版本号是0.1.0nginx......
  • Nginx 的编译并打包成二.txt
    Nginx的编译并打包成二进制文件是一个涉及源代码编译和静态链接的过程。‌下面是一个简单的步骤说明,‌帮助你从源代码编译Nginx并生成一个可独立运行的二进制文件。‌安装依赖首先,‌确保你的系统上安装了编译Nginx所需的依赖项。‌对于大多数Linux发行版,‌你可能需要安......
  • 利用api方式部署流式接口到nginx服务器,api无法流式输出,但localhost和ip可以的问题
    需要在nginx代理中,配置:proxy_cacheoff;#关闭缓存proxy_bufferingoff;#关闭代理缓冲chunked_transfer_encodingon;#开启分块传输编码tcp_nopushon;#开启TCPNOPUSH选项,禁止Nagle算法tcp_nodelayon;#开启TCPNODELAY选项,禁止延迟ACK算法keepalive_t......
  • 防范SSL协议降级攻击:Nginx负载均衡的安全策略
    引言在网络安全领域,SSL/TLS协议降级攻击是一种常见的攻击手段,攻击者通过诱导客户端使用较低版本的SSL/TLS协议,利用已知的安全漏洞来截取或篡改通信内容。Nginx作为广泛使用的Web服务器和反向代理,提供了多种配置选项来防范此类攻击。本文将详细介绍SSL协议降级攻击的原理、N......