没有使用rails 4.1.0.rc1 nginx和unicorn在生产中提供资产

时间:2014-03-10 11:21:06

标签: ruby-on-rails nginx unicorn ruby-on-rails-4.1

我正在将rails 4.1.0.rc1应用程序部署到生产环境,除了没有提供任何资产外,一切似乎都在工作。

我正在使用Unicorn在Nginx上部署到Ubuntu 12.04。 Webrick能够通过以下方式提供资产:

config.serve_static_assets = true

in production.rb。

有趣的是,在nginx / unicorn下,没有指纹就会引用资产。即 /assets/application.css 代替 /assets/application-2c83bb5c879fd170625884df41e4b778.css

当然,当nginx去服务资产时,它不存在。这只是unicorn / nginx设置的一个问题,在webrick下生产(本地和服务器上)正确的文件名存在且资产正确提供。

除了操作系统特定部分,我一直关注https://www.digitalocean.com/community/articles/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5

配置/ unicorn.rb

# Set the working application directory
# working_directory "/path/to/your/app"
working_directory "/var/www/citysquares"

# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "/var/www/citysquares/pids/unicorn.pid"

# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "/var/www/citysquares/log/unicorn.log"
stdout_path "/var/www/citysquares/log/unicorn.log"

# Unicorn socket
listen "/tmp/unicorn.[app name].sock"
listen "/tmp/unicorn.citysquares.sock"

# Number of processes
# worker_processes 4
worker_processes 2

# Time-out
timeout 30

/etc/nginx/conf.d/default.conf

upstream app {
    # Path to Unicorn SOCK file, as defined previously
    server unix:/tmp/unicorn.citysquares.sock fail_timeout=0;
}

server {


    listen 80;
    server_name localhost;

    # Application root, as defined previously
    #root /root/citysquares/public;
    root /var/www/citysquares/public;

    try_files $uri/index.html $uri @app;

    location @app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}

任何和所有的帮助表示赞赏,这让我很难过!

1 个答案:

答案 0 :(得分:0)

尝试在配置中添加“assets”块并重新启动nginx

server {
  # . . .
  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }
  # . . .
}