Nginx:不根据请求提供文件

Nginx:不根据请求提供文件

我已经定义了这个位置指令:

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

但它会捕获如下请求:

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

如果我删除图片从上述指令并且我的请求包含这种类型的文件,nginx 正确处理请求并重定向到 Active Storage 控制器。

但是,我想保留上述指令,但排除与上述类似的请求。

我尝试过这个:

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

但它将其视为一个文件并返回:

打开()“/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBdndGIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--58ed77b42559b9db0ec3c3abbd6a028a9f8b2257/eyJfcm FpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9MY21WemFYcGxTU0lLTXpCNE1qQUdPZ1pGVkE9PSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--6dfdb387ea3ee27450879124ed743b07a3094987/2_mar.jpeg”失败(2:没有此文件或目录)

我究竟做错了什么?

服务器块:

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;
}

从 /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;
}

相关内容