4

首先,我很困惑。我已经 ssh'ed 到我们的弹性 beanstalk 实例以仔细阅读 nginx 所在的位置等,但似乎我找不到它。

显然,执行 curl 命令会产生如下标题:

Content-Encoding: gzip
Content-Type: text/css
Date: Wed, 23 Oct 2013 20:33:53 GMT
Last-Modified: Wed, 23 Oct 2013 18:59:04 GMT
Server: nginx/1.2.3
transfer-encoding: chunked
Connection: keep-alive

所以我假设 nginx 就在某个地方。我试图找到正确的位置,以便可以通过 ebextensions 注入配置文件。

本质上,我试图确保在遥远的将来设置缓存控制,这似乎不起作用:

  03-nginx.config:
    files:
      "/etc/nginx/conf.d/custom.conf" :
        mode: "000777"
        owner: ec2-user
        owner: ec2-user
        content: |
            location ~ ^/assets/ {
              expires 1y;
              add_header Cache-Control public;

              add_header ETag "";
              break;
            }

似乎nginx正在通过passenger-standalone.

[ec2-user@ip-10-196-221-244 support]$ pwd
/var/app/support
[ec2-user@ip-10-196-221-244 support]$ ls pids
passenger.pid  passenger.pid.lock
[ec2-user@ip-10-196-221-244 support]$ cat pids/passenger.pid
1781
[ec2-user@ip-10-196-221-244 support]$ ps -eaf | grep 1781
root      1781     1  0 Sep25 ?        00:00:00 nginx: master process /var/lib/passenger-standalone/3.0.17-x86_64-ruby1.9.3-linux-gcc4.6.2-1002/nginx-1.2.3/sbin/nginx -c /tmp/passenger-standalone.1704/config -p /tmp/passenger-standalone.1704/
webapp    1782  1781  0 Sep25 ?        00:00:57 nginx: worker process                                                                                                                                                       
ec2-user 26387 25743  0 10:53 pts/0    00:00:00 grep 1781

更新 我在配置了 cloudfront 的 rails 端使用这个配置。尽管标题与理想的推荐不符,但总比没有好。

  #--------------------------------------------------------------------------------
  # CDN
  #   Enable serving of images, stylesheets, and JavaScripts from an asset server
  #   http://thediscoblog.com/blog/2013/05/01/the-rails-cloudfront-and-heroku-performance-hat-trick/
  #   http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html
  #   http://www.mnot.net/cache_docs/
  #   Check with http://redbot.org/
  #   - set asset host
  #--------------------------------------------------------------------------------
  config.action_controller.asset_host = "http://cdn.staging.acme.com"
  config.assets.compress = true # Compress JavaScripts and CSS
  config.assets.compile = false # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.digest = true # Generate digests for assets URLs
  # must do this so we can inject the proper cache-control headers for cloudfront, served very few times anyways...
  #config.serve_static_assets = true
  config.static_cache_control = "public, max-age=#{1.year.to_i}"

仍然悬而未决的问题: 我错过了什么?我应该使用什么位置nginx为独立乘客注入额外的配置?

4

1 回答 1

1

您可以通过修改“$(passenger-config --root)/resources/templates/standalone”中的 config.erb 来更改为带有乘客独立的 nginx 生成的配置。请参阅http://www.modrails.com/documentation/Users%20guide%20Standalone.html上的第 4.3 节。

修改它的选项是:

  1. 完全替换为 .ebextensions/.config 文件:调用
  2. 尝试使用命令和一些 perl 正则表达式来更改它

这些中的任何一个都应该在应用服务器第一次通过 hooks/preinit 启动之前执行。尝试将其应用于正在运行的实例可能不起作用。您可以终止现有的 EC2 实例,自动缩放将生成另一个实例。

于 2014-01-17T01:39:21.273 回答