【问题标题】:Wordpress Nginx Security Best Practice [closed]Wordpress Nginx 安全最佳实践 [关闭]
【发布时间】:2020-09-06 05:34:59
【问题描述】:
我正在考虑从 Apache 切换到 Nginx,我正在努力确定 WordPress 特定的安全指令需要什么。到目前为止,我发现的几乎所有特定于 WordPress 的东西都会破坏 wp-admin、破坏内容布局、提供 ajax 错误或更多。
两个最常见的建议似乎是:ethanpil/wp-secure.conf 和 digital ocean。
有什么建议或更好的资源吗?
谢谢
安德鲁
【问题讨论】:
标签:
wordpress
nginx
nginx-config
【解决方案1】:
我已将安全 WordPress NGINX 配置的基本部分放在一起,here。
最安全的方法是将可以通过 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;
}
}
最后,禁用/wp-content/下的任何PHP执行是至关重要的:
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 运行,则需要将其列入白名单。