使用?htpasswd -c /usr/local/nginx/passwd.db zhangsan 進行設置賬號
如果提示 htpasswd 沒有
-bash: htpasswd: command not found
1.沒有安裝命令
可以按照提示 安裝下
2.可能是已經安裝,但是沒有設置path,則需要加上路徑運行命令
解決完之后,運行?htpasswd -c /usr/local/nginx/passwd.db zhangsan
然后讓輸入密碼,再次輸入密碼
下一步就是修改 vhost配置文件,找到對應的域名配置文件,編輯
vim /usr/local/nginx/conf/vhost/www.ceshi.com.conf
按 i 開始編輯
添加
auth_basic "secret"; ? ? ? ? ? ? ? ? ? //添加認證配置 auth_basic_user_file /usr/local/nginx/passwd.db; ? ? //添加文件路徑添加
然后esc 鍵入 :wq 保存退出
重啟系統環境 ?lnmp restart
現在就可以看到效果了
輸入剛才設置的 賬號密碼 就能訪問網址了