MENU

#笔记#使用Nginx加密网站目录

February 15, 2018 • Read: 2264 • 网络笔记

本次使用环境为Nginx web服务器,并且安装目录于/usr/local/nginx 如果你的目录并不在此,请自行修改为Nginx所安装的目录之中。

生成用户名及密码

进入nginx安装目录中

printf "user:$(openssl passwd -crypt passwd)\n" >> /usr/local/nginx/conf/htpasswd
//其中user为你的用户名 passwd为你的密码

配置nginx

location ~ ^/my/.* {           
//其中~ ^/my/.*代表 my目录下访问需要密码,其他目录则不需要密码   如需要全目录加密则直接 location / {
 auth_basic "Nginx";  
 auth_basic_user_file htpasswd;
 autoindex on;
 }

保存退出后重启nginx

service nginx restart
Archives QR Code Tip
QR Code for this page
Tipping QR Code