【问题标题】:assets not being served in production with rails 4.1.0.rc1 nginx and unicornrails 4.1.0.rc1 nginx 和 unicorn 未在生产环境中提供资产
【发布时间】:2014-04-13 11:19:11
【问题描述】:

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

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

config.serve_static_assets = true

在生产.rb.

有趣的是,在 nginx/unicorn 下,资产是在没有指纹的情况下被引用的。 IE /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

config/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;
}

感谢所有帮助,这让我很难过!

【问题讨论】:

  • 您是否预编译了资产?
  • 感谢您的回复,是的,我做到了。我可以看到编译后的资产,webrick 能够提供它们。

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


【解决方案1】:

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

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

【讨论】:

  • 我在“error_page”正上方添加了该块,重新启动但仍然没有运气。资产仍在页面源中显示,没有指纹。
猜你喜欢
  • 2014-04-21
  • 2014-06-15
  • 2013-07-28
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
  • 2015-01-18
  • 1970-01-01
  • 2022-11-10
相关资源
最近更新 更多