The locally precompiled manifest file cannot be read from the AWS production environment.

Asked 1 years ago, Updated 1 years ago, 98 views

I couldn't understand the cause and got stuck, so I'd like to ask you a question.
The title is correct.

I am deploying to the server after running assembets:precompile locally, but I am having trouble because the manifest file is not reflected.
(Only images are reflected, but stylesheets and javascripts are not.)

Below are the things I have confirmed.

  • Deleting browser cache and Nginx cache, restarting Nginx, Unicorn, and checking operation in secret window
  • I've also changed the browser user agent to verify its operation
  • The contents of the manifest file are exactly the same
  • The developer tool has successfully called all associates and returned 200,304 status codes
  • css,javascript files directly link to verify correct path
  • In the local production environment, assets are reflected successfully
  • After downloading the file group locally to see if assocets are reflected,

↓ reflects css, but

<link rel="stylesheet" media="all" href="http://localhost:3000/assets/application-34ad617bfadb73ed23d5a75.cs"data-turbolinks-track="true">

↓ does not reflect css

<link rel="stylesheet" media="all" href="http://ec2-****.ap-northeast-1.compute.amazonaws.com/assets/application-34ad617bfadb73ed23d5a75.css"data-turbolinks-track="true">

This situation (both of them are exactly the same), except that the server is different between the local and AWS environments.We use WEBrick locally and Nginx+Unicorn in AWS environments.

Based on this, I thought that the setting of Nginx might be suspicious, so I have tried many things, but it has not been improved.The following are the settings for /etc/nginx/nginx.conf, the relevant settings for production.rb, and the operating environment:
Thank you for your advice.

events{
  worker_connections2048;
}
US>http{
  upstream unicorn {
    server unix: /tmp/unicorn.sock;
  }
  server{
    listen80;
    server_name localhost;
    root/var/www/app;
    error_log/var/www/app/log/nginx.log;
    location~^/assets/{
      root/var/www/app/public;
    }
    location / {
      if (-f$request_filename) {break;}
      proxy_set_header X-Real-IP$remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_pass http://unicorn;
    }
  }
}

-

config.serve_static_files=ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.compile=false
config.assets.digest=true

-

  • Rails 4.2.0
  • Ruby 2.2.0
  • rbenv0.4.0
  • Unicorn 4.8.3
  • Nginx 1.6.2
  • MySQL 5.5.40
  • EC2 Amazon Linux AMI 2014.09.1 (HVM) (Production Machine)
  • Git (Repository Machine)

ruby-on-rails nginx aws unicorn

2022-09-30 11:39

1 Answers

It's not an answer, it's a question.

Questions

server_name localhost;

Therefore, I wonder if this conf is not used.
Does the server name match localhost?

Is there a possibility that other nginx.conf is starting?

However,

You can see it even if you type the URL directly.
Unicorn

So it may not matter.
As part of the problem isolation, it would be good if you could confirm it.

http://ec2-****.ap-northeast-1.compute.amazonaws.com/assets/application-34ad617bfadb73ed23d5a75.css

You can infer that the html that rails render is incorrect, since you can see that you hit directly.

You may find the problem by looking at the links that rails on the server output.


2022-09-30 11:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.