Contents
  1. 1. 前置要求
  2. 2. 操作步骤
  3. 3. 参考文档

公司的安全团队扫描到我的系统后台直接暴露在公网,有安全问题,需要加上Basic Auth鉴权。

前置要求

需要安装httpd-tools(Centos), Debian系列需要安装apache2-utils

1
yum install -u httpd-tools

操作步骤

  1. 创建htpasswd文件
1
htpasswd -c /usr/local/nginx/conf/htpasswd admin
  1. 在nginx.conf里配置鉴权
1
2
3
4
5
6
7
8
9
10
server {
...
auth_basic "Administrator's Area";
auth_basic_user_file /usr/local/nginx/conf/htpasswd;

# 不需要开启鉴权的path设置成auth_basic off
location /test/ {
auth_basic off;
}
}

参考文档

https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/

Contents
  1. 1. 前置要求
  2. 2. 操作步骤
  3. 3. 参考文档