0

下面是我的 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 $1;
          set $month $2;
          set $day $3;
          set $hour $4;
        }

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

每当我打开带有文件扩展名的链接时,它都会显示 404 错误,但是如果我打开没有文件扩展名的相同链接,它可以工作没有文件扩展名的链接。不知道我做错了什么请帮忙

4

1 回答 1

1

尝试禁用 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";
}
于 2020-05-18T04:59:44.233 回答