0

I'm working on Nginx to add cache headers on my static files and works. I'm using this location

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";
    include       /etc/nginx/mime.types;
}

I just add mime.types, cause otherwise my css files came with "application/octet-stream".

My problem happen when i use SEO analyser tools, like https://gtmetrix.com. This tools append ;jsessionid=k40cMYJwvlCBjX5bkZY6t5oeMquLcMv0dJve1PtD.ip-XXX-XX-XX-XXX and i can't my location to match this

Following a few others answers I tried

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";
    include       /etc/nginx/mime.types;
}

But when i do this i receive this message

nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/conf.d/default.conf:34

What i'm doing wrong?

Edit 1 - My entire default.conf

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 {

  root /var/www/mysite;

  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;
    include       /etc/nginx/mime.types;
  }

  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";
    include       /etc/nginx/mime.types;
  }

}

Edit 2 - New info

Maybe the problem could be other. When I return the original location

~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|eot)$

and test in putty in the server with

curl -I http://example.com/images/myimg.jpg;jsessionid=k40cMYJwvlCBjX5bkZY6t5oeMquLcMv0dJve1PtD.ip-XXX-XX-XX-XXX

works the expires header was included, but when i open in my browser the same url, wasn't.

1 Answers1

1

I fixed my problem.

After looking Edit 2 I discover the source of problem was in Wildfly 10 server. He append ;jsessionid in links.

To solve i just add the following tag in my web.xml

<session-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>