Nginx

Nginx 代理記憶體 404 未找到靜態文件 (css,js,jpg,png vb)

  • March 16, 2019

我的 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:

謝謝

問題是這個塊:

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

這意味著所有對圖像的請求最終都會使用這個塊,它不會告訴圖像在哪裡。因此,nginx 嘗試使用預設root位置來發送文件。

nginx 總是選擇單個location塊來服務請求,除非該塊進行內部重定向。

我會從你的配置中刪除這個塊,因為你已經安裝了 Pagespeed。它負責圖像的正確到期日期,至少如果您已正確配置它。

引用自:https://serverfault.com/questions/958605