1

Below is my AWS NGINX config file. I am using rich text with active storage in my new rails app after upload when i am trying to open a file it gives me 404 error in production where in development it works really fine.

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

Whenever i open 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. Not sure what i am doing wrong please help

1 Answer 1

1

Try disabling the below blocks in your Nginx, this might fix it

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";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.