海运的博客

Apache添加密码认证

发布时间:July 10, 2012 // 分类:Apache // No Comments

生成用户、密码文件:

htpasswd -c /etc/httpd/passwd user

1.直接编辑Apache配置添加认证:

#https://www.haiyun.me
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
AuthName "Httpd Access"
AuthType Basic
AuthUserFile /etc/httpd/passwd
Require valid-user
</Directory>

2.以.htaccess认证,首先授权相应网站建.htaccess验证权限:

Options Indexes FollowSymLinks
AllowOverride AuthConfig 
Order allow,deny
Allow from all

在验证目录新建.htaccess文件:

AuthName "Httpd Access"
AuthType Basic
AuthUserFile /etc/httpd/passwd
Require valid-user

Nginx设置目录密码认证/限制特定IP访问

发布时间:April 8, 2012 // 分类:Nginx,网络安全 // No Comments

网络安全无处不在,使用Nginx为您的网站后台加把锁吧。
验证界面如:
2012-04-08_071422.png
1.Nginx兼容于Apache下htpasswd生成的密钥,不过Nginx下无此工具,可以使用crypt生成密码。

perl -e 'print crypt($ARGV[0], "pwdsalt")' password ;echo ""#password请更改为您的密码

用php生成sha密码,不建议:

$user = 'test';
$pass = 'test';
$sha1 = base64_encode(sha1($pass, true));
echo $user.':{SHA}'.$sha1;

使用openssl生成sha512crypt密码,建议使用。

echo 123456|openssl passwd -6 -in - 

结果即加密后的密码,新建密钥配置谁的将用户密码以以下方式添加。

user:passwd

编辑Nginx配置文件

location ^~ /admin/ {        #特定目录
location ~ .*\.(php|php5)?$ {
allow 192.168.1.16; #允许IP
deny all; #拒绝所有
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
auth_basic "Login";
auth_basic_user_file /passwdfile;
}

添加ip白名单跳过验证:

satisfy any;
allow 127.0.0.1;
deny all;
auth_basic "Login";
auth_basic_user_file /passwdfile;
分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...