我正在考虑从Apache切换到Nginx,并且我很难确定WordPress特定的安全指令需要什么。到目前为止,我发现的几乎所有特定于WordPress的内容都会破坏wp、中断内容布局、给出ajax错误或更多。
最常见的两个建议似乎是:ethanpil/wp-secure.conf和数字海洋。
有什么建议或更好的来源吗?
谢谢
安德鲁
发布于 2020-09-05 21:34:59
我已经把安全的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;
}
}最后,在/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)。
https://stackoverflow.com/questions/63753876
复制相似问题