nginx auth_basic

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx auth_basic相关的知识,希望对你有一定的参考价值。

参考技术A nginx的简单鉴权
使用nginx搭建的web服务,需要限制访问,但是构建用户系统又过于繁琐时,可考虑使用nginx的auth_basic进行简单鉴权

Debian系统一般安装apache后已经带入,如果命令不存在尝试 apt-get install apache2-utils 命令安装

这个可以给swagger等页面做简单的鉴权。防止接口直接公开外露

nginx

安装htpasswd

htpasswd是Apache密码生成工具,Nginx支持auth_basic认证,因此我门可以将生成的密码用于Nginx中,输入一行命令即可安装:yum -y install httpd-tools ,参数如下:

 

htpasswd -c ./passwd username

 

server{
    listen 80;
    server_name xxxx;

    location / {
        auth_basic "登陆验证";
        auth_basic_user_file /etc/nginx/passwd;
        proxy_pass http://127.0.0.1:9090/;
    }
}

  

以上是关于nginx auth_basic的主要内容,如果未能解决你的问题,请参考以下文章

死磕nginx系列

Nginx一Nginx服务器搭建

nginx 如何检测配置文件的正确性

nginx安装和常见的配置

nginx简介

Nginx 学习导航