wordpress - WordPress Nginx 安全最佳实践
问题描述
我正在考虑从 Apache 切换到 Nginx,我正在努力确定 WordPress 特定的安全指令需要什么。到目前为止,我发现的几乎所有特定于 WordPress 的东西都会破坏 wp-admin、破坏内容布局、提供 ajax 错误或更多。
两个最常见的建议似乎是: ethanpil/wp-secure.conf和digital ocean。
有什么建议或更好的来源吗?
谢谢
安德鲁
解决方案
我已经把安全的 WordPress NGINX 配置的基本部分放在一起,在这里。
最安全的方法是将可以通过 PHP 解释器运行的文件列入白名单,并以 HTTP 状态 404 拒绝所有其他文件的请求。
location / {
# any URI without extension is routed through PHP-FPM (WordPress controller)
location ~ ^[^.]*$ {
length_hiding on;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include includes/php-example.com.conf;
}
# allow only a handful of PHP files in root directory to be interpreted
# wp-cron.php ommited on purpose as it should *not* be web accessible, see proper setup
# https://www.getpagespeed.com/web-apps/wordpress/wordpress-cron-optimization
location ~ ^/wp-(?:links-opml|login|mail|signup|trackback)\.php$ {
length_hiding on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include includes/php-example.com.conf;
}
# other PHP files "do not exist"
location ~ \.php$ {
return 404;
}
}
最后,禁用以下任何 PHP 执行至关重要/wp-content/
:
location /wp-content/ {
# contents under wp-content are typically highly cacheable
immutable on;
# hide and do not interpret internal plugin or user uploaded scripts
location ~ \.php$ {
return 404;
}
}
如果您觉得必须将某些脚本作为/wp-content/some.php
URI 启动,那么您可能有一个需要删除的坏插件,或者(很少)如果要通过 PHP-FPM 运行则将其列入白名单。
推荐阅读
- django - Django模板不呈现任务信息
- node.js - 等待函数的最佳方式是什么?
- java - 如何使用休眠验证器为验证传递不同的错误代码?
- python - 将 celery worker 与 Flask 一起使用时出现协议错误
- node.js - 如何使用过期令牌将 WebChat 重新连接到旧对话
- django - Django-管理部分视图不正确
- android - 如何以正确的方式将jwt存储在android应用程序中?
- python - 使用 pytest 记录毫秒数
- mailchimp - Mailchimp API:向带有标签的用户发送活动
- rest - Jira REST api,更新特定于项目的自定义字段选项