您现在的位置是:首页 > 网站头条 > 乱七八糟 > 文章正文 乱七八糟
分享个自用的 Nginx 加强 WordPress 防护的规则
西安SEO优化
2023-03-13 11:34:22
乱七八糟
人已围观
简介Nginx+ WordPress 的组合是目前非常普及的组合了,我们完全可以借助 Nginx 规则来加强 WordPress 的防护,提高 WordPress 的安全性,今天明月就给大家分享个自用的 Nginx 针对 WordPress 的防护规则,部分规则大家只需要根据自己的需要进行调整即可。
Nginx+ WordPress 的组合是目前非常普及的组合了,我们完全可以借助 Nginx 规则来加强 WordPress 的防护,提高 WordPress 的安全性,今天明月就给大家分享个自用的 Nginx 针对 WordPress 的防护规则,部分规则大家只需要根据自己的需要进行调整即可。
万晓博SEO推荐服务器:

- #隐藏 nginx 版本.
- server_tokens off;
- #隐藏 PHP 版本
- fastcgi_hide_header X-Powered-By;
- proxy_hide_header X-Powered-By;
- #禁止目录列表
- autoindex off;
- #验证浏览器行为防 CC
- #if ($cookie_say != "hbnl$remote_addr"){
- # rewrite .* "$scheme://$host$uri" redirect;
- #return 444;
- #}
- #屏蔽 IP 访问
- deny 158.69.243.0/24; # MJ12bot
- deny 46.229.168.0/24; # SemRush
- deny 54.36.148.0/24; # AhrefsBot
- deny 54.36.149.0/24; # AhrefsBot
- #禁止 17ce.com 的测速
- if ($http_referer ~* 17ce.com) { return 444; }
- #禁止恶意 UA 以及为空的请求(^$)
- if ($http_user_agent ~ "Go-http-client|Apache-HttpClient|lua-resty-http|loli_spider|ngx_lua"){
- return 444;
- }
- # 禁止 Scrapy 等工具的抓取
- if ($http_user_agent ~* (cdnunion_monitor|python-httpx|Wget|Scrapy|HttpClient|PostmanRuntime|ApacheBench|python-requests|Python-urllib|node-fetch)) {
- return 499;
- }
- #禁止一些特殊的 UA
- if ($http_user_agent ~ "Mozilla/4.0\ \(compatible;\ MSIE\ 6.0;\ Windows\ NT\ 5.1;\ SV1;\ .NET\ CLR\ 1.1.4322;\ .NET\ CLR\ 2.0.50727\)") {
- return 444;
- }
- # 屏蔽恶意后缀文件访问请求
- if ($document_uri ~* \.(asp|aspx|jsp|swp|git|env|yaml|yml|sql|db|bak|ini|docx|doc|rar|tar|gz|zip|log|bak|conf)$) { return 444; }
- #禁止直接访问任何 php 文件
- location ~* /(?:uploads|files|akismet)/.*.php$ { deny all; access_log off; log_not_found off;}
- # 保护 WordPress 系统文件
- location = /wp-admin/install.php { deny all; }
- location = /nginx.conf { deny all; }
- location ~ ^/user_extention/ { deny all; }
- location ~ /\.htaccess$ { deny all; }
- location ~ /readme\.html$ { deny all; }
- location ~ /readme\.txt$ { deny all; }
- location ~ ^/wp-config.php$ { deny all; }
- location ~ ^/wp-admin/includes/ { deny all; }
- location ~ ^/wp-includes/[^/]+\.php$ { deny all; }
- location ~ ^.*/\.git/.*$ { deny all; }
- location ~ ^.*/\.svn/.*$ { deny all; }
- # 禁用 Uploads 目录的 PHP
- location ~ ^/wp\-content/uploads/.*\.(?:php[1-7]?|pht|phtml?|phps)$ { deny all; }
- # 禁用 Plugins 目录的 PHP
- location ~ ^/wp\-content/plugins/.*\.(?:php[1-7]?|pht|phtml?|phps)$ { deny all; }
- # 禁用 Themes 目录的 PHP,慎重使用会影响到部分主题的缩略图裁剪哦!
- location ~ ^/wp\-content/themes/.*\.(?:php[1-7]?|pht|phtml?|phps)$ { deny all; }
- # 不记录 favicon.ico 请求
- location = /favicon.ico { log_not_found off; access_log off;}
- # 不记录 robots.txt 请求
- location = /robots.txt { log_not_found off; access_log off;}
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {expires 30d;}
- location ~ .*\.(js|css)?$ { expires 30d;}
- location ~ /\. {deny all;}
- location ~ /\.ht { deny all; access_log off; log_not_found off;}
- location ~ /\.user.ini { deny all; access_log off;log_not_found off;}
一般明月使用这些规则都是新建一个.conf 文件,在 Nginx 站点配置文件里单独 include 这个文件,重启 Nginx 生效,主要是为了根据不同站点需求进行细微的修改而已,理论上来说在宝塔面板里也可以这么用的,大家活学活用即可。
万晓博SEO推荐服务器:

相关文章
文章评论
点击排行
- 老电脑的福音,Win11流畅版——精简版的Windows11——Tiny11
- VMware Workstation 17 pro永久激活,无限制!附序列号,直接上高速!
- 《黑豹2》4K原盘REMUX [HDR] [内封简英双字]
- 【群晖NAS迁移数据】群晖NAS换新机器数据迁移3种方法,这次给讲全了!
- 群晖NAS入门教程第1节:群晖NAS硬盘及DSM系统安装
- 【良心网盘】123网盘终于推出PC客户端了,完全免费不限速且大空间,注册就送2T空间!
- 【电影推荐】中国大陆《流浪地球》1080PREMUX(蓝光原盘)资源分享
- 如何在OpenAI网站上申请API密钥?申请openapi(ChatGPT)密钥的方法
站长推荐
标签云
猜你喜欢
站点信息
打赏本站
- 如果你觉得本站很棒,可以通过扫码支付打赏哦!
- 微信扫码:你说多少就多少~
- 支付宝扫码:你说多少就多少~