nginx_config_generator 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +18 -0
- data/Manifest.txt +8 -0
- data/README +17 -0
- data/Rakefile +9 -0
- data/bin/generate_nginx_config +2 -0
- data/lib/config.yml.example +48 -0
- data/lib/nginx.erb +150 -0
- data/lib/nginx_config_generator.rb +27 -0
- metadata +53 -0
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2007 Chris Wanstrath
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/README
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
A work in progress. Check it: http://errtheblog.com/post/#
|
2
|
+
|
3
|
+
Use it:
|
4
|
+
$ generate_nginx_config nginx_config.yml /etc/nginx.conf
|
5
|
+
|
6
|
+
See an example config file:
|
7
|
+
$ generate_nginx_config --example
|
8
|
+
|
9
|
+
You can set two environment variables:
|
10
|
+
- NGINX_CONFIG_YAML to specify the YAML config file
|
11
|
+
- NGINX_CONFIG_FILE to specify the nginx config file
|
12
|
+
|
13
|
+
By default, generate_nginx_config won't overwrite your OUT file. To rock this behavior,
|
14
|
+
pass in --overwrite or -o or -y or --force or -f. Whichever.
|
15
|
+
|
16
|
+
>> Chris Wanstrath
|
17
|
+
=> chris[at]ozmm[dot]org
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# This defines the default roots and alternate roots.
|
2
|
+
# The name (or key) of your site will be sprintf'd with
|
3
|
+
# the below root, right.
|
4
|
+
root:
|
5
|
+
rails: /home/chris/sites/%s/current/public
|
6
|
+
default: /home/chris/sites/%s
|
7
|
+
|
8
|
+
# All your vhosts.
|
9
|
+
sites:
|
10
|
+
# We're naming this vhost 'errtheblog'
|
11
|
+
errtheblog:
|
12
|
+
# Two upstream servers to proxy balance.
|
13
|
+
upstream:
|
14
|
+
- 127.0.0.1:8000
|
15
|
+
- 127.0.0.1:8001
|
16
|
+
# Just a string of server names.
|
17
|
+
server_name: errtheblog.com www.errtheblog.com
|
18
|
+
# www.errtheblog.com => errtheblog.com
|
19
|
+
no_www: true
|
20
|
+
# Just strings that get spit out as rewrites
|
21
|
+
rewrites:
|
22
|
+
- ^/feed/feedburner http://feeds.feedburner.com/errtheblog
|
23
|
+
- ^/feed/atom.xml http://feeds.feedburner.com/errtheblog
|
24
|
+
# Which root to use. You can add a custom one here, too.
|
25
|
+
root: rails
|
26
|
+
|
27
|
+
cheat:
|
28
|
+
upstream: 127.0.0.1:8020
|
29
|
+
server_name: cheat.errtheblog.com
|
30
|
+
|
31
|
+
subtlety:
|
32
|
+
upstream: 127.0.0.1:8021
|
33
|
+
server_name: subtlety.errtheblog.com
|
34
|
+
|
35
|
+
sfruby:
|
36
|
+
upstream: 127.0.0.1:8030
|
37
|
+
server_name: sfruby.org www.sfruby.org
|
38
|
+
no_www: true
|
39
|
+
root: rails
|
40
|
+
|
41
|
+
trac:
|
42
|
+
upstream: 127.0.0.1:9000
|
43
|
+
server_name: require.errtheblog.com
|
44
|
+
|
45
|
+
qa:
|
46
|
+
server_name: qa.famupdate.com
|
47
|
+
auth_file: /home/builder/conf/htpasswd
|
48
|
+
root: /home/builder/site
|
data/lib/nginx.erb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
## http://brainspl.at/nginx.conf.txt
|
2
|
+
|
3
|
+
#user and group to run as
|
4
|
+
user nginx nginx;
|
5
|
+
|
6
|
+
# number of nginx workers
|
7
|
+
worker_processes 2;
|
8
|
+
|
9
|
+
# pid of nginx master process
|
10
|
+
pid logs/nginx.pid;
|
11
|
+
|
12
|
+
# Number of worker connections. 1024 is a good default
|
13
|
+
events {
|
14
|
+
worker_connections 1024;
|
15
|
+
}
|
16
|
+
|
17
|
+
# start the http module where we config http access.
|
18
|
+
http {
|
19
|
+
# pull in mime-types. You can break out your config
|
20
|
+
# into as many include's as you want to make it cleaner
|
21
|
+
include conf/mime.types;
|
22
|
+
|
23
|
+
# set a default type for the rare situation that
|
24
|
+
# nothing matches from the mimie-type include
|
25
|
+
default_type application/octet-stream;
|
26
|
+
|
27
|
+
# configure log format
|
28
|
+
log_format main '$remote_addr - $remote_user [$time_local] $status '
|
29
|
+
'"$request" $body_bytes_sent "$http_referer" '
|
30
|
+
'"$http_user_agent" "http_x_forwarded_for"';
|
31
|
+
|
32
|
+
# main access log
|
33
|
+
access_log logs/access.log main;
|
34
|
+
|
35
|
+
# main error log
|
36
|
+
error_log logs/error.log debug;
|
37
|
+
#error_log logs/error.log debug_http;
|
38
|
+
|
39
|
+
# no sendfile on OSX
|
40
|
+
sendfile on;
|
41
|
+
|
42
|
+
# These are good default values.
|
43
|
+
tcp_nopush on;
|
44
|
+
tcp_nodelay off;
|
45
|
+
# output compression saves bandwidth
|
46
|
+
gzip on;
|
47
|
+
gzip_http_version 1.0;
|
48
|
+
gzip_comp_level 2;
|
49
|
+
gzip_proxied any;
|
50
|
+
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml
|
51
|
+
application/xml+rss text/javascript;
|
52
|
+
|
53
|
+
# this is where you define your mongrel clusters.
|
54
|
+
# you need one of these blocks for each cluster
|
55
|
+
# and each one needs its own name to refer to it later.
|
56
|
+
<% config['sites'].each do |name, site| %>
|
57
|
+
<% next unless site['upstream'] %>
|
58
|
+
upstream <%= name %> {
|
59
|
+
<% Array(site['upstream'] || site['upstreams']).each do |server| %>
|
60
|
+
server <%= server %>;
|
61
|
+
<% end %>
|
62
|
+
}
|
63
|
+
<% end %>
|
64
|
+
|
65
|
+
<% config['sites'].each do |name, site| %>
|
66
|
+
# the server directive is nginx's virtual host directive.
|
67
|
+
server {
|
68
|
+
# port to listen on. Can also be set to an IP:PORT
|
69
|
+
listen 80;
|
70
|
+
|
71
|
+
# sets the domain[s] that this vhost server requests for
|
72
|
+
server_name <%= site['server_name'] %>;
|
73
|
+
|
74
|
+
# doc root
|
75
|
+
root <%= (config['root'][ site['root'] || 'default' ] || site['root']) % name %>;
|
76
|
+
|
77
|
+
# vhost specific access log
|
78
|
+
access_log logs/<%= name %>.access.log main;
|
79
|
+
|
80
|
+
#Set the max size for file uploads to 50Mb
|
81
|
+
client_max_body_size 50M;
|
82
|
+
|
83
|
+
# this rewrites all the requests to the maintenance.html
|
84
|
+
# page if it exists in the doc root. This is for capistrano's
|
85
|
+
# disable web task
|
86
|
+
if (-f $document_root/maintenance.html){
|
87
|
+
rewrite ^(.*)$ /maintenance.html last;
|
88
|
+
break;
|
89
|
+
}
|
90
|
+
|
91
|
+
<% if site['no_www'] %>
|
92
|
+
if ($host ~* "www") {
|
93
|
+
rewrite ^(.*)$ http://<%= site['server_name'].split.first %>$1 redirect;
|
94
|
+
break;
|
95
|
+
}
|
96
|
+
<% end %>
|
97
|
+
|
98
|
+
location / {
|
99
|
+
<% Array(site['rewrite'] || site['rewrites']).each do |rewrite| %>
|
100
|
+
rewrite <%= rewrite %> break;
|
101
|
+
<% end %>
|
102
|
+
|
103
|
+
<% if site['auth_file'] %>
|
104
|
+
auth_basic "<%= name %> requires credentials.";
|
105
|
+
auth_basic_user_file <%= site['auth_file'] %>;
|
106
|
+
<% end %>
|
107
|
+
|
108
|
+
# needed to forward user's IP address to rails
|
109
|
+
proxy_set_header X-Real-IP $remote_addr;
|
110
|
+
|
111
|
+
# needed for HTTPS
|
112
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
113
|
+
proxy_set_header Host $http_host;
|
114
|
+
proxy_redirect false;
|
115
|
+
proxy_max_temp_file_size 0;
|
116
|
+
|
117
|
+
# check for index.html for directory index
|
118
|
+
# if its there on the filesystem then rewite
|
119
|
+
# the url to add /index.html to the end of it
|
120
|
+
# and then break to send it to the next config rules.
|
121
|
+
if (-f $request_filename/index.html) {
|
122
|
+
rewrite (.*) $1/index.html break;
|
123
|
+
}
|
124
|
+
|
125
|
+
# this is the meat of the rails page caching config
|
126
|
+
# it adds .html to the end of the url and then checks
|
127
|
+
# the filesystem for that file. If it exists, then we
|
128
|
+
# rewite the url to have explicit .html on the end
|
129
|
+
# and then send it on its way to the next config rule.
|
130
|
+
# if there is no file on the fs then it sets all the
|
131
|
+
# necessary headers and proxies to our upstream mongrels
|
132
|
+
if (-f $request_filename.html) {
|
133
|
+
rewrite (.*) $1.html break;
|
134
|
+
}
|
135
|
+
|
136
|
+
<% if site['upstream'] %>
|
137
|
+
if (!-f $request_filename) {
|
138
|
+
proxy_pass http://<%= name %>;
|
139
|
+
break;
|
140
|
+
}
|
141
|
+
<% end %>
|
142
|
+
}
|
143
|
+
|
144
|
+
error_page 500 502 503 504 /50x.html;
|
145
|
+
location = /50x.html {
|
146
|
+
root html;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
<% end %>
|
150
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
%w(erb yaml).each &method(:require)
|
3
|
+
|
4
|
+
def error(message) puts(message) || exit end
|
5
|
+
def file(file) "#{File.dirname(__FILE__)}/#{file}" end
|
6
|
+
|
7
|
+
if ARGV.include? '--example'
|
8
|
+
example = file:'config.yml.example'
|
9
|
+
error open(example).read
|
10
|
+
end
|
11
|
+
|
12
|
+
env_in = ENV['NGINX_CONFIG_YAML']
|
13
|
+
env_out = ENV['NGINX_CONFIG_FILE']
|
14
|
+
|
15
|
+
error "Usage: generate_nginx_config [config file] [out file]" if ARGV.empty? && !env_in
|
16
|
+
|
17
|
+
overwrite = !(%w(-y -o -f --force --overwrite) & ARGV).empty?
|
18
|
+
|
19
|
+
config = YAML.load_file(env_in || ARGV.shift || 'config.yml')
|
20
|
+
template = file:'nginx.erb'
|
21
|
+
|
22
|
+
if File.exists?(out_file = env_out || ARGV.shift || 'nginx.conf') && !overwrite
|
23
|
+
error "=> #{out_file} already exists, won't overwrite it. Quitting."
|
24
|
+
else
|
25
|
+
open(out_file, 'w+').write(ERB.new(File.read(template), nil, '>').result(binding))
|
26
|
+
error "=> Wrote #{out_file} successfully."
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: nginx_config_generator
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "1.0"
|
7
|
+
date: 2007-04-28 00:00:00 -07:00
|
8
|
+
summary: ""
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: chris@ozmm.org
|
12
|
+
homepage: http://require.errtheblog.com/projects
|
13
|
+
rubyforge_project: err
|
14
|
+
description: ""
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Chris Wanstrath
|
31
|
+
files:
|
32
|
+
- LICENSE
|
33
|
+
- Manifest.txt
|
34
|
+
- README
|
35
|
+
- Rakefile
|
36
|
+
- bin/generate_nginx_config
|
37
|
+
- lib/config.yml.example
|
38
|
+
- lib/nginx.erb
|
39
|
+
- lib/nginx_config_generator.rb
|
40
|
+
test_files: []
|
41
|
+
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
executables:
|
47
|
+
- generate_nginx_config
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
dependencies: []
|
53
|
+
|