nginx_config_parser 1.0.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/History.txt +3 -0
- data/Manifest.txt +20 -0
- data/README.txt +73 -0
- data/Rakefile +21 -0
- data/lib/nginx_config_parser.rb +62 -0
- data/lib/nginx_config_parser/configuration.rb +68 -0
- data/lib/nginx_config_parser/scanner.rb +510 -0
- data/src/scanner.rl +94 -0
- data/tasks/annotations.rake +30 -0
- data/tasks/doc.rake +49 -0
- data/tasks/gem.rake +89 -0
- data/tasks/manifest.rake +41 -0
- data/tasks/ragel.rake +10 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +151 -0
- data/tasks/spec.rake +40 -0
- data/tasks/test.rake +40 -0
- data/test/fixtures/ezra/conf/nginx.conf +209 -0
- data/test/fixtures/simple/conf/nginx.conf +21 -0
- data/test/parser_test.rb +69 -0
- metadata +74 -0
data/tasks/spec.rake
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_SPEC_RAKE_SPECTASK
|
4
|
+
|
5
|
+
namespace :spec do
|
6
|
+
|
7
|
+
desc 'Run all specs with basic output'
|
8
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
9
|
+
t.spec_opts = PROJ.spec_opts
|
10
|
+
t.spec_files = PROJ.specs
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Run all specs with text output'
|
14
|
+
Spec::Rake::SpecTask.new(:specdoc) do |t|
|
15
|
+
t.spec_opts = PROJ.spec_opts + ['--format', 'specdoc']
|
16
|
+
t.spec_files = PROJ.specs
|
17
|
+
end
|
18
|
+
|
19
|
+
if HAVE_RCOV
|
20
|
+
desc 'Run all specs with RCov'
|
21
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
22
|
+
t.spec_opts = PROJ.spec_opts
|
23
|
+
t.spec_files = PROJ.specs
|
24
|
+
t.rcov = true
|
25
|
+
t.rcov_opts = PROJ.rcov_opts + ['--exclude', 'spec']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end # namespace :spec
|
30
|
+
|
31
|
+
desc 'Alias to spec:run'
|
32
|
+
task :spec => 'spec:run'
|
33
|
+
|
34
|
+
task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
|
35
|
+
|
36
|
+
remove_desc_for_task %w(spec:clobber_rcov)
|
37
|
+
|
38
|
+
end # if HAVE_SPEC_RAKE_SPECTASK
|
39
|
+
|
40
|
+
# EOF
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
|
7
|
+
Rake::TestTask.new(:run) do |t|
|
8
|
+
t.libs = PROJ.libs
|
9
|
+
t.test_files = if test ?f, PROJ.test_file then [PROJ.test_file]
|
10
|
+
else PROJ.tests end
|
11
|
+
t.ruby_opts += PROJ.ruby_opts
|
12
|
+
t.ruby_opts += PROJ.test_opts
|
13
|
+
end
|
14
|
+
|
15
|
+
if HAVE_RCOV
|
16
|
+
desc 'Run rcov on the unit tests'
|
17
|
+
task :rcov => :clobber_rcov do
|
18
|
+
opts = PROJ.rcov_opts.join(' ')
|
19
|
+
files = if test ?f, PROJ.test_file then [PROJ.test_file]
|
20
|
+
else PROJ.tests end
|
21
|
+
files = files.join(' ')
|
22
|
+
sh "#{RCOV} #{files} #{opts}"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Remove rcov products'
|
26
|
+
task :clobber_rcov do
|
27
|
+
rm_r 'coverage' rescue nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end # namespace :test
|
32
|
+
|
33
|
+
desc 'Alias to test:run'
|
34
|
+
task :test => 'test:run'
|
35
|
+
|
36
|
+
task :clobber => 'test:clobber_rcov' if HAVE_RCOV
|
37
|
+
|
38
|
+
remove_desc_for_task %w(test:clobber_rcov)
|
39
|
+
|
40
|
+
# EOF
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# user and group to run as
|
2
|
+
user ez ez;
|
3
|
+
|
4
|
+
# number of nginx workers
|
5
|
+
worker_processes 6;
|
6
|
+
|
7
|
+
# pid of nginx master process
|
8
|
+
pid /var/run/nginx.pid;
|
9
|
+
|
10
|
+
# Number of worker connections. 1024 is a good default
|
11
|
+
events {
|
12
|
+
worker_connections 1024;
|
13
|
+
}
|
14
|
+
|
15
|
+
# start the http module where we config http access.
|
16
|
+
http {
|
17
|
+
# pull in mime-types. You can break out your config
|
18
|
+
# into as many include's as you want to make it cleaner
|
19
|
+
include /etc/nginx/mime.types;
|
20
|
+
|
21
|
+
# set a default type for the rare situation that
|
22
|
+
# nothing matches from the mimie-type include
|
23
|
+
default_type application/octet-stream;
|
24
|
+
|
25
|
+
# configure log format
|
26
|
+
log_format main '$remote_addr - $remote_user [$time_local] '
|
27
|
+
'"$request" $status $body_bytes_sent "$http_referer" '
|
28
|
+
'"$http_user_agent" "$http_x_forwarded_for"';
|
29
|
+
|
30
|
+
# main access log
|
31
|
+
access_log /var/log/nginx_access.log main;
|
32
|
+
|
33
|
+
# main error log
|
34
|
+
error_log /var/log/nginx_error.log debug;
|
35
|
+
|
36
|
+
# no sendfile on OSX
|
37
|
+
sendfile on;
|
38
|
+
|
39
|
+
# These are good default values.
|
40
|
+
tcp_nopush on;
|
41
|
+
tcp_nodelay off;
|
42
|
+
# output compression saves bandwidth
|
43
|
+
gzip on;
|
44
|
+
gzip_http_version 1.0;
|
45
|
+
gzip_comp_level 2;
|
46
|
+
gzip_proxied any;
|
47
|
+
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml
|
48
|
+
application/xml+rss text/javascript;
|
49
|
+
|
50
|
+
|
51
|
+
# this is where you define your mongrel clusters.
|
52
|
+
# you need one of these blocks for each cluster
|
53
|
+
# and each one needs its own name to refer to it later.
|
54
|
+
upstream mongrel {
|
55
|
+
server 127.0.0.1:5000;
|
56
|
+
server 127.0.0.1:5001;
|
57
|
+
server 127.0.0.1:5002;
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
# the server directive is nginx's virtual host directive.
|
62
|
+
server {
|
63
|
+
# port to listen on. Can also be set to an IP:PORT
|
64
|
+
listen 80;
|
65
|
+
|
66
|
+
# Set the max size for file uploads to 50Mb
|
67
|
+
client_max_body_size 50M;
|
68
|
+
|
69
|
+
# sets the domain[s] that this vhost server requests for
|
70
|
+
# server_name www.[engineyard].com [engineyard].com;
|
71
|
+
|
72
|
+
# doc root
|
73
|
+
root /data/ez/current/public;
|
74
|
+
|
75
|
+
# vhost specific access log
|
76
|
+
access_log /var/log/nginx.vhost.access.log main;
|
77
|
+
|
78
|
+
# this rewrites all the requests to the maintenance.html
|
79
|
+
# page if it exists in the doc root. This is for capistrano's
|
80
|
+
# disable web task
|
81
|
+
if (-f $document_root/system/maintenance.html) {
|
82
|
+
rewrite ^(.*)$ /system/maintenance.html last;
|
83
|
+
break;
|
84
|
+
}
|
85
|
+
|
86
|
+
location / {
|
87
|
+
# needed to forward user's IP address to rails
|
88
|
+
proxy_set_header X-Real-IP $remote_addr;
|
89
|
+
|
90
|
+
# needed for HTTPS
|
91
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
92
|
+
proxy_set_header Host $http_host;
|
93
|
+
proxy_redirect false;
|
94
|
+
proxy_max_temp_file_size 0;
|
95
|
+
|
96
|
+
# If the file exists as a static file serve it directly without
|
97
|
+
# running all the other rewite tests on it
|
98
|
+
if (-f $request_filename) {
|
99
|
+
break;
|
100
|
+
}
|
101
|
+
|
102
|
+
# check for index.html for directory index
|
103
|
+
# if its there on the filesystem then rewite
|
104
|
+
# the url to add /index.html to the end of it
|
105
|
+
# and then break to send it to the next config rules.
|
106
|
+
if (-f $request_filename/index.html) {
|
107
|
+
rewrite (.*) $1/index.html break;
|
108
|
+
}
|
109
|
+
|
110
|
+
# this is the meat of the rails page caching config
|
111
|
+
# it adds .html to the end of the url and then checks
|
112
|
+
# the filesystem for that file. If it exists, then we
|
113
|
+
# rewite the url to have explicit .html on the end
|
114
|
+
# and then send it on its way to the next config rule.
|
115
|
+
# if there is no file on the fs then it sets all the
|
116
|
+
# necessary headers and proxies to our upstream mongrels
|
117
|
+
if (-f $request_filename.html) {
|
118
|
+
rewrite (.*) $1.html break;
|
119
|
+
}
|
120
|
+
|
121
|
+
if (!-f $request_filename) {
|
122
|
+
proxy_pass http://mongrel;
|
123
|
+
break;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
error_page 500 502 503 504 /500.html;
|
128
|
+
location = /500.html {
|
129
|
+
root /data/ez/current/public;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
# This server is setup for ssl. Uncomment if
|
134
|
+
# you are using ssl as well as port 80.
|
135
|
+
server {
|
136
|
+
# port to listen on. Can also be set to an IP:PORT
|
137
|
+
listen 443;
|
138
|
+
|
139
|
+
# Set the max size for file uploads to 50Mb
|
140
|
+
client_max_body_size 50M;
|
141
|
+
|
142
|
+
# sets the domain[s] that this vhost server requests for
|
143
|
+
# server_name www.[engineyard].com [engineyard].com;
|
144
|
+
|
145
|
+
# doc root
|
146
|
+
root /data/ez/current/public;
|
147
|
+
|
148
|
+
# vhost specific access log
|
149
|
+
access_log /var/log/nginx.vhost.access.log main;
|
150
|
+
|
151
|
+
# this rewrites all the requests to the maintenance.html
|
152
|
+
# page if it exists in the doc root. This is for capistrano's
|
153
|
+
# disable web task
|
154
|
+
if (-f $document_root/system/maintenance.html) {
|
155
|
+
rewrite ^(.*)$ /system/maintenance.html last;
|
156
|
+
break;
|
157
|
+
}
|
158
|
+
|
159
|
+
location / {
|
160
|
+
# needed to forward user's IP address to rails
|
161
|
+
proxy_set_header X-Real-IP $remote_addr;
|
162
|
+
|
163
|
+
# needed for HTTPS
|
164
|
+
proxy_set_header X_FORWARDED_PROTO https;
|
165
|
+
|
166
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
167
|
+
proxy_set_header Host $http_host;
|
168
|
+
proxy_redirect false;
|
169
|
+
proxy_max_temp_file_size 0;
|
170
|
+
|
171
|
+
# If the file exists as a static file serve it directly without
|
172
|
+
# running all the other rewite tests on it
|
173
|
+
if (-f $request_filename) {
|
174
|
+
break;
|
175
|
+
}
|
176
|
+
|
177
|
+
# check for index.html for directory index
|
178
|
+
# if its there on the filesystem then rewite
|
179
|
+
# the url to add /index.html to the end of it
|
180
|
+
# and then break to send it to the next config rules.
|
181
|
+
if (-f $request_filename/index.html) {
|
182
|
+
rewrite (.*) $1/index.html break;
|
183
|
+
}
|
184
|
+
|
185
|
+
# this is the meat of the rails page caching config
|
186
|
+
# it adds .html to the end of the url and then checks
|
187
|
+
# the filesystem for that file. If it exists, then we
|
188
|
+
# rewite the url to have explicit .html on the end
|
189
|
+
# and then send it on its way to the next config rule.
|
190
|
+
# if there is no file on the fs then it sets all the
|
191
|
+
# necessary headers and proxies to our upstream mongrels
|
192
|
+
if (-f $request_filename.html) {
|
193
|
+
rewrite (.*) $1.html break;
|
194
|
+
}
|
195
|
+
|
196
|
+
if (!-f $request_filename) {
|
197
|
+
proxy_pass http://mongrel;
|
198
|
+
break;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
error_page 500 502 503 504 /500.html;
|
203
|
+
location = /500.html {
|
204
|
+
root /data/ez/current/public;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
user nobody www;
|
2
|
+
worker_processes 1;
|
3
|
+
|
4
|
+
events {
|
5
|
+
worker_connections 1024;
|
6
|
+
}
|
7
|
+
|
8
|
+
http {
|
9
|
+
default_type application/octet-stream;
|
10
|
+
sendfile on;
|
11
|
+
keepalive_timeout 65;
|
12
|
+
server {
|
13
|
+
listen 80;
|
14
|
+
server_name simple.com *.simple.com;
|
15
|
+
access_log logs/simple.access.log;
|
16
|
+
location / {
|
17
|
+
root html;
|
18
|
+
index index.html index.htm;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
data/test/parser_test.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + "/../lib"
|
2
|
+
|
3
|
+
require 'nginx_config_parser'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
begin
|
7
|
+
require 'test/spec'
|
8
|
+
rescue LoadError
|
9
|
+
STDERR.puts "Testing requires test-spec; gem install test-spec"
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
context "Nginx Configuration Parser" do
|
14
|
+
|
15
|
+
specify "can parse simple configuration" do
|
16
|
+
parsing :simple do |config|
|
17
|
+
assert_equal 2, config.sections.size
|
18
|
+
assert_equal %w(events http), config.sections.map { |s| s.name }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "can parser more complex configuration" do
|
23
|
+
assert_nothing_raised do
|
24
|
+
parsing :ezra do |config|
|
25
|
+
# TODO: More tests
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
specify "skips if statements" do
|
31
|
+
result = parse(<<-EOCONFIG)
|
32
|
+
start 1;
|
33
|
+
if ( an if statement here ) {
|
34
|
+
this should all be ignored
|
35
|
+
}
|
36
|
+
if( this has ( some parenths ) ) {
|
37
|
+
but_is_still_ignored ok;
|
38
|
+
}
|
39
|
+
should_reach_here 1;
|
40
|
+
and_this = / {
|
41
|
+
should_exist 1;
|
42
|
+
}
|
43
|
+
EOCONFIG
|
44
|
+
assert_equal 2, result.settings.size
|
45
|
+
assert_equal 1, result.sections.size
|
46
|
+
assert_equal({'should_exist' => 1}, result.sections.first.settings)
|
47
|
+
assert_equal(%w(= /), result.sections.first.value)
|
48
|
+
assert_nothing_raised do
|
49
|
+
result.each do |section|
|
50
|
+
assert section.is_a?(NginxConfigParser::Section)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
#######
|
57
|
+
private
|
58
|
+
#######
|
59
|
+
|
60
|
+
def parse(text)
|
61
|
+
NginxConfigParser.parse(text)
|
62
|
+
end
|
63
|
+
|
64
|
+
def parsing(scenario)
|
65
|
+
fixture = File.dirname(__FILE__) << "/fixtures/#{scenario}/conf/nginx.conf"
|
66
|
+
yield parse(File.read(fixture))
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nginx_config_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruce Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-21 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: "== FEATURES/PROBLEMS: * Currently ignores `if' statements (focused on only parsing static config)"
|
17
|
+
email: bruce@codefluency.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- History.txt
|
24
|
+
- README.txt
|
25
|
+
files:
|
26
|
+
- History.txt
|
27
|
+
- Manifest.txt
|
28
|
+
- README.txt
|
29
|
+
- Rakefile
|
30
|
+
- lib/nginx_config_parser.rb
|
31
|
+
- lib/nginx_config_parser/configuration.rb
|
32
|
+
- lib/nginx_config_parser/scanner.rb
|
33
|
+
- src/scanner.rl
|
34
|
+
- tasks/annotations.rake
|
35
|
+
- tasks/doc.rake
|
36
|
+
- tasks/gem.rake
|
37
|
+
- tasks/manifest.rake
|
38
|
+
- tasks/ragel.rake
|
39
|
+
- tasks/rubyforge.rake
|
40
|
+
- tasks/setup.rb
|
41
|
+
- tasks/spec.rake
|
42
|
+
- tasks/test.rake
|
43
|
+
- test/fixtures/ezra/conf/nginx.conf
|
44
|
+
- test/fixtures/simple/conf/nginx.conf
|
45
|
+
- test/parser_test.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://codefluency.rubyforge.org/nginx_config_parser
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --main
|
51
|
+
- README.txt
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: codefluency
|
69
|
+
rubygems_version: 1.0.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: A simple nginx.conf parser and emitter
|
73
|
+
test_files:
|
74
|
+
- test/parser_test.rb
|