如果索引文件存在NGINX,我如何防止代理?



我有一个代理apache的NGINX服务器。Wp-Rocket制作所有缓存作业,并将缓存文件存储到wp-content/cache/Wp-Rocket/mysite.com/每个索引文件保存为index-http .html这样做的目的是在索引文件已经存在的情况下防止代理。每次刷新页面时,我都会在Apache日志中看到GET请求。你能指出我哪里做错了吗?

root /var/www/html;
location ~ .php$ {
error_page 420 = @apache;
return 420;
}
location / {
index index.html index-https.html;
error_page 420 = @apache;
error_page 405 = @apache;
if ($request_method = POST ) {
return 420;
}
if ( $query_string ){
return 420;
}
if ( $http_cookie ~ "wordpress_logged_in" ){
return 420;
}
expires 365d;
add_header Cache-Control "public, no-transform";
gzip_static on;
try_files $uri wp-content/cache/wp-rocket/mysite.com/$uri/ @apache;
}
location @apache {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port  $server_port;
proxy_hide_header Upgrade;
}

尝试指定索引文件(index-https.html),但没有成功也试过:

try_files $uri wp-content/cache/wp-rocket/mysite.com/$uri/ @apache;
try_files $uri /wp-content/cache/wp-rocket/mysite.com/$uri/ @apache;
try_files $uri /wp-content/cache/wp-rocket/mysite.com/$uri @apache;
try_files $uri /wp-content/cache/wp-rocket/mysite.com/$uri/index-https.html @apache;

URI/resumes/marina-7/应该指向文件/var/www/html/wp-content/cache/wp-rocket/mysite.com/resumes/marina-7/index-https.html

$uri的值正好是/resumes/marina-7/,所以注意不要在变量之前或之后插入额外的/

使用:

try_files $uri /wp-content/cache/wp-rocket/mysite.com${uri}index-https.html @apache;

注意,术语必须以/开头,并且用大括号分隔变量名。

最新更新