diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/logrotate.conf | 29 | ||||
-rw-r--r-- | examples/nginx.conf | 33 | ||||
-rw-r--r-- | examples/unicorn.conf.rb | 12 |
3 files changed, 61 insertions, 13 deletions
diff --git a/examples/logrotate.conf b/examples/logrotate.conf new file mode 100644 index 0000000..03fefc6 --- /dev/null +++ b/examples/logrotate.conf @@ -0,0 +1,29 @@ +# example logrotate config file, I usually keep this in +# /etc/logrotate.d/unicorn_app on my Debian systems +# +# See the logrotate(8) manpage for more information: +# http://linux.die.net/man/8/logrotate + +# Modify the following glob to match the logfiles your app writes to: +/var/log/unicorn_app/*.log { + # this first block is mostly just personal preference, though + # I wish logrotate offered an "hourly" option... + daily + missingok + rotate 180 + compress # must use with delaycompress below + dateext + + # this is important if using "compress" since we need to call + # the "lastaction" script below before compressing: + delaycompress + + # note the lack of the evil "copytruncate" option in this + # config. Unicorn supports the USR1 signal and we send it + # as our "lastaction" action: + lastaction + # assuming your pid file is in /var/run/unicorn_app/pid + pid=/var/run/unicorn_app/pid + test -s $pid && kill -USR1 "$(cat $pid)" + endscript +} diff --git a/examples/nginx.conf b/examples/nginx.conf index d42ade8..9f245c8 100644 --- a/examples/nginx.conf +++ b/examples/nginx.conf @@ -83,9 +83,9 @@ http { } server { + # enable one of the following if you're on Linux or FreeBSD # listen 80 default deferred; # for Linux # listen 80 default accept_filter=httpready; # for FreeBSD - listen 80 default; client_max_body_size 4G; server_name _; @@ -98,7 +98,16 @@ http { # path for static files root /path/to/app/current/public; - location / { + # Prefer to serve static files directly from nginx to avoid unnecessary + # data copies from the application server. + # + # try_files directive appeared in in nginx 0.7.27 and has stabilized + # over time. Older versions of nginx (e.g. 0.6.x) requires + # "if (!-f $request_filename)" which was less efficient: + # http://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127 + try_files $uri/index.html $uri.html $uri @app; + + location @app { # an HTTP header important enough to have its own Wikipedia entry: # http://en.wikipedia.org/wiki/X-Forwarded-For proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -116,18 +125,18 @@ http { proxy_redirect off; # set "proxy_buffering off" *only* for Rainbows! when doing - # Comet/long-poll stuff. It's also safe to set if you're - # using only serving fast clients with Unicorn + nginx. - # Otherwise you _want_ nginx to buffer responses to slow - # clients, really. + # Comet/long-poll/streaming. It's also safe to set if you're using + # only serving fast clients with Unicorn + nginx, but not slow + # clients. You normally want nginx to buffer responses to slow + # clients, even with Rails 3.1 streaming because otherwise a slow + # client can become a bottleneck of Unicorn. + # + # The Rack application may also set "X-Accel-Buffering (yes|no)" + # in the response headers do disable/enable buffering on a + # per-response basis. # proxy_buffering off; - # Try to serve static files from nginx, no point in making an - # *application* server like Unicorn/Rainbows! serve static files. - if (!-f $request_filename) { - proxy_pass http://app_server; - break; - } + proxy_pass http://app_server; } # Rails error pages diff --git a/examples/unicorn.conf.rb b/examples/unicorn.conf.rb index 37c3e81..61f0b4b 100644 --- a/examples/unicorn.conf.rb +++ b/examples/unicorn.conf.rb @@ -12,6 +12,13 @@ # more will usually help for _short_ waits on databases/caches. worker_processes 4 +# Since Unicorn is never exposed to outside clients, it does not need to +# run on the standard HTTP port (80), there is no reason to start Unicorn +# as root unless it's from system init scripts. +# If running the master process as root and the workers as an unprivileged +# user, do this to switch euid/egid in the workers (also chowns logs): +# user "unprivileged_user", "unprivileged_group" + # Help ensure your application will always spawn in the symlinked # "current" directory that Capistrano sets up. working_directory "/path/to/app/current" # available in 0.94.0+ @@ -63,7 +70,10 @@ before_fork do |server, worker| # end # end # - # # *optionally* throttle the master from forking too quickly by sleeping + # Throttle the master from forking too quickly by sleeping. Due + # to the implementation of standard Unix signal handlers, this + # helps (but does not completely) prevent identical, repeated signals + # from being lost when the receiving process is busy. # sleep 1 end |