详解Nginx防盗链和Nginx访问控制与Nginx解析php的配置
Nginx防盗链
配置如下,可以和上面的配置结合起来
?
1
2
3
4
5
6
7
8
9 |
location ~* ^.+\\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
expires 7d;
valid_referers none blocked server_names *. test .com ;
if ($invalid_referer) {
return 403;
}
access_log off;
} |
Nginx访问控制
配置如下:
?
1
2
3
4
5
6 |
location /admin/
{
allow 192.168.133.1;
allow 127.0.0.1;
deny all;
} |
创建测试
?
1
2 |
mkdir /data/wwwroot/test .com /admin/
echo “ test , test ”> /data/wwwroot/test .com /admin/1 .html |
检测重启
?
1 |
/usr/local/nginx/bin/nginx -t && -s reload |
测试
?
1
2 |
curl -x127.0.0.1:80 test .com /admin/1 .html -I
curl -x192.168.133.130:80 test .com /admin/1 .html -I |
Nginx访问控制
配置如下:
?
1
2
3
4 |
location ~ .*(abc|image)/.*\\.php$
{
deny all;
} |
根据user_agent限制
?
1
2
3
4 |
if ($http_user_agent ~ 'Spider/3.0|YoudaoBot|Tomato' )
{
return 403;
} |
deny all和return 403效果一样
Nginx解析php的配置
配置如下:
?
1
2
3
4
5
6
7 |
location ~ \\.php$
{
include fastcgi_params;
fastcgi_pass unix: /tmp/php-fcgi .sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/test .com$fastcgi_script_name;
} |
fastcgi_pass 用来指定php-fpm监听的地址或者socket
以上就是Nginx防盗链和Nginx访问控制与Nginx解析php的配置的讲解,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
原文链接:https://my.oschina.net/jiangshanlinux/blog/1510278
相关文章
猜你喜欢
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 41
-
2025-05-29 93
-
2025-05-25 68
-
2025-05-25 40
-
2025-05-29 28
热门评论