网站安全之nginx的配置创建访问网站密码认证
生活随笔
收集整理的這篇文章主要介紹了
网站安全之nginx的配置创建访问网站密码认证
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
最近我們Sinesafe在處理nginx+php+mysql架構(gòu)的客戶網(wǎng)站安全方面要配置后臺(tái)的二級(jí)密碼訪問驗(yàn)證處理過程中要用到nginx的配置來(lái)完成這個(gè)二級(jí)密碼的設(shè)置安全部署。
下面由我來(lái)簡(jiǎn)要說一下在nginx配置服務(wù)中,創(chuàng)建訪問網(wǎng)站密碼認(rèn)證的方法。
1)需要ngx_http_auth_basic_module模塊
語(yǔ)法:
Syntax: auth_basic string | off; Default: auth_basic off; Context: http, server, location, limit_except默認(rèn)是關(guān)閉的,使用位置在http,server,location標(biāo)簽。
2)例子:
location / {auth_basic "closed site";auth_basic_user_file conf/htpasswd; }3)首先配置出保存用戶和密碼的文件htpasswd
使用htpasswd命令進(jìn)行創(chuàng)建登錄用戶和密碼
參數(shù):
1 -c:創(chuàng)建一個(gè)加密文件; 2 -n:不更新加密文件,只將加密后的用戶名密碼顯示在屏幕上; 3 -m:默認(rèn)采用MD5算法對(duì)密碼進(jìn)行加密; 4 -d:采用CRYPT算法對(duì)密碼進(jìn)行加密; 5 -p:不對(duì)密碼進(jìn)行進(jìn)行加密,即明文密碼; 6 -s:采用SHA算法對(duì)密碼進(jìn)行加密; 7 -b:在命令行中一并輸入用戶名和密碼而不是根據(jù)提示輸入密碼; 8 -D:刪除指定的用戶。a、查看系統(tǒng)是否安裝了htpasswd命令
1 root@oldboy nginx]# which htpasswd 2 /usr/bin/which: no htpasswd in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)b、安裝htpasswd命令
[root@oldboy nginx]# yum install http -yc、使用htpasswd命令創(chuàng)建密碼文件htpasswd
1 [root@oldboy nginx]# htpasswd -cb /application/nginx/conf/htpasswd taili01 123456 2 Adding password for user taili01d、在原文件htpasswd中增加新的用戶
1 [root@oldboy nginx]# htpasswd -b ./htpasswd taili02 123456 2 Adding password for user taili02e、查看htpasswd文件內(nèi)容
1 [root@oldboy nginx]# cat ./htpasswd 2 taili01:ZCN8EXnjt3OYY 3 taili02:lDJrLzZuwxh/g4)配置nginx.conf文件
?
1 [root@oldboy conf]# vim nginx.conf2 worker_processes 1;3 events {4 worker_connections 1024;5 }6 error_log logs/error.log;7 http {8 include mime.types;9 default_type application/octet-stream; 10 sendfile on; 11 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 12 '$status $body_bytes_sent "$http_referer" ' 13 '"$http_user_agent" "$http_x_forwarded_for"'; 14 keepalive_timeout 65; 15 server { 16 listen 80; 17 server_name www.sandy.com; 18 location / { 19 root html/www; 20 index index.html index.htm; 21 auth_basic "This is input password"; 22 auth_basic_user_file conf/htpasswd; 23 } 24 access_log logs/host.access.log main; 25 error_page 500 502 503 504 /50x.html; 26 location = /50x.html { 27 root html; 28 } 29 } 30 }5)訪問網(wǎng)站
?
如果有錯(cuò)誤,歡迎各位網(wǎng)友指導(dǎo)。 另外喜歡的話,給個(gè)點(diǎn)贊唄,謝謝!
專注于安全領(lǐng)域 解決網(wǎng)站安全 解決網(wǎng)站被黑 網(wǎng)站被掛馬 網(wǎng)站被篡改 網(wǎng)站安全、服務(wù)器安全提供商-www.sinesafe.com --專門解決其他人解決不了的網(wǎng)站安全問題. 與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的网站安全之nginx的配置创建访问网站密码认证的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Netty 系列三(ByteBuf).
- 下一篇: 使用canvas绘制小程序码