Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 Nginx不提供rails 4资产管道中的静态资产_Ruby On Rails 4_Nginx_Server - Fatal编程技术网

Ruby on rails 4 Nginx不提供rails 4资产管道中的静态资产

Ruby on rails 4 Nginx不提供rails 4资产管道中的静态资产,ruby-on-rails-4,nginx,server,Ruby On Rails 4,Nginx,Server,最近几天,我尝试将我的应用程序部署到生产环境中。我已部署finish,但我的应用程序未显示图标 此配置位于app/config/environments/production.rb中 config.cache_classes = true config.eager_load = true config.consider_all_requests_local = false config.action_controller.perform_caching = false config.

最近几天,我尝试将我的应用程序部署到生产环境中。我已部署finish,但我的应用程序未显示图标

此配置位于app/config/environments/production.rb中

config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local       = false
config.action_controller.perform_caching = false
config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
在nginx.conf中

location ~ ^/(assets)/  {
 root /my_public_path_here;
 gzip_static on;
 expires max;
 add_header Cache-Control public;
}

如果您有类似问题,请留言,谢谢

如果静态资产存在,我会使用类似的东西来服务它们

location / {
  try_files $uri @app;
}

location @app {
  # rails app stuff here...
}
也许您只是缺少上面的一条指令。

看看Nginx配置示例,它是一致的、功能齐全的。此配置描述了通过Unix套接字运行的Rails应用程序的Nginx代理。关于您的问题,您的
位置~^/(资产)/{…
部分似乎是正确的

对于
Try\u文件
部分(注意
$uri$uri/index.html$uri.html
):

还要确保
@您的上游名称是正确的上游名称。以防万一,请确保toy已预编译assest;-)


谢谢你的回复。我已经添加了try_文件$uri@myapp;但它不起作用。try_文件有助于复杂的逻辑,但大多数时候root就足够了。一旦没有位置满足要求,root就被用来从磁盘提供文件。你有public/assets/all.js.gz和public/assets/all.css.gz吗?是的,我已经编译了assets,它可以在publ中使用ic/assets.turn access/error logs on并将输出放在此处。@Peter您能提供一些日志或其他配置吗?这是一个非常有趣的问题。我正在试图了解问题所在:Nginx配置错误还是Rails工作不正常。例如,您能直接访问资产吗,即不通过Nginx?这是Nginx日志
E/36.0.1985.143Safari/537.36“118.69.34.46---[20/Nov/2014:17:52:14+0900]“GET/assets/add.png HTTP/1.1”404 198““Mozilla/5.0(X11;Linux x86_64)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/36.0.1985.143 Safari/537.36”118.69.34.46---[20/2014:17:52:14+0900]“GET/assets/export.png HTTP/1.1”404 198/Linux.64““Mozilla/x86”AppleWebKit/537.36(KHTML,比如Gecko)Chrome/36.0.1985.143 Safari/537.36“
  location / {
    ## Serve static files from defined root folder.
    ## @your_up_stream_name is a named location for the upstream fallback, see below.
    try_files $uri $uri/index.html $uri.html @your_up_stream_name;
  }
$ RAILS_ENV=production bundle exec rake assets:precompile