Endblc
如果有人在陪你,你又怎么会看这些文字。
Ubuntu 20.04为Nginx配置密码访问web页面

access_time
brush 68个字
whatshot 11606 ℃

apache2-utils

安装apache2-utils
apt install apache2-utils

QQ截图20220714090054.png

使用htpasswd -c /etc/nginx/pwd admin来创建一个名为admin的用户名
输入两次密码来确认
QQ截图20220714090356.png

Nginx

修改配置文件
加入字段

auth_basic "wdnmd";  #提示信息
auth_basic_user_file /etc/nginx/pwd; #密码文件的路径

QQ截图20220714091312.png

然后重启/重载nginx(随意)
systemctl restart nginx
systemctl reload nginx

效果图

QQ截图20220714091618.png

参数说明

root@C20220712131507:~# htpasswd 
Usage:
    htpasswd [-cimBdpsDv] [-C cost] passwordfile username
    htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password

    htpasswd -n[imBdps] [-C cost] username
    htpasswd -nb[mBdps] [-C cost] username password
 -c  Create a new file.
 -n  Dont update file; display results on stdout.
 -b  Use the password from the command line rather than prompting for it.
 -i  Read password from stdin without verification (for script usage).
 -m  Force MD5 encryption of the password (default).
 -B  Force bcrypt encryption of the password (very secure).
 -C  Set the computing time used for the bcrypt algorithm
     (higher is more secure but slower, default: 5, valid: 4 to 17).
 -d  Force CRYPT encryption of the password (8 chars max, insecure).
 -s  Force SHA encryption of the password (insecure).
 -p  Do not encrypt the password (plaintext, insecure).
 -D  Delete the specified user.
 -v  Verify password for the specified user.

#如无特别声明,该文章均为 Endblc 原创,转载请遵循 署名-非商业性使用 4.0 国际(CC BY-NC 4.0) 协议,即转载请注明文章来源。
#最后编辑时间为: 2022 年 11 月 17 日


create 添加新评论


account_circle
email
language
textsms





关于 DreamCat

主题名称:DreamCat | 版本:2.8.221001(LTS)

主题开发:HanFengA7 | TeddyNight | Dev-Leo | CornWorld | WhiteBearcn | DFFZMXJ

Designed by HanFengA7 Power by Typecho

Copyright © 2015-2022 by LychApe All rights reserved!

加我的QQ
加我的微博
加我的支付宝
加我的微信