东拚西凑了一些有用的东东,可以贴在nginx配置文件中,

功能比较杂,防盗链、防注入等等

  1. location = /robots.txt { access_log off; log_not_found off; }
  2. location = /favicon.ico { access_log off; log_not_found off; }
  3. location ~ /\. { access_log off; log_not_found off; deny all; }
  4. location ~ ~$ { access_log off; log_not_found off; deny all; }
  5. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; }
  6. location ~ .*\.(js|css)?$ {  expires  12h; }
  7. location ~* \.(gif|jpg|png|swf|flv)$
  8. if ($host !=’*.yourdomain.com’) {
  9. return 403;
  10. }
  11. ## Block SQL injections
  12. set $block_sql_injections 0;
  13. if ($query_string ~ "union.*select.*\(") {
  14. set $block_sql_injections 1;
  15. }
  16. if ($query_string ~ "union.*all.*select.*") {
  17. set $block_sql_injections 1;
  18. }
  19. if ($query_string ~ "concat.*\(") {
  20. set $block_sql_injections 1;
  21. }
  22. if ($block_sql_injections = 1) {
  23. return 403;
  24. }
  25. ## Block file injections
  26. set $block_file_injections 0;
  27. if ($query_string ~ "[a-zA-Z0-9_]=http://") {
  28. set $block_file_injections 1;
  29. }
  30. if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") {
  31. set $block_file_injections 1;
  32. }
  33. if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") {
  34. set $block_file_injections 1;
  35. }
  36. if ($block_file_injections = 1) {
  37. return 403;
  38. }
  39. ## Block common exploits
  40. set $block_common_exploits 0;
  41. if ($query_string ~ "(<|%3C).*script.*(>|%3E)") {
  42. set $block_common_exploits 1;
  43. }
  44. if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
  45. set $block_common_exploits 1;
  46. }
  47. if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
  48. set $block_common_exploits 1;
  49. }
  50. if ($query_string ~ "proc/self/environ") {
  51. set $block_common_exploits 1;
  52. }
  53. if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") {
  54. set $block_common_exploits 1;
  55. }
  56. if ($query_string ~ "base64_(en|de)code\(.*\)") {
  57. set $block_common_exploits 1;
  58. }
  59. if ($block_common_exploits = 1) {
  60. return 403;
  61. }
  62. ## Block spam
  63. set $block_spam 0;
  64. if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") {
  65. set $block_spam 1;
  66. }
  67. if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") {
  68. set $block_spam 1;
  69. }
  70. if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") {
  71. set $block_spam 1;
  72. }
  73. if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") {
  74. set $block_spam 1;
  75. }
  76. if ($block_spam = 1) {
  77. return 403;
  78. }
  79. ## Block user agents
  80. set $block_user_agents 0;
  81. # Don't disable wget if you need it to run cron jobs!
  82. #if ($http_user_agent ~ "Wget") {
  83. #    set $block_user_agents 1;
  84. #}
  85. # Disable Akeeba Remote Control 2.5 and earlier
  86. if ($http_user_agent ~ "Indy Library") {
  87. set $block_user_agents 1;
  88. }
  89. # Common bandwidth hoggers and hacking tools.
  90. if ($http_user_agent ~ "libwww-perl") {
  91. set $block_user_agents 1;
  92. }
  93. if ($http_user_agent ~ "GetRight") {
  94. set $block_user_agents 1;
  95. }
  96. if ($http_user_agent ~ "GetWeb!") {
  97. set $block_user_agents 1;
  98. }
  99. if ($http_user_agent ~ "Go!Zilla") {
  100. set $block_user_agents 1;
  101. }
  102. if ($http_user_agent ~ "Download Demon") {
  103. set $block_user_agents 1;
  104. }
  105. if ($http_user_agent ~ "Go-Ahead-Got-It") {
  106. set $block_user_agents 1;
  107. }
  108. if ($http_user_agent ~ "TurnitinBot") {
  109. set $block_user_agents 1;
  110. }
  111. if ($http_user_agent ~ "GrabNet") {
  112. set $block_user_agents 1;
  113. }
  114. if ($block_user_agents = 1) {
  115. return 403;
  116. }

使用方法

1、按照rpm的标准安装的路径,假设配置文件为/etc/nginx/nginx.conf 和/etc/nginx/conf.d/default.conf ,将上述内容保存为 /etc/nginx/nginx-extra.conf

2、在server 栏中加入,“ include nginx-extra.conf ” ,也就是如下格式:

  1. server {
  2. [...]
  3. include nginx-extra.conf
  4. }

注:有大段代码摘自howtoforge

本文转自 紫色葡萄 51CTO博客,原文链接:http://blog.51cto.com/purplegrape/957731,如需转载请自行联系原作者

nginx的优化加固相关推荐

  1. 基于ubuntu 的LAMP 优化加固

    很多朋友都喜欢用ubuntu,很大原因是它安装LAMP非常简单, 尽管默认安装的lamp已经可以良好工作,但是系统管理员仍然可以找到一些优化加固的空间. 1.php加速 事实证明,php解释缓存可以提 ...

  2. ab测试nginx Nginx性能优化

    转自:https://www.cnblogs.com/nulige/p/9369700.html 1.性能优化概述 在做性能优化前, 我们需要对如下进行考虑 1.当前系统结构瓶颈 观察指标 压力测试 ...

  3. 【整理】Nginx 战斗准备 —— 优化指南

    2019独角兽企业重金招聘Python工程师标准>>> 本文内容参考自< Nginx 战斗准备 -- 优化指南 >. [一句话总结] 本文不是一个全面的微调指南,而是让你 ...

  4. Nginx 性能优化

    Nginx 性能优化有这篇就够了! 1.Nginx运行工作进程数量 Nginx 运行工作进程个数一般设置CPU的核心或者核心数x2.如果不了解cpu的核数,可以top命令之后按1看出来,也可以查看/p ...

  5. Nginx 备战-优化指南

    Nginx 备战-优化指南 作者:Zachary Orr 大多数关于 Nginx 的指南只告诉你那最基本的部分:apt-get 一个包,修改这里和那里的某些行,然后就得到了一个 web 服务器!而在大 ...

  6. 老司机整理对Nginx性能优化

    Nginx性能优化应遵循一个原则:一次只调整一项,调整不理想,将修改还原. Linux参数 Nginx很多功能直接使用操作系统实现,操作系统决定nginx上限. 现代linux内核(2.6+)涵盖了大 ...

  7. Nginx配置优化参考

    Nginx配置优化参考                                                                                      编辑词 ...

  8. Nginx软件优化【转】

    转自 Nginx软件优化 - 惨绿少年 - 博客园 Nginx软件优化 - 惨绿少年 - 博客园 https://www.cnblogs.com/clsn/p/8484559.html 1.1 Ngi ...

  9. 关于nginx性能优化CPU参数worker_cpu_affinity使用说明

    Nginx性能优化CPU参数worker_cpu_affinity使用说明 官方说明:http://wiki.nginx.org/NginxHttpMainModule#worker_cpu_affi ...

最新文章

  1. 英伟达A100可达V100的3.5倍?
  2. 鸿蒙系统画饼,任正非说在三年内华为鸿蒙系统即可媲美苹果!真的不是“画饼”?...
  3. tor screenrec屏幕录制+_ScreenFlow for mac(屏幕录制软件) v8.2.4中文版
  4. 芬兰计算机研究生申请表,芬兰的研究生申请技巧
  5. 如何查看Linux版本号(内核版本号和发行版本号)
  6. mysql+查询新的一条记录表_Mysql 查询表中每个类别最新的一条记录
  7. Lua1.0 代码分析 opcode.c
  8. 使用asp.net改变图片颜色
  9. 力扣198. 打家jie舍(JavaScript)
  10. 计算机系班级海报,系部动态 | 电子系“五彩班栏”班级海报评比
  11. python装饰器快速入门
  12. VC操作Excel2003,Word2003的两种方式
  13. Visual Studio中View页面与Js页面用快捷键互相跳转
  14. 郑州大学期末php试题,郑州大学英语期末考试试题及答案
  15. 采用Turbo编码的图像传输试验(AWAG信道,matlab实现)分别验证了不同交织器类型,交织深度对turbo码性能的影响
  16. 双网卡电脑同时访问内外网设置静态路由表
  17. 简单实现微信抢红包的功能(Java)
  18. 如何用C语言来求次幂(快速幂算法)
  19. The Frame Buffer
  20. MyEclipse老是提示 resetting selection 长耗时的问题

热门文章

  1. C语言--分治法经典例题--循环日程安排问题
  2. IDEA同一窗口打开多个项目
  3. 小学计算机病毒与危害的课,计算机病毒与危害
  4. 在VMware虚拟机上使用网络测试命令找出虚拟机的IP地址
  5. js 获取当前星期跟年月日
  6. 【Vue】vue先转化文章内容再去除标签 vue filters过滤器去除标签 js提取文字内容
  7. 【瑞萨RA_FSP】GPT—— 通用PWM定时器
  8. 开源直播推流sdk_直播中那几秒延时到底来自哪?
  9. iOS 使用腾讯地图SDK,搜索附近位置
  10. Java8的一些新特性