Permalink
Browse files

adding in everything

  • Loading branch information...
defunkt committed Apr 24, 2007
0 parents commit 6f876374daf23f95be76f0f94979d717aad6f604
Showing with 286 additions and 0 deletions.
  1. +18 −0 LICENSE
  2. +11 −0 README
  3. +51 −0 config.yml
  4. +38 −0 config.yml.example
  5. +18 −0 generate_nginx_config.rb
  6. +150 −0 nginx.erb
18 LICENSE
@@ -0,0 +1,18 @@
+Copyright (c) 2007 Chris Wanstrath
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 README
@@ -0,0 +1,11 @@
+A work in progress. Check it: http://errtheblog.com/post/#
+
+Use it:
+ $ generate_nginx_config nginx_config.yml /etc/nginx.conf
+
+You can set two environment variables:
+ - NGINX_CONFIG_YAML to specify the YAML config file
+ - NGINX_CONFIG_FILE to specify the nginx config file
+
+>> Chris Wanstrath
+=> chris[at]ozmm[dot]org
@@ -0,0 +1,51 @@
+root:
+ rails: /home/chris/sites/%s/current/public
+ default: /home/chris/sites/%s
+
+sites:
+ errtheblog:
+ upstream: 127.0.0.1:8000
+ server_name: errtheblog.com www.errtheblog.com
+ no_www: true
+ rewrites:
+ - ^/feed/feedburner http://feeds.feedburner.com/errtheblog
+ - ^/feed/atom.xml http://feeds.feedburner.com/errtheblog
+ root: rails
+
+ ozmm:
+ upstream: 127.0.0.1:8010
+ server_name: ozmm.org www.ozmm.org
+ no_www: true
+ root: rails
+
+ cheat:
+ upstream: 127.0.0.1:8020
+ server_name: cheat.errtheblog.com
+
+ subtlety:
+ upstream: 127.0.0.1:8021
+ server_name: subtlety.errtheblog.com
+
+ sfruby:
+ upstream: 127.0.0.1:8030
+ server_name: sfruby.org www.sfruby.org
+ no_www: true
+ root: rails
+
+ cioffi:
+ upstream: 127.0.0.1:8040
+ server_name: legendofcioffi.com www.legenofcioffi.com
+ no_www: true
+ root: rails
+
+ trac:
+ upstream: 127.0.0.1:9000
+ server_name: require.errtheblog.com
+
+ famupdate:
+ server_name: famupdate.com www.famupdate.com
+
+ qa:
+ server_name: qa.famupdate.com
+ auth_file: /home/builder/conf/htpasswd
+ root: /home/builder/site
@@ -0,0 +1,38 @@
+root:
+ rails: /home/chris/sites/%s/current/public
+ default: /home/chris/sites/%s
+
+sites:
+ errtheblog:
+ upstream:
+ - 127.0.0.1:8000
+ - 127.0.0.1:8001
+ server_name: errtheblog.com www.errtheblog.com
+ no_www: true # www.errtheblog.com => errtheblog.com
+ rewrites:
+ - ^/feed/feedburner http://feeds.feedburner.com/errtheblog
+ - ^/feed/atom.xml http://feeds.feedburner.com/errtheblog
+ root: rails
+
+ cheat:
+ upstream: 127.0.0.1:8020
+ server_name: cheat.errtheblog.com
+
+ subtlety:
+ upstream: 127.0.0.1:8021
+ server_name: subtlety.errtheblog.com
+
+ sfruby:
+ upstream: 127.0.0.1:8030
+ server_name: sfruby.org www.sfruby.org
+ no_www: true
+ root: rails
+
+ trac:
+ upstream: 127.0.0.1:9000
+ server_name: require.errtheblog.com
+
+ qa:
+ server_name: qa.secretsite.com
+ auth_file: /home/builder/conf/htpasswd
+ root: /home/builder/site
@@ -0,0 +1,18 @@
+#! /usr/bin/env ruby
+%w(erb yaml).each &method(:require)
+
+def error(message) !puts(message) && exit end
+
+env_in = ENV['NGINX_CONFIG_YAML']
+env_out = ENV['NGINX_CONFIG_FILE']
+
+error "Usage: generate_nginx_config.rb [config file] [out file]" if ARGV.empty? && !env_in
+
+config = YAML.load_file(env_in || ARGV.shift || 'config.yml')
+template = 'nginx.erb'
+
+if File.exists? out_file = env_out || ARGV.shift || 'nginx.conf'
+ error "=> #{out_file} already exists, won't overwrite it. Quitting."
+else
+ open(out_file, 'w+').write(ERB.new(File.read(template), nil, '>').result(binding))
+end
150 nginx.erb
@@ -0,0 +1,150 @@
+## http://brainspl.at/nginx.conf.txt
+
+#user and group to run as
+user nginx nginx;
+
+# number of nginx workers
+worker_processes 2;
+
+# pid of nginx master process
+pid logs/nginx.pid;
+
+# Number of worker connections. 1024 is a good default
+events {
+ worker_connections 1024;
+}
+
+# start the http module where we config http access.
+http {
+ # pull in mime-types. You can break out your config
+ # into as many include's as you want to make it cleaner
+ include conf/mime.types;
+
+ # set a default type for the rare situation that
+ # nothing matches from the mimie-type include
+ default_type application/octet-stream;
+
+ # configure log format
+ log_format main '$remote_addr - $remote_user [$time_local] $status '
+ '"$request" $body_bytes_sent "$http_referer" '
+ '"$http_user_agent" "http_x_forwarded_for"';
+
+ # main access log
+ access_log logs/access.log main;
+
+ # main error log
+ error_log logs/error.log debug;
+ #error_log logs/error.log debug_http;
+
+ # no sendfile on OSX
+ sendfile on;
+
+ # These are good default values.
+ tcp_nopush on;
+ tcp_nodelay off;
+ # output compression saves bandwidth
+ gzip on;
+ gzip_http_version 1.0;
+ gzip_comp_level 2;
+ gzip_proxied any;
+ gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml
+ application/xml+rss text/javascript;
+
+ # this is where you define your mongrel clusters.
+ # you need one of these blocks for each cluster
+ # and each one needs its own name to refer to it later.
+<% config['sites'].each do |name, site| %>
+<% next unless site['upstream'] %>
+ upstream <%= name %> {
+<% Array(site['upstream'] || site['upstreams']).each do |server| %>
+ server <%= server %>;
+<% end %>
+ }
+<% end %>
+
+<% config['sites'].each do |name, site| %>
+ # the server directive is nginx's virtual host directive.
+ server {
+ # port to listen on. Can also be set to an IP:PORT
+ listen 80;
+
+ # sets the domain[s] that this vhost server requests for
+ server_name <%= site['server_name'] %>;
+
+ # doc root
+ root <%= (config['root'][ site['root'] || 'default' ] || site['root']) % name %>;
+
+ # vhost specific access log
+ access_log logs/<%= name %>.access.log main;
+
+ #Set the max size for file uploads to 50Mb
+ client_max_body_size 50M;
+
+ # this rewrites all the requests to the maintenance.html
+ # page if it exists in the doc root. This is for capistrano's
+ # disable web task
+ if (-f $document_root/maintenance.html){
+ rewrite ^(.*)$ /maintenance.html last;
+ break;
+ }
+
+<% if site['no_www'] %>
+ if ($host ~* "www") {
+ rewrite ^(.*)$ http://<%= site['server_name'].split.first %>$1 redirect;
+ break;
+ }
+<% end %>
+
+ location / {
+<% Array(site['rewrite'] || site['rewrites']).each do |rewrite| %>
+ rewrite <%= rewrite %> break;
+<% end %>
+
+<% if site['auth_file'] %>
+ auth_basic "<%= name %> requires credentials.";
+ auth_basic_user_file <%= site['auth_file'] %>;
+<% end %>
+
+ # needed to forward user's IP address to rails
+ proxy_set_header X-Real-IP $remote_addr;
+
+ # needed for HTTPS
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Host $http_host;
+ proxy_redirect false;
+ proxy_max_temp_file_size 0;
+
+ # check for index.html for directory index
+ # if its there on the filesystem then rewite
+ # the url to add /index.html to the end of it
+ # and then break to send it to the next config rules.
+ if (-f $request_filename/index.html) {
+ rewrite (.*) $1/index.html break;
+ }
+
+ # this is the meat of the rails page caching config
+ # it adds .html to the end of the url and then checks
+ # the filesystem for that file. If it exists, then we
+ # rewite the url to have explicit .html on the end
+ # and then send it on its way to the next config rule.
+ # if there is no file on the fs then it sets all the
+ # necessary headers and proxies to our upstream mongrels
+ if (-f $request_filename.html) {
+ rewrite (.*) $1.html break;
+ }
+
+<% if site['upstream'] %>
+ if (!-f $request_filename) {
+ proxy_pass http://<%= name %>;
+ break;
+ }
+<% end %>
+ }
+
+ error_page 500 502 503 504 /50x.html;
+ location = /50x.html {
+ root html;
+ }
+ }
+ <% end %>
+}

0 comments on commit 6f87637

Please sign in to comment.