0

I have this location directive defined:

location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
  expires max;
  add_header Cache-Control public;
}

But it catches requests that look like this:

request: "GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename?locale=en HTTP/1.1"

If I delete jpg from the above directive and my request contains this type of file, nginx handles the request correctly and redirects to Active Storage controller.

However, I want to keep the above directive as is, but exclude requests that look like the one above.

I've tried this:

location ^~ /rails/active_storage {
  root /;
}

But it treats it as a file and returns:

open() "/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBdndGIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--58ed77b42559b9db0ec3c3abbd6a028a9f8b2257/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9MY21WemFYcGxTU0lLTXpCNE1qQUdPZ1pGVkE9PSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--6dfdb387ea3ee27450879124ed743b07a3094987/2_mar.jpeg" failed (2: No such file or directory)

What am I doing wrong?

Server blocks:

server {
  include path/to_file;
  listen 80 default deferred;
}

server {
 listen 443 ssl;
 ssl_certificate_key /etc/letsencrypt/live/smth;
 ssl_certificate /etc/letsencrypt/live/smth;
}

From /path/to/file:

root /var/www/smth/current/public;

error_page 500 502 503 504 /500.html;
client_max_body_size 25M;
keepalive_timeout 10;

try_files /maintenance.html $uri/index.html $uri @unicorn;

location ~* /sidekiq/ {
  try_files $uri @unicorn;
}

location ^~ /assets/ {
  expires max;
  add_header Cache-Control public;
}

location ^~ /images/ {
  expires max;
  add_header Cache-Control public;
}

location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
  expires max;
  add_header Cache-Control public;
}

location @unicorn {
  limit_req zone=webserver_req_limit_per_ip burst=100 nodelay;

  # track request queuing in newRelic
  proxy_set_header X-Request-Start "t=${msec}";

  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;
  proxy_pass http://unicorn;
  proxy_read_timeout 120s;
}
  • Show full server block. Including all includes – Alexey Ten Jun 9 at 15:00
  • @AlexeyTen I added server blocks. – kondor Jun 9 at 15:15
  • Can’t see location you’ve mentioned in question – Alexey Ten Jun 9 at 15:36
  • Also can’t see @inicorn block. Means that’s not full server block – Alexey Ten Jun 9 at 15:38
  • @AlexeyTen Sorry for that, I added location blocks as well. – kondor Jun 9 at 15:39

Your Answer

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

Browse other questions tagged or ask your own question.