海运的博客

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;

Apache服务器安全设置

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

Apache是世界上占用率最大的web服务器软件,以安装、稳定而著称,默认安装后有一些限制较为宽松,可进一步设置加固其安全。
1.隐藏版本信息:

ServerSignature off #不输出任何页脚信息
ServerTokens prod #不输出apache版本信息

2.以低权限用户运行:

User nobody
Group nobody

3.网站目录设定:

<Directory "/var/www/html">
#Options Indexes FollowSymLinks #取消目录浏览,链接到其它目录
AllowOverride None  #禁止htaccess
php_admin_value open_basedir /var/www/html/ #限制活动目录,防止跨站,多个目录以:相隔
Order allow,deny
Allow from all
</Directory>

4.隐藏php版本,编辑php配置文件php.ini,添加或修改:

expose_php Off

Nginx限制IP请求数防CC攻击

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

适用于Nginx服务器,如需通过自带防火墙限制请参考iptables防CC
编辑Nginx配置文件在http段添加:

limit_req_zone $binary_remote_addr zone=req:10m rate=2r/s;
#定义会话存储区,名字为reg,每秒2个请求

server添加:

location /path/ #限制的目录
{
  limit_req_zone zone=reg burst=2; #突发最高每秒2个请求数
}

Nginx安全设置上传目录无php执行权限。

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

编辑Nginx配置文件在fastpass前添加以下内容

location ~* ^/www.haiyun.me/.*\.(php|php5)$  #限制/data/attachment/目录
{
  deny all;  #拒绝执行php程序
}

重启nginx

service nginx restart

Iptables限制同一IP连接数防CC/DDOS

发布时间:March 24, 2012 // 分类:网络安全 // No Comments

1.限制与80端口连接的IP最大连接数为10,可自定义修改。

iptables -I INPUT -p tcp --dport 80 -m connlimit --connlimit-above 10 -j DROP

2.使用recent模块限制同IP时间内新请求连接数,recent更多功能请参考:Iptables模块recent应用

iptables -A INPUT -p tcp --dport 80 --syn -m recent --name webpool --rcheck --seconds 60 --hitcount 10 -j LOG --log-prefix 'DDOS:' --log-ip-options
#60秒10个新连接,超过记录日志。
iptables -A INPUT -p tcp --dport 80 --syn -m recent --name webpool --rcheck --seconds 60 --hitcount 10 -j DROP
#60秒10个新连接,超过丢弃数据包。
iptables -A INPUT -p tcp --dport 80 --syn -m recent --name webpool --set -j ACCEPT
#范围内允许通过。
分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • 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 论坛没找到好方法,博...