我正在将一个 rails 4.1.0.rc1 应用程序部署到生产环境中,除了没有提供任何资产外,一切似乎都在工作。
我正在使用 Unicorn 在 Nginx 上部署到 Ubuntu 12.04。Webrick 能够通过以下方式为资产提供服务:
config.serve_static_assets = true
在生产中.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 .
配置/独角兽.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;
}
任何和所有的帮助表示赞赏,这让我很难过!