/rails/active_storage/blobs/*文件名(扩展名)的 Nginx 404

Nginx 404 for /rails/active_storage/blobs/*filename(extension)

下面是我的 AWS NGINX 配置文件。上传后,我在我的新 rails 应用程序中使用带有活动存储的富文本,当我试图打开一个文件时,它在生产中给我 404 错误,而在开发中它工作得很好。

files:
  /etc/nginx/conf.d/proxy.conf:
    mode: "000755"
    owner: root
    group: root
    content: |

      upstream backend {
        server unix:///var/run/puma/my_app.sock;
      }

      log_format logd '$msec"$uri"'
                      '$status"$request_time"$upstream_response_time"'
                      '$http_x_forwarded_for';

      server {
        listen 80;
        server_name _ localhost; # need to listen to localhost for worker tier
        return 301 https://$host$request_uri;

      }

      server {
        listen 443;
        charset UTF-8;
        server_name _ localhost; # need to listen to localhost for worker tier


        root /var/app/current/public;    

        # try_files $uri/index.html $uri /deploy/$uri /deploy/$uri.html /deploy/$uri.js @puma;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
          set $year ;
          set $month ;
          set $day ;
          set $hour ;
        }

        access_log  /var/log/nginx/access.log  main;
        access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour logd;


        # 413 Request Entity Too Large
        client_max_body_size 50M;
        large_client_header_buffers 8 32k;

        location / {
          try_files $uri /deploy/$uri /deploy/$uri.html /deploy/$uri.js @puma;
        }


        location @puma{
          proxy_pass http://backend;
          # proxy_pass http://backend; # match the name of upstream directive which is defined above
          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 https;

          # prevents 502 bad gateway error
          proxy_buffers 8 32k;
          proxy_buffer_size 64k;

          proxy_redirect off;
          #break;
        }

        location /assets {
          alias /var/app/current/public/assets;
          allow all;
        }

        location ~ \.(png|jpg|jpeg|gif|ico|html|woff|woff2|ttf|svg|eot|otf|pdf)$ {
          expires max;
          access_log off;
          add_header Cache-Control public;
          add_header Access-Control-Allow-Origin *;
        }

        location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc|pdf)$ {
          access_log off;
          add_header Cache-Control "max-age=2592000";
        }



        if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
          return 405;
        }

        if (-f $document_root/system/maintenance.html) {
          return 503;
        }
      }

每当我打开 Link with file extension it shows me 404 error but if i open the same link without file extension it works Link without file extension。不确定我做错了什么请帮忙

尝试在您的 Nginx 中禁用以下块,这可能会解决问题

location ~ \.(png|jpg|jpeg|gif|ico|html|woff|woff2|ttf|svg|eot|otf|pdf)$ {
  gzip_static on;
  gzip on;
  gzip_comp_level 6;
  gzip_buffers 16 8k;
  gzip_vary on;
  gzip_proxied any;
  expires max;
  access_log off;
  add_header Cache-Control public;
  add_header Access-Control-Allow-Origin *;
}

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc|pdf)$ {
  access_log off;
  add_header Cache-Control "max-age=2592000";
}