我正在尝试在我的 wordpress 网站上安装 wordfence,它要求我更新我的 nginx.conf 以进行缓存,我创建了一个新的文件名 wp.conf 并将其包含在 nginx.conf 中,但是当尝试重新启动 nginx 时出现以下错误:
nginx: [emerg] invalid parameter "cookie”" in /etc/nginx/wf.conf:8
nginx: configuration file /etc/nginx/nginx.conf test failed
这是我的 wf.conf 文件:
server {
# WORDFENCE FALCON ENGINE CODE
#Match on gzip first because ordering matters.
location ~ “/site/wp-content/wfcache/.*gzip$” {
gzip off;
types {}
default_type text/html;
add_header Vary “Accept-Encoding, Cookie”;
add_header Content-Encoding gzip;
}
#If the previous matched, the following location won’t be executed.
location ~ /site/wp-content/wfcache/.* {
add_header Vary “Accept-Encoding, Cookie”;
}
set $wordfenceCacheOn 1;
#Don’t cache form submissions.
if ($request_method = POST) {
set $wordfenceCacheOn 0;
}
#Allow caching of /?123=123 because this is a common DDoS to override caches.
if ($query_string !~ “^(?:d+=d+)?$”) {
set $wordfenceCacheOn 0;
}
#Only cache URL’s ending in /
if ($request_uri !~ /$) {
set $wordfenceCacheOn 0;
}
#Don’t cache any cookies with this in their names e.g. users who are logged in.
if ($http_cookie ~* “(comment_author|wp- postpass|wf_logout|wordpress_logged_in|wptouch_switch_toggle|wpmp_switcher)”) {
set $wordfenceCacheOn 0;
}
set $wordfenceEncoding “”;
#Oh, you want gzipped content?
if ($http_accept_encoding ~ gzip) {
set $wordfenceEncoding _gzip;
}
set $wordfenceHTTPS “”;
if ($scheme = ‘https’){
#If you want to ENABLE HTTPS caching, comment out the next line.
set $wordfenceCacheOn 0; #Comment this line out to enable HTTPS caching.
set $wordfenceHTTPS ‘_https’; #Uncomment this line to enable HTTPS caching.
}
#The main purpose of this line is to capture the URL components into variables.
if ($request_uri !~ “^/*(?<wfone>[^/]*)/*(?<wftwo>[^/]*)/*(?<wfthree> [^/]*)/*(?<wffour>[^/]*)/*(?<wffive>[^/]*)(?<wfsix>.*)$”){
set $wordfenceCacheOn 0;
}
#If the file doesn’t exist then don’t serve from cache.
if (!-f “$document_root/site/wp- content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wf six}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}”) {
set $wordfenceCacheOn 0;
}
if ($wordfenceCacheOn = 1) {
rewrite .* “/site/wp- content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wf six}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}” last;
}
# END Wordfence Rules
}
这是 nginx.conf 文件:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
答案1
文件中含有无效的引号wf.conf
。
在您的 中nginx.conf
,您有"
作为引号字符,而在 中wf.conf
,您有“
,这是无效的。
更改引号,配置就可以起作用了。