お読みいただきまして、ありがとうございます。
現在AWSにてEC2+RDS、nginx+unicornでrailsアプリを運用しております。
ご相談したいこと:
nginxを経由した、
xxx.xxx.xxx.xxx(:80)
でcss及びjsが反映されない。
(xxx.xxx.xxx.xxx:3000では反映されています。)
nginxのエラーコード:
2017/11/28 03:08:35 [error] 28xx7#0: *1xxx00 open() "/var/www/my_app/public/assets/application-9f0dfe6ead4aacc77b1a6e6e874aa719.css" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET
/assets/application-9f0dfe6ead4aacc77b1a6e6e874aa719.css HTTP/1.1", host: "xxx.xxx.xxx.xxx", referrer: "http://xxx.xxx.xxx.xxx/"
※ファイルはbundle exec rake assets:precompile RAILS_ENV=productionにて生成済みです。またファイル名も合っています。
※unicornのログではエラーは出ておりません。
/etc/nginx/conf.d/my_app.confの内容:
upstream app_server {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name xxx.xxx.xxx.xxx;
root /var/www/my_app/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
error_page 500 502 503 504 /500.html;
}
/etc/nginx/nginx.confの内容:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; index index.html index.htm; server { listen 80 default_server; listen [::]:80 default_server; server_name localhost; root /usr/share/nginx/html; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
#試したこと
nginx/conf.d/my_appの内容を少し変更したところ、ブラウザで反応がありましたので、nginxが反映されていないということではないようです。
rootあたりかと思うのですが、原因がわかりません。
お忙しいところ恐縮ですが、どなたかお分かりになる方がいらっしゃったらよろしくお願いいたします。
追記:
config/environments/production.rbの内容です。
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/28 05:01
2017/11/28 05:02