nginx_config_generator 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  LICENSE
2
- Manifest.txt
2
+ Manifest
3
3
  README
4
4
  Rakefile
5
5
  bin/generate_nginx_config
data/README CHANGED
@@ -1,4 +1,7 @@
1
- A work in progress. Check it: http://errtheblog.com/post/#
1
+ A work in progress.
2
+
3
+ Check it:
4
+ http://errtheblog.com/post/3908
2
5
 
3
6
  Use it:
4
7
  $ generate_nginx_config nginx_config.yml /etc/nginx.conf
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'echoe'
3
3
 
4
- Echoe.new('nginx_config_generator', '1.0') do |p|
4
+ Echoe.new('nginx_config_generator', '1.1') do |p|
5
5
  p.rubyforge_name = 'err'
6
6
  p.author = 'Chris Wanstrath'
7
7
  p.email = 'chris@ozmm.org'
@@ -46,3 +46,24 @@ sites:
46
46
  server_name: qa.famupdate.com
47
47
  auth_file: /home/builder/conf/htpasswd
48
48
  root: /home/builder/site
49
+
50
+ ssl_sites:
51
+ errtheblog:
52
+ # ssl configuration
53
+ ssl:
54
+ key: /path/to/err.key
55
+ cert: /path/to/err.crt
56
+ # SSL only allows one vhost per IP this can be solved if you have multiple IPs.
57
+ listen: 10.10.10.1:443
58
+ # Two upstream servers to proxy balance.
59
+ upstream:
60
+ - 127.0.0.1:8000
61
+ - 127.0.0.1:8001
62
+ no_www: true
63
+ # Just strings that get spit out as rewrites
64
+ rewrites:
65
+ - ^/feed/feedburner http://feeds.feedburner.com/errtheblog
66
+ - ^/feed/atom.xml http://feeds.feedburner.com/errtheblog
67
+ # Which root to use. You can add a custom one here, too.
68
+ root: rails
69
+
data/lib/nginx.erb CHANGED
@@ -34,7 +34,7 @@ http {
34
34
 
35
35
  # main error log
36
36
  error_log logs/error.log debug;
37
- #error_log logs/error.log debug_http;
37
+ #error_log logs/error.log debug_http;
38
38
 
39
39
  # no sendfile on OSX
40
40
  sendfile on;
@@ -62,15 +62,37 @@ http {
62
62
  }
63
63
  <% end %>
64
64
 
65
- <% config['sites'].each do |name, site| %>
65
+ <% %w(sites ssl_sites).each do |site_type| %>
66
+
67
+ <% config[site_type].each do |name, site| %>
66
68
  # the server directive is nginx's virtual host directive.
67
69
  server {
70
+
71
+ <% if site['ssl'] %>
72
+
73
+ <% if site['listen'] %>
74
+ listen <%= site['listen'] %>;
75
+ <% else %>
76
+ listen 443;
77
+ <% end %>
78
+ ssl on;
79
+
80
+ # path to your certificate
81
+ ssl_certificate <%= site['ssl']['cert'] %>;
82
+
83
+ # path to your ssl key
84
+ ssl_certificate_key <%= site['ssl']['key'] %>;
85
+
86
+ <% else %>
87
+
68
88
  # port to listen on. Can also be set to an IP:PORT
69
89
  listen 80;
70
90
 
71
91
  # sets the domain[s] that this vhost server requests for
72
92
  server_name <%= site['server_name'] %>;
73
-
93
+
94
+ <% end %>
95
+
74
96
  # doc root
75
97
  root <%= (config['root'][ site['root'] || 'default' ] || site['root']) % name %>;
76
98
 
@@ -90,7 +112,14 @@ http {
90
112
 
91
113
  <% if site['no_www'] %>
92
114
  if ($host ~* "www") {
93
- rewrite ^(.*)$ http://<%= site['server_name'].split.first %>$1 redirect;
115
+ rewrite ^(.*)$ http://<%= site['server_name'].split.first %>$1 permanent;
116
+ break;
117
+ }
118
+ <% end %>
119
+
120
+ <% if site['always_www'] %>
121
+ if ($host != "www.<%= site['server_name'].split.first %>") {
122
+ rewrite ^(.*)$ http://www.<%= site['server_name'].split.first %>$1 permanent;
94
123
  break;
95
124
  }
96
125
  <% end %>
@@ -113,6 +142,10 @@ http {
113
142
  proxy_set_header Host $http_host;
114
143
  proxy_redirect false;
115
144
  proxy_max_temp_file_size 0;
145
+ <% if site['ssl'] %>
146
+ # set X-FORWARDED_PROTO so ssl_requirement plugin works
147
+ proxy_set_header X-FORWARDED_PROTO https;
148
+ <% end %>
116
149
 
117
150
  # check for index.html for directory index
118
151
  # if its there on the filesystem then rewite
@@ -16,12 +16,12 @@ error "Usage: generate_nginx_config [config file] [out file]" if ARGV.empty? &&
16
16
 
17
17
  overwrite = !(%w(-y -o -f --force --overwrite) & ARGV).empty?
18
18
 
19
- config = YAML.load_file(env_in || ARGV.shift || 'config.yml')
19
+ config = YAML.load(ERB.new(env_in || ARGV.shift || 'config.yml').result)
20
20
  template = file:'nginx.erb'
21
21
 
22
22
  if File.exists?(out_file = env_out || ARGV.shift || 'nginx.conf') && !overwrite
23
23
  error "=> #{out_file} already exists, won't overwrite it. Quitting."
24
24
  else
25
- open(out_file, 'w+').write(ERB.new(File.read(template), nil, '>').result(binding))
25
+ open(out_file, 'w+').write(ERB.new(File.read(template), nil, '>').result)
26
26
  error "=> Wrote #{out_file} successfully."
27
27
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: nginx_config_generator
5
5
  version: !ruby/object:Gem::Version
6
- version: "1.0"
7
- date: 2007-04-28 00:00:00 -07:00
6
+ version: "1.1"
7
+ date: 2007-08-17 00:00:00 -07:00
8
8
  summary: ""
9
9
  require_paths:
10
10
  - lib
@@ -30,7 +30,7 @@ authors:
30
30
  - Chris Wanstrath
31
31
  files:
32
32
  - LICENSE
33
- - Manifest.txt
33
+ - Manifest
34
34
  - README
35
35
  - Rakefile
36
36
  - bin/generate_nginx_config