Nie*_*ian 4 assets ruby-on-rails nginx unicorn
我在rails 3.2上,我的生产设置是使用nginx和unicorn.
我有一些资产,一个名为sidekiq的红宝石宝石使用.但是,当我提出要求时,这些资产没有得到妥善处理.我的nginx配置看起来像这样:
upstream unicorn {
server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/deployer/apps/myapp/current/public;
if (-f $document_root/system/maintenance.html) {
return 503;my
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
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://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
if (-f $document_root/system/maintenance.html) {
return 503;
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
从我的浏览器我可以看到它是
例如请求http://www.myapp.com/admin/sidekiq/stylesheets/application.css
.
如果我ssh到服务器并写:
ls /home/deployer/apps/myapp/current/public/admin/sidekiq/stylesheets
application.css bootstrap.css
Run Code Online (Sandbox Code Playgroud)
你可以看到它确实在那里.那么为什么不服务呢?
解决了它,这完全是由于我的production.rb中的错误设置导致默认行为失败,所以无论如何都不需要手动将资产放入/ public.
我有:
config.action_dispatch.x_sendfile_header = "X-Sendfile"
Run Code Online (Sandbox Code Playgroud)
相反,nginx应该是:
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
Run Code Online (Sandbox Code Playgroud)
感谢所有的帮助:-)
归档时间: |
|
查看次数: |
3474 次 |
最近记录: |