0

My Nginx Proxy Server : 10.90.100.2 My Backend Server : 10.90.100.3

my proxy server not loading static files (css,js,woff,png vb.)

My conf


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.log


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

Thank you

2

The problem is this block:

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

This means that all requests for images end up using this block, which does not tell where the images are. nginx therefore tries to use the default root location for sending the files.

nginx always selects a single location block to serve a request, unless the block makes an internal redirect.

I would remove this block from your configuration, since you already have Pagespeed installed. It takes care of proper expiration dates for images, at least if you have configured it properly.

  • Thank you @Tero Kilkanen; – Ferdi KUCUK Mar 17 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.