nginx的优化加固
东拚西凑了一些有用的东东,可以贴在nginx配置文件中,
功能比较杂,防盗链、防注入等等
- location = /robots.txt { access_log off; log_not_found off; }
- location = /favicon.ico { access_log off; log_not_found off; }
- location ~ /\. { access_log off; log_not_found off; deny all; }
- location ~ ~$ { access_log off; log_not_found off; deny all; }
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; }
- location ~ .*\.(js|css)?$ { expires 12h; }
- location ~* \.(gif|jpg|png|swf|flv)$
- if ($host !=’*.yourdomain.com’) {
- return 403;
- }
- ## Block SQL injections
- set $block_sql_injections 0;
- if ($query_string ~ "union.*select.*\(") {
- set $block_sql_injections 1;
- }
- if ($query_string ~ "union.*all.*select.*") {
- set $block_sql_injections 1;
- }
- if ($query_string ~ "concat.*\(") {
- set $block_sql_injections 1;
- }
- if ($block_sql_injections = 1) {
- return 403;
- }
- ## Block file injections
- set $block_file_injections 0;
- if ($query_string ~ "[a-zA-Z0-9_]=http://") {
- set $block_file_injections 1;
- }
- if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") {
- set $block_file_injections 1;
- }
- if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") {
- set $block_file_injections 1;
- }
- if ($block_file_injections = 1) {
- return 403;
- }
- ## Block common exploits
- set $block_common_exploits 0;
- if ($query_string ~ "(<|%3C).*script.*(>|%3E)") {
- set $block_common_exploits 1;
- }
- if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
- set $block_common_exploits 1;
- }
- if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
- set $block_common_exploits 1;
- }
- if ($query_string ~ "proc/self/environ") {
- set $block_common_exploits 1;
- }
- if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") {
- set $block_common_exploits 1;
- }
- if ($query_string ~ "base64_(en|de)code\(.*\)") {
- set $block_common_exploits 1;
- }
- if ($block_common_exploits = 1) {
- return 403;
- }
- ## Block spam
- set $block_spam 0;
- if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") {
- set $block_spam 1;
- }
- if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") {
- set $block_spam 1;
- }
- if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") {
- set $block_spam 1;
- }
- if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") {
- set $block_spam 1;
- }
- if ($block_spam = 1) {
- return 403;
- }
- ## Block user agents
- set $block_user_agents 0;
- # Don't disable wget if you need it to run cron jobs!
- #if ($http_user_agent ~ "Wget") {
- # set $block_user_agents 1;
- #}
- # Disable Akeeba Remote Control 2.5 and earlier
- if ($http_user_agent ~ "Indy Library") {
- set $block_user_agents 1;
- }
- # Common bandwidth hoggers and hacking tools.
- if ($http_user_agent ~ "libwww-perl") {
- set $block_user_agents 1;
- }
- if ($http_user_agent ~ "GetRight") {
- set $block_user_agents 1;
- }
- if ($http_user_agent ~ "GetWeb!") {
- set $block_user_agents 1;
- }
- if ($http_user_agent ~ "Go!Zilla") {
- set $block_user_agents 1;
- }
- if ($http_user_agent ~ "Download Demon") {
- set $block_user_agents 1;
- }
- if ($http_user_agent ~ "Go-Ahead-Got-It") {
- set $block_user_agents 1;
- }
- if ($http_user_agent ~ "TurnitinBot") {
- set $block_user_agents 1;
- }
- if ($http_user_agent ~ "GrabNet") {
- set $block_user_agents 1;
- }
- if ($block_user_agents = 1) {
- return 403;
- }
使用方法
1、按照rpm的标准安装的路径,假设配置文件为/etc/nginx/nginx.conf 和/etc/nginx/conf.d/default.conf ,将上述内容保存为 /etc/nginx/nginx-extra.conf
2、在server 栏中加入,“ include nginx-extra.conf ” ,也就是如下格式:
- server {
- [...]
- include nginx-extra.conf
- }
注:有大段代码摘自howtoforge
nginx的优化加固相关推荐
- 基于ubuntu 的LAMP 优化加固
很多朋友都喜欢用ubuntu,很大原因是它安装LAMP非常简单, 尽管默认安装的lamp已经可以良好工作,但是系统管理员仍然可以找到一些优化加固的空间. 1.php加速 事实证明,php解释缓存可以提 ...
- ab测试nginx Nginx性能优化
转自:https://www.cnblogs.com/nulige/p/9369700.html 1.性能优化概述 在做性能优化前, 我们需要对如下进行考虑 1.当前系统结构瓶颈 观察指标 压力测试 ...
- 【整理】Nginx 战斗准备 —— 优化指南
2019独角兽企业重金招聘Python工程师标准>>> 本文内容参考自< Nginx 战斗准备 -- 优化指南 >. [一句话总结] 本文不是一个全面的微调指南,而是让你 ...
- Nginx 性能优化
Nginx 性能优化有这篇就够了! 1.Nginx运行工作进程数量 Nginx 运行工作进程个数一般设置CPU的核心或者核心数x2.如果不了解cpu的核数,可以top命令之后按1看出来,也可以查看/p ...
- Nginx 备战-优化指南
Nginx 备战-优化指南 作者:Zachary Orr 大多数关于 Nginx 的指南只告诉你那最基本的部分:apt-get 一个包,修改这里和那里的某些行,然后就得到了一个 web 服务器!而在大 ...
- 老司机整理对Nginx性能优化
Nginx性能优化应遵循一个原则:一次只调整一项,调整不理想,将修改还原. Linux参数 Nginx很多功能直接使用操作系统实现,操作系统决定nginx上限. 现代linux内核(2.6+)涵盖了大 ...
- Nginx配置优化参考
Nginx配置优化参考 编辑词 ...
- Nginx软件优化【转】
转自 Nginx软件优化 - 惨绿少年 - 博客园 Nginx软件优化 - 惨绿少年 - 博客园 https://www.cnblogs.com/clsn/p/8484559.html 1.1 Ngi ...
- 关于nginx性能优化CPU参数worker_cpu_affinity使用说明
Nginx性能优化CPU参数worker_cpu_affinity使用说明 官方说明:http://wiki.nginx.org/NginxHttpMainModule#worker_cpu_affi ...
最新文章
- 英伟达A100可达V100的3.5倍?
- 鸿蒙系统画饼,任正非说在三年内华为鸿蒙系统即可媲美苹果!真的不是“画饼”?...
- tor screenrec屏幕录制+_ScreenFlow for mac(屏幕录制软件) v8.2.4中文版
- 芬兰计算机研究生申请表,芬兰的研究生申请技巧
- 如何查看Linux版本号(内核版本号和发行版本号)
- mysql+查询新的一条记录表_Mysql 查询表中每个类别最新的一条记录
- Lua1.0 代码分析 opcode.c
- 使用asp.net改变图片颜色
- 力扣198. 打家jie舍(JavaScript)
- 计算机系班级海报,系部动态 | 电子系“五彩班栏”班级海报评比
- python装饰器快速入门
- VC操作Excel2003,Word2003的两种方式
- Visual Studio中View页面与Js页面用快捷键互相跳转
- 郑州大学期末php试题,郑州大学英语期末考试试题及答案
- 采用Turbo编码的图像传输试验(AWAG信道,matlab实现)分别验证了不同交织器类型,交织深度对turbo码性能的影响
- 双网卡电脑同时访问内外网设置静态路由表
- 简单实现微信抢红包的功能(Java)
- 如何用C语言来求次幂(快速幂算法)
- The Frame Buffer
- MyEclipse老是提示 resetting selection 长耗时的问题