0

i'm using nginx as reverse proxy. I'm already redirect port 80 to 8080, redirect non-www to www and enabled gzip. Al this works.

Now i need add expires headers

Following many posts and answers to this question i add

location ~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|eot)$ {
    expires 30d;
    add_header Pragma public;
    add_header Cache-Control "public";
}

But when i restart nginx, all my static files, that matches with location cannot but found.

I tried figure out by my self but without success.

Follow my default.com

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

upstream originserver  {
  server 127.0.0.1:8080;
}

server {
  server_name  mysite.com;
  rewrite ^(.*) $scheme://www.mysite.com$1 permanent;
}

server {

  listen 80;
  server_name www.mysite.com;  

  location /{
    try_files $uri @backend;
  }

  location @backend {
    proxy_pass  http://originserver;
    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;
  }

  location ~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|eot)$ {
    expires 30d;
    add_header Pragma public;
    add_header Cache-Control "public";
  }

}

How can i fix it?

Thanks

1
  • 1
    You are missing a root statement in your server block. See this document for details. Oct 23, 2016 at 17:00

1 Answer 1

0

The problem is not expires.

The problem is that you haven't told nginx where the files are. This is done with the root directive, which should be placed within the server block.

3
  • I read something like this, but this static files are deployed within wildfly10 server. I should found the deploy folder and set root to this location? Oct 23, 2016 at 17:30
  • @ViniciusRoberto Right, nginx cannot read a war file directly, so you have to do an exploded deployment and point nginx to the document root of the static files. Oct 23, 2016 at 17:40
  • thanks for help me! I changed my root and copy my static files to this location and works =D! Now i have to look how i do this easy on wildfly. Oct 25, 2016 at 11:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .