Nginx添加htpasswd认证
参考:
http://blog.csdn.net/longxibendi/article/details/23954017
http://tool.oschina.net/htpasswd
http://www.letuknowit.com/post/12.html
在Linux上编写脚本(注意权限,对脚本做了一些修改):
vi htpasswd.sh
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo "====================================="
echo "# A tool like htpasswd for Nginx #"
echo "#-----------------------------------#"
echo "# Author:Licess http://blog.csdn.net/longxibendi #"
echo "====================================="
workdir="/nginx/user/conf"
#set UserName
username=""
read -p "Please input UserName:" username
if [ "$username" = "" ]; then
echo "Error:UserName can't be NULL!"
exit 1
fi
echo "==========================="
echo "UserName was: $username"
echo "==========================="
#set password
unpassword=""
read -p "Please input the Password:" unpassword
if [ "$unpassword" = "" ]; then
echo "Error:Password can't be NULL!"
exit 1
fi
echo "==========================="
echo "Password was: $unpassword"
echo "==========================="
password=$(perl -e 'print crypt($ARGV[0], "pwdsalt")' $unpassword)
#set htpasswd file
htfile=""
#read -p "Please input Auth filename:" htfile
if [ "$htfile" = "" ]; then
echo "Error:Auth filename can't be NULL!"
exit 1
fi
echo "==========================="
echo "Auth File: $workdir/$htfile"
echo "==========================="
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to Creat...or Press Ctrl+c to cancel"
char=`get_char`
if [ ! -f $workdir/$htfile.conf ]; then
make -p $workdir/$htfile.conf
echo "Create Auth file......"
fi
cat >>$workdir/$htfile.conf<<eof
$username:$password
eof
echo "Create Auth file successful,auth file path:$workdir/$htfile.conf."
cat $workdir/$htfile.conf
生成用户名密码信息
./htpasswd.sh
修改Nginx.conf配置
添加如下内容:
auth_basic "Authorized users only";
auth_basic_user_file /nginx/conf/longxibendi.auth.conf ; #这里写前面脚本返回的文件路径;
重启nginx
nginx -t
nginx -s reload
相关推荐
Nginx超级强大它可以单独为一个域名设置用户认证,方法也很简单我们只要生成用户认证的用户名和密码,然后再Nginx添加auth认证配置即可。 Nginx可以为某一个域名...2. 为Nginx添加auth认证配置 下面以某域名下面的aut
Nginx可以为某一个域名单独加用户认证,具体做法如下: ...2. 为Nginx添加auth认证配置 下面以某域名下面的auth目录为例,在域名的server段里加上如下代码: 代码如下:location ^~ /auth/ {location ~ .*.
安全起见需要增加下认证,但是重新搭建登录服务比较麻烦,所以想到利用nginx做认证. 1. 下载安装httpd-tools yum install httpd-tools -y 2. 创建授权用户和密码 htpasswd -c -d /usr/local/nginx/conf/pass_file ...
为网站目录设置访问验证之后我们就是进入此页面都需要输入验证密码才可以,下面我来介绍nginx中...2、为Nginx添加auth认证配置 下面是以某域名下面的soft目录为例,在域名的server段里加上如下代码: 代码如下: l
主要介绍了Nginx服务器中为网站或目录添加认证密码的配置详解,使用到了Apache的htpasswd工具,需要的朋友可以参考下
Nginx基本认证WebDAV和HTTP安全目录(链接)的url / .htpasswd。 目录中的简单自动搜索文件密码和高级用户权限。 支持CRYPT(3)MD5 SHA-1安全哈希密码并允许用户文件。 Lua中的计算(5.1) Yura Vdovytchenko版权...
配置添加到您的config.yaml : auth : htpasswd : file : ./htpasswd # Maximum amount of users allowed to register, defaults to "+inf". # You can set this to -1 to disable registration. # max_users: 1000...
在您的开发环境中,将主机添加到/etc/hosts文件中: 127.0.0.1 your-domain.test 用法 要在没有LetsEncrypt SSL的情况下启动服务器(在开发过程中): $ make up 要以Swarm模式使用SSL启动服务器以进行生产,请...
使用 docker 和 fig 一次性启动 norikra、elasticsearch、kibana4、nginx 进行基本身份验证,使用 fluentd 进行日志收集。首次执行fig up时将构建 Dockerfile。... 将 ID 和 PASS 添加到nginx_conf/htpasswd 。