网站首页 > 技术教程 正文
? 部署 Nginx
1、安装 Nginx
yum install -y nginx
2、创建必要文件夹
mkdir -p /data/log/nginx
3、启动 Nginx
nginx
? 配置 Nginx Basic Authentication
1、安装 `httpd-tools`
yum install -y httpd-tools
2、生成账号、密码
htpasswd -cb /etc/nginx/.htpasswd anoyi password
3、修改 Nginx 配置文件 `/etc/nginx/conf.d/default.conf`
server {
...
auth_basic "Administrator’s Area";
auth_basic_user_file /etc/nginx/.htpasswd;
...
}
4、重启 Nginx
nginx -s reload
?动态密码发送到钉钉
1、设置钉钉群机器人
- 参考文档:https://open-doc.dingtalk.com/microapp/serverapi2
2、动态密码推送脚本 nginx_pwd.sh
#!/bin/bash
# 账号
NGINX_USERNAME=anoyi
# UUID 动态密码
NGINX_PASSWORD=`uuidgen`
# 更新 Nginx 密码
htpasswd -cb /etc/nginx/.htpasswd $NGINX_USERNAME ${NGINX_PASSWORD//'-'/}
# 推送到钉钉
curl 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxx' \
-H 'Content-Type: application/json' \
-d "{\"msgtype\": \"text\", \"text\": {\"content\": \"账号:${NGINX_USERNAME}\n密码:${NGINX_PASSWORD//'-'/}\"}}"
# 重新加载 nginx
nginx -s reload
修改脚本权限
chmod a+x nginx_pwd.sh
推送动态密码
./nginx_pwd.sh
?定时更新密码
1、添加任务,执行命令 `crontab -e`,输入如下内容
30 9 * * 1 sh ~/nginx_pwd.sh
代表每周一 9:30 执行脚本 `nginx_pwd.sh`
2、删除任务
crontab -r
? 相关文档
- Nginx Http Basic Authtication:https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/
- Linux Crontab 定时任务:https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html
猜你喜欢
- 2024-10-06 Nginx开启chunked输出(nginx输出真正访问路径)
- 2024-10-06 基于Docker + Consul + Nginx + Consul-Template的服务负载均衡
- 2024-10-06 猪八戒网Nginx的动态服务发现演进之路
- 2024-10-06 Nginx 备忘录 - 07. 长链接与响应压缩
- 2024-10-06 NGINX Unit:一个动态Web和应用服务器
欢迎 你 发表评论:
- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)

本文暂时没有评论,来添加一个吧(●'◡'●)