Nginx 代理缓存 404 未找到静态文件(css、js、jpg、png vb)

Nginx 代理缓存 404 未找到静态文件(css、js、jpg、png vb)

我的 Nginx 代理服务器:10.90.100.2 我的后端服务器:10.90.100.3

我的代理服务器没有加载静态文件(css、js、woff、png vb。)

我的会议


proxy_cache_path /etc/nginx/proxy_cache levels=1:2 keys_zone=ferditest:10m inactive=60m;
proxy_cache_key "$scheme$request_method$host$request_uri";

server {

listen 80;
listen 443 ssl;
server_name www.abc.com abc.com;

ssl_certificate /etc/letsencrypt/live/abc.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/abc.com/privkey.pem;




location ~*  \.(jpg|jpeg|png|gif|ico|css|js|pdf|woff|woff2|pdf)$ {
    expires 30d;
}



#include /etc/nginx/bots.d/ddos.conf;
#include /etc/nginx/bots.d/blockbots.conf;
#include /etc/nginx/bots.d/blacklist-ips.conf;


ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don't use SSLv3 because of killer poodles


pagespeed on;
pagespeed FileCachePath "/etc/nginx/ngx_pagespeed/";
pagespeed EnableFilters collapse_whitespace; 
pagespeed EnableFilters extend_cache; 
pagespeed EnableFilters make_google_analytics_async; 
pagespeed EnableFilters lazyload_images; 
pagespeed EnableFilters rewrite_images;

location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }



location / {


add_header Strict-Transport-Security "max-age=31536000";
add_header X-Content-Type-Options nosniff;
add_header X-Cache $upstream_cache_status;


proxy_cache ferditest;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; 
proxy_set_header Accept-Encoding "gzip";

proxy_buffering        on;
proxy_cache_valid 200 302 1m;
proxy_cache_valid 404    1m;
proxy_cache_methods GET HEAD;

proxy_cache_use_stale  error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_cache_lock on;
proxy_cache_use_stale updating;
proxy_bind 0.0.0.0;


proxy_pass http://10.90.100.3;

proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_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 https;
proxy_set_header HTTPS "on";
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Accel-Internal /internal-nginx-static-location;





}
}

错误日志


[error] 23151#23151: *6 open() "/etc/nginx/html/test1/wp-includes/js/wp-embed.min.js" failed (2: No such file or directory), client:

谢谢

答案1

问题出在这个块上:

location ~*  \.(jpg|jpeg|png|gif|ico|css|js|pdf|woff|woff2|pdf)$ {
    expires 30d;
}

这意味着所有对图像的请求最终都会使用这个块,而它并不会告诉图像在哪里。因此,nginx 会尝试使用默认root位置来发送文件。

nginx 总是选择一个location块来处理请求,除非该块进行内部重定向。

我会从您的配置中删除此块,因为您已经安装了 Pagespeed。它会处理图像的正确到期日期,至少如果您已正确配置它的话。

相关内容