4

First, I'm quite confused. I've ssh'ed to our elastic beanstalk instance to peruse where nginx is located etc, and it appears I can't find it.

Clearly, executing a curl command yields headers like:

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

So I assume nginx is there somewhere. I was trying to discover the right location so I could inject a config file via ebextensions.

Essentially, I'm trying to make sure I set cache control in the far future, which this does not seem to be working:

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

It appears that nginx is running via 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

Update I'm using this config on the rails side with cloudfront configured. It's better than nothing though the headers don't match the ideal recommendation.

  #--------------------------------------------------------------------------------
  # 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}"

Still open question: What am I missing? What location should I use to inject additional nginx configuration for standalone passenger?

kross
  • 3,627
  • 2
  • 32
  • 60
  • 1
    It appears that the `nginx` included as part of `passenger-standalone` is not configurable...but I still need to serve up these headers for proper `cloudfront` cdn caching. – kross Oct 28 '13 at 18:23
  • Not sure about passenger, but this answer might help http://stackoverflow.com/questions/18908426/increasing-client-max-body-size-in-nginx-conf-on-aws-elastic-beanstalk – mrmagooey Jan 03 '14 at 03:55
  • @kross did you ever find a solution to this? I'm at the point where the original config is being created from the passgenger gem (and stored in /tmp), but I don't know if I just have to push the entire config, or if I can put in an override snippet/include. – chrisp Jan 14 '14 at 21:41
  • @jacobsd - I never found a solution. I setup the cloudfront instance and tested assets with http://redbot.org/. I'll update my config in original post. – kross Jan 15 '14 at 16:51
  • Here is the file I know you have to edit (through .ebextensions) : /usr/share/ruby/1.9/gems/1.9.1/gems/passenger-4.0.20/resources/templates/standalone/config.erb I don't know how to force passenger to recreate the "/tmp/passenger-standalone.*/config – chrisp Jan 16 '14 at 02:16
  • Correction: I do know how to force passenger to recreate it... but typical /etc/init.d/passenger restart does not work in my instance. – chrisp Jan 16 '14 at 14:32

1 Answers1

1

You can change the configuration that's generated for nginx with passenger standalone by modifying config.erb in "$(passenger-config --root)/resources/templates/standalone". See section 4.3 at http://www.modrails.com/documentation/Users%20guide%20Standalone.html.

Options for modifying it are:

  1. Replace entirely with a .ebextensions/.config files: call
  2. Try to in place change it using a command and some perl regexes

Either of these should work as both execute before the application server is started for the first time through hooks/preinit. Trying to apply it to a running instance may not work. You can kill your existing EC2 instance and autoscaling will spawn another one.

mentat
  • 102
  • 6
  • Could you explain your final statements further? I'm at the point where I can edit the config using .ebextensions and a file: directive. I can not find a way to get passenger to rewrite its config from the template. (I mean automatically... I can ssh and do it by hand but this is ugly.) – chrisp Jan 20 '14 at 01:35
  • If you kill the instance(s) in EC2 it should restart them and the restarted instances should have correctly built configs (as would a new environment or any new instances). – mentat Jan 23 '14 at 23:11