2017-03-01 4 views
0

私は/に配備されており、レールアプリはサブディレクトリ/h20-initiativeを配備しています。 レールアプリのフロントページが読み込まれますが、静的ファイルはありません。私は間違って何をしていますか?レール5、nginx +パッセンジャーは静的資産を提供できません(404)

ここに私のnginx設定ファイルがあります。

server { 
    listen 80 default_server; 
    listen [::]:80 default_server; 

    root /var/sites/unify_wordpress; 
    index index.php index.html index.htm index.nginx-debian.html; 

    passenger_enabled on; 
    passenger_app_env production; 
    server_name 10.0.15.11; 

    location/{ 
     #try_files $uri $uri/ =404; 
     try_files $uri $uri/ /index.php$is_args$args; 
    } 

    location ~ \.php$ { 
     include snippets/fastcgi-php.conf; 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    } 

    location ~ /\.ht { 
     deny all; 
    } 

    location = /favicon.ico { log_not_found off; access_log off; } 
    location = /robots.txt { log_not_found off; access_log off; allow all; } 
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ { 
     expires max; 
     log_not_found off; 
    } 

    location ~ ^/h20-initiative(/.*|$) { 
     alias /home/vagrant/unify/public$1; # <-- be sure to point to 'public'! 
     passenger_base_uri /h20-initiative; 
     passenger_app_root /home/vagrant/unify; 
     passenger_document_root /home/vagrant/unify/public; 
     passenger_enabled on; 

    } 
    location ~* ^/assets/ { 
    expires 1y; 
    add_header Cache-Control public; 

    add_header Last-Modified ""; 
    add_header ETag ""; 
    break; 
    } 
} 

そしてここにはある/config/enviornments/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 

    # Disable serving static files from the `/public` folder by default since 
    # Apache or NGINX already handles this. 
    config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 

    # Compress JavaScripts and CSS. 
    config.assets.js_compressor = :uglifier 
    # config.assets.css_compressor = :sass 

    # Do not fallback to assets pipeline if a precompiled asset is missed. 
    config.assets.compile = false 

    # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 

    # Enable serving of images, stylesheets, and JavaScripts from an asset server. 
    # config.action_controller.asset_host = 'http://assets.example.com' 

    # Specifies the header that your server uses for sending files. 
    # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 

    # Mount Action Cable outside main process or domain 
    # config.action_cable.mount_path = nil 
    # config.action_cable.url = 'wss://example.com/cable' 
    # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 

    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 
    # config.force_ssl = true 

    # Use the lowest log level to ensure availability of diagnostic information 
    # when problems arise. 
    config.log_level = :debug 

    # Prepend all log lines with the following tags. 
    config.log_tags = [ :request_id ] 

    # Use a different cache store in production. 
    # config.cache_store = :mem_cache_store 

    # Use a real queuing backend for Active Job (and separate queues per environment) 
    # config.active_job.queue_adapter  = :resque 
    # config.active_job.queue_name_prefix = "spam_#{Rails.env}" 
    config.action_mailer.perform_caching = false 

    # Ignore bad email addresses and do not raise email delivery errors. 
    # Set this to true and configure the email server for immediate delivery to raise delivery errors. 
    # config.action_mailer.raise_delivery_errors = false 

    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 
    # the I18n.default_locale when a translation cannot be found). 
    config.i18n.fallbacks = true 

    # Send deprecation notices to registered listeners. 
    config.active_support.deprecation = :notify 

    # Use default logging formatter so that PID and timestamp are not suppressed. 
    config.log_formatter = ::Logger::Formatter.new 

    # Use a different logger for distributed setups. 
    # require 'syslog/logger' 
    # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 

    if ENV["RAILS_LOG_TO_STDOUT"].present? 
    logger   = ActiveSupport::Logger.new(STDOUT) 
    logger.formatter = config.log_formatter 
    config.logger = ActiveSupport::TaggedLogging.new(logger) 
    end 

    # Do not dump schema after migrations. 
    config.active_record.dump_schema_after_migration = false 
end 

UPDATE:

http://localhost:8080/h20-initiative/assets/application-eca7aa380d6901462faf375c03979ed8fd1292bda70e3321f82c272e050290d3.css

私のブラウザでのdevのツールを使用して、ここでは発見されず、例えば資産があります

その正確なファイルが@SeanHuberからの提案へ

That exact file _does_ exist in my public directory (at least I think) 

app_root $ find public/ -name "application-eca7aa380d6901462faf375c03979ed8fd1292bda70e3321f82c272e050290d3.css" 
public/assets/application-eca7aa380d6901462faf375c03979ed8fd1292bda70e3321f82c272e050290d3.css 
+0

'config.relative_url_root'が設定されていることを確認してください:http://guides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root –

+0

@SeanHuberありがとうございます。私はこの設定を追加し、nginxを再起動しました。何も変更されていません – stoebelj

+0

変更後にアセットを再コンパイルする必要があります。 –

答えて

0

おかげで(少なくとも私は思う)私の公開ディレクトリに存在しない、私は/etc/nginx/nginx.confに行き、それを行うにはdebug

に私のnginxのログレベルを設定します。

2017/03/01 02:02:31 [debug] 28274#28274: *231 test location: "/" 
2017/03/01 02:02:31 [debug] 28274#28274: *231 test location: "robots.txt" 
2017/03/01 02:02:31 [debug] 28274#28274: *231 test location: "favicon.ico" 
2017/03/01 02:02:31 [debug] 28274#28274: *231 test location: ~ "\.php$" 
2017/03/01 02:02:31 [debug] 28274#28274: *231 test location: ~ "/\.ht" 
2017/03/01 02:02:31 [debug] 28274#28274: *231 test location: ~ "\.(css|gif|ico|jpeg|jpg|js|png)$" 
2017/03/01 02:02:31 [debug] 28274#28274: *231 using configuration "\.(css|gif|ico|jpeg|jpg|js|png)$" 
:私はこれらの行を提供されていませんでした資産の一つで検索し、見つかった...

をラインerror_log /var/log/nginx/error.log;を見つけ、error_log /var/log/nginx/error.log debug;

その後

私はログをgrepedに変更します

ブロック"\.(css|gif|ico|jpeg|jpg|js|png)$"は一致したブロックで、ファイルの場所を特定するために使用されたようです。問題は、それがファイルの場所ではないということです!実際、ルートディレクトリからアセットを提供する必要はありません。私はそのブロックを削除し、目的のブロックが資産を提供できるようにしました。

関連する問題