-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx-full.rb
417 lines (373 loc) · 16.1 KB
/
nginx-full.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
class NginxFull < Formula
desc "HTTP(S) server, reverse proxy, IMAP/POP3 proxy server"
homepage "https://nginx.org/"
url "https://nginx.org/download/nginx-1.12.1.tar.gz"
sha256 "8793bf426485a30f91021b6b945a9fd8a84d87d17b566562c3797aba8fac76fb"
head "http://hg.nginx.org/nginx/", :using => :hg
devel do
url "https://nginx.org/download/nginx-1.13.4.tar.gz"
sha256 "de21f3c49ba65c611329d8759a63d72e5fcf719bc6f2a3270e2541348ef1fbba"
end
bottle do
root_url "file:///Volumes/Caches/brew"
sha256 "9014194affa6dc1e5539480c2968ee79af344b9026ebc4f5fc19af5128f88c53" => :high_sierra
end
conflicts_with "nginx", :because => "nginx-full symlink with the name for compatibility with nginx"
def self.core_modules
[
["addition", "http_addition_module", "Build with HTTP Addition support"],
["auth-req", "http_auth_request_module", "Build with HTTP Auth Request support"],
["debug", "debug", "Build with debug log"],
["degredation", "http_degradation_module", "Build with HTTP Degredation support"],
["flv", "http_flv_module", "Build with FLV support"],
["geoip", "http_geoip_module", "Build with HTTP GeoIP support"],
["google-perftools", "google_perftools_module", "Build with Google Performance Tools support"],
["gunzip", "http_gunzip_module", "Build with Gunzip support"],
["gzip-static", "http_gzip_static_module", "Build with Gzip static support"],
["http2", "http_v2_module", "Build with HTTP/2 support"],
["image-filter", "http_image_filter_module", "Build with Image Filter support"],
["mail", "mail", "Build with Mail support"],
["mail-ssl", "mail_ssl_module", "Build with Mail SSL/TLS support"],
["mp4", "http_mp4_module", "Build with MP4 support"],
["no-pool-nginx", nil, "Build without nginx-pool (valgrind debug memory)"],
["passenger", nil, "Build with Phusion Passenger support"],
["pcre-jit", "pcre-jit", "Build with JIT in PCRE"],
["perl", "http_perl_module", "Build with Perl support"],
["random-index", "http_random_index_module", "Build with Random Index support"],
["realip", "http_realip_module", "Build with Real IP support"],
["secure-link", "http_secure_link_module", "Build with Secure Link support"],
["slice", "http_slice_module", "Build with Slice support"],
["status", "http_stub_status_module", "Build with Stub Status support"],
["stream", "stream", "Build with TCP/UDP proxy support"],
["stream-ssl", "stream_ssl_module", "Build with Stream SSL/TLS support"],
["stream-ssl-preread", "stream_ssl_preread_module", "Build with Stream without terminating SSL/TLS support"],
["stream-geoip", "stream_geoip_module", "Build with Stream GeoIP support"],
["stream-realip", "stream_realip_module", "Build with Stream RealIP support"],
["sub", "http_sub_module", "Build with HTTP Sub support"],
["webdav", "http_dav_module", "Build with WebDAV support"],
["xslt", "http_xslt_module", "Build with XSLT support"],
]
end
def self.third_party_modules
{
"accept-language" => "Build with Accept Language support",
"accesskey" => "Build with HTTP Access Key support",
"ajp" => "Build with AJP-protocol support",
"anti-ddos" => "Build with Anti-DDoS support",
"array-var" => "Build with Array Var support",
"auth-digest" => "Build with Auth Digest support",
"auth-ldap" => "Build with Auth LDAP support",
"auth-pam" => "Build with Auth PAM support",
"auto-keepalive" => "Build with Auto Disable KeepAlive support",
"autols" => "Build with Flexible Auto Index support",
"cache-purge" => "Build with Cache Purge support",
"captcha" => "Build with Captcha support",
"counter-zone" => "Build with Realtime Counter Zone support",
"ctpp2" => "Build with CT++ support",
"dav-ext" => "Build with HTTP WebDav Extended support",
"dosdetector" => "Build with detecting DoS attacks support",
"echo" => "Build with Echo support",
"eval" => "Build with Eval support",
"extended-status" => "Build with Extended Status support",
"fancyindex" => "Build with Fancy Index support",
"geoip2" => "Build with GeoIP2 support",
"headers-more" => "Build with Headers More support",
"healthcheck" => "Build with Healthcheck support",
"http-accounting" => "Build with HTTP Accounting support",
"http-flood-detector" => "Build with Var Flood-Threshold support",
"http-remote-passwd" => "Build with Remote Basic Auth Password support",
"log-if" => "Build with Log-if support",
"lua" => "Build with LUA support",
"mod-zip" => "Build with HTTP Zip support",
"mogilefs" => "Build with HTTP MogileFS support",
"mp4-h264" => "Build with HTTP MP4/H264 support",
"mruby" => "Build with MRuby support",
"naxsi" => "Build with Naxsi support",
"nchan" => "Build with Nchan support",
"notice" => "Build with HTTP Notice support",
"php-session" => "Build with Parse PHP Sessions support",
"push-stream" => "Build with HTTP Push Stream support",
"realtime-req" => "Build with Realtime Request support",
"redis" => "Build with Redis support",
"redis2" => "Build with Redis2 support",
"rtmp" => "Build with RTMP support",
"set-misc" => "Build with Set Misc support",
"small-light" => "Build with Small Light support",
"subs-filter" => "Build with Substitutions Filter support",
"tcp-proxy" => "Build with TCP Proxy support",
"txid" => "Build with Sortable Unique ID support",
"unzip" => "Build with UnZip support",
"upload" => "Build with Upload support",
"upload-progress" => "Build with Upload Progress support",
"upstream-order" => "Build with Order Upstream support",
"ustats" => "Build with Upstream Statistics (HAProxy style) support",
"var-req-speed" => "Build with Var Request-Speed support",
"vod" => "Build with VOD on-the-fly MP4 Repackager support",
"websockify" => "Build with Websockify support",
"xsltproc" => "Build with XSLT Transformations support",
}
end
option 'with-homebrew-libressl', 'Include LibreSSL instead of OpenSSL via Homebrew'
depends_on "pcre"
depends_on "passenger" => :optional
depends_on "geoip" => :optional
if build.with?("homebrew-libressl")
depends_on "libressl"
else
depends_on "openssl"
end
depends_on "libzip" if build.with?("unzip")
depends_on "libxml2" if build.with?("xslt")
depends_on "libxslt" if build.with?("xslt")
depends_on "gd" if build.with?("image-filter")
depends_on "valgrind" if build.with?("no-pool-nginx")
depends_on "icu4c" if build.with?("xsltproc-module")
depends_on "libxml2" if build.with?("xsltproc-module")
depends_on "libxslt" if build.with?("xsltproc-module")
depends_on "gperftools" => :optional
depends_on "gd" => :optional
depends_on "imlib2" => :optional
# HTTP2 (backward compatibility for spdy)
if build.with?("spdy")
deprecated_option "with-spdy" => "with-http2"
end
core_modules.each do |arr|
option "with-#{arr[0]}", arr[2]
end
third_party_modules.each do |name, desc|
option "with-#{name}-module", desc
depends_on "#{name}-nginx-module" if build.with?("#{name}-module")
end
def patches
patches = {}
# https://github.com/openresty/no-pool-nginx
if build.with?("no-pool-nginx")
patches[:p2] = "https://raw.githubusercontent.com/openresty/no-pool-nginx/master/nginx-1.11.2-no_pool.patch"
end
if build.with?("extended-status-module")
patches[:p1] = "https://raw.githubusercontent.com/nginx-modules/ngx_http_extended_status_module/master/extended_status-1.10.1.patch"
end
if build.with?("ustats-module")
patches[:p1] = "https://raw.githubusercontent.com/nginx-modules/ngx_ustats_module/master/nginx-1.6.1.patch"
end
if build.with?("tcp-proxy-module")
patches[:p1] = "https://raw.githubusercontent.com/yaoweibin/nginx_tcp_proxy_module/afcab76/tcp_1_8.patch"
end
patches
end
env :userpaths
skip_clean "logs"
def install
if build.with?("http-flood-detector-module") && build.without?("status")
odie "http-flood-detector-nginx-module: Stub Status module is required --with-status"
end
if build.with?("dav-ext-module") && build.without?("webdav")
odie "dav-ext-nginx-module: WebDav Extended module is required --with-webdav"
end
# small-light needs to run setup script
if build.with?("small-light-module")
small_light = Formula["small-light-nginx-module"]
args = build.used_options.select { |option| ["with-gd", "with-imlib2"].include?(option.name) }
origin_dir = Dir.pwd
Dir.chdir("#{small_light.share}/#{small_light.name}")
system "./setup", *args
raise "The small-light setup script couldn't generate config file." unless File.exist?("./config")
Dir.chdir(origin_dir)
end
# mruby module needs to prepare compiling mruby
if build.with?("mruby-module")
mruby = Formula["mruby-nginx-module"]
origin_dir = Dir.pwd
Dir.chdir("#{mruby.share}/#{mruby.name}")
# The compile flow of ngx_mruby is assumed that build_config.rb is managed with git.
system "git", "init"
system "git", "submodule", "init"
system "git", "submodule", "update"
Dir.chdir("#{mruby.share}/#{mruby.name}/mruby")
system "git", "add", "build_config.rb"
system "git", "commit", "-m 'build_config.rb'"
Dir.chdir("#{mruby.share}/#{mruby.name}")
system "./configure", "--with-ngx-src-root=#{buildpath}"
system "make", "build_mruby"
system "make", "generate_gems_config"
rm_rf(".git")
Dir.chdir(origin_dir)
end
# Changes default port to 8080
inreplace "conf/nginx.conf" do |s|
s.gsub! "listen 80;", "listen 8080;"
s.gsub! " #}\n\n}", " #}\n include servers/*;\n}"
end
pcre = Formula["pcre"]
cc_opt = "-I#{HOMEBREW_PREFIX}/include -I#{pcre.include}"
ld_opt = "-L#{HOMEBREW_PREFIX}/lib -L#{pcre.lib}"
if build.with?("libressl")
cc_opt += " -I#{Formula["libressl"].include}"
ld_opt += " -L#{Formula["libressl"].lib}"
else
cc_opt += " -I#{Formula["openssl"].include}"
ld_opt += " -L#{Formula["openssl"].lib}"
end
if build.with?("xsltproc-module")
icu = Formula["icu4c"]
cc_opt += " -I#{icu.opt_include}"
ld_opt += " -L#{icu.opt_lib}"
end
cc_opt += " -I#{Formula["libzip"].opt_lib}/libzip/include" if build.with?("unzip")
args = %W[
--prefix=#{prefix}
--with-http_ssl_module
--with-pcre
--with-ipv6
--sbin-path=#{bin}/nginx
--with-cc-opt=#{cc_opt}
--with-ld-opt=#{ld_opt}
--conf-path=#{etc}/nginx/nginx.conf
--pid-path=#{var}/run/nginx.pid
--lock-path=#{var}/run/nginx.lock
--http-client-body-temp-path=#{var}/run/nginx/client_body_temp
--http-proxy-temp-path=#{var}/run/nginx/proxy_temp
--http-fastcgi-temp-path=#{var}/run/nginx/fastcgi_temp
--http-uwsgi-temp-path=#{var}/run/nginx/uwsgi_temp
--http-scgi-temp-path=#{var}/run/nginx/scgi_temp
--http-log-path=#{var}/log/nginx/access.log
--error-log-path=#{var}/log/nginx/error.log
]
# Core Modules
self.class.core_modules.each do |arr|
args << "--with-#{arr[1]}" if build.with?(arr[0]) && arr[1]
end
# Set misc module and mruby module both depend on nginx-devel-kit being compiled in
if build.with?("set-misc-module") || build.with?("mruby-module") || build.with?("lua-module") || build.with?("array-var-module")
args << "--add-module=#{HOMEBREW_PREFIX}/share/ngx-devel-kit"
end
# Third Party Modules
self.class.third_party_modules.each_key do |name|
if build.with?("#{name}-module")
args << "--add-module=#{HOMEBREW_PREFIX}/share/#{name}-nginx-module"
end
end
# Passenger
if build.with?("passenger")
nginx_ext = `#{Formula["passenger"].opt_bin}/passenger-config --nginx-addon-dir`.chomp
args << "--add-module=#{nginx_ext}"
end
# Install LuaJit
if build.with?("lua-module")
luajit_path = `brew --prefix luajit`.chomp
ENV["LUAJIT_LIB"] = "#{luajit_path}/lib"
ENV["LUAJIT_INC"] = "#{luajit_path}/include/luajit-2.0"
end
if build.head?
system "./auto/configure", *args
else
system "./configure", *args
end
system "make", "install"
if build.head?
man8.install "docs/man/nginx.8"
else
man8.install "man/nginx.8"
end
(etc/"nginx/servers").mkpath
(var/"run/nginx").mkpath
end
def post_install
# nginx's docroot is #{prefix}/html, this isn't useful, so we symlink it
# to #{HOMEBREW_PREFIX}/var/www. The reason we symlink instead of patching
# is so the user can redirect it easily to something else if they choose.
html = prefix/"html"
dst = var/"www"
if dst.exist?
html.rmtree
dst.mkpath
else
dst.dirname.mkpath
html.rename(dst)
end
prefix.install_symlink dst => "html"
# for most of this formula's life the binary has been placed in sbin
# and Homebrew used to suggest the user copy the plist for nginx to their
# ~/Library/LaunchAgents directory. So we need to have a symlink there
# for such cases
if rack.subdirs.any? { |d| d.join("sbin").directory? }
sbin.install_symlink bin/"nginx"
end
end
def passenger_caveats; <<-EOS.undent
To activate Phusion Passenger, add this to #{etc}/nginx/nginx.conf, inside the 'http' context:
passenger_root #{Formula["passenger"].opt_libexec}/src/ruby_supportlib/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;
EOS
end
def caveats
s = <<-EOS.undent
Docroot is: #{var}/www
The default port has been set in #{etc}/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in #{etc}/nginx/servers/.
- Tips -
Run port 80:
$ sudo chown root:wheel #{bin}/nginx
$ sudo chmod u+s #{bin}/nginx
Reload config:
$ nginx -s reload
Reopen Logfile:
$ nginx -s reopen
Stop process:
$ nginx -s stop
Waiting on exit process
$ nginx -s quit
EOS
s << "\n" << passenger_caveats if build.with?("passenger")
s
end
plist_options :manual => "nginx"
def plist; <<-EOS.undent
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/nginx</string>
<string>-g</string>
<string>daemon off;</string>
</array>
<key>WorkingDirectory</key>
<string>#{HOMEBREW_PREFIX}</string>
</dict>
</plist>
EOS
end
test do
(testpath/"nginx.conf").write <<-EOS
worker_processes 4;
error_log #{testpath}/error.log;
pid #{testpath}/nginx.pid;
events {
worker_connections 1024;
}
http {
client_body_temp_path #{testpath}/client_body_temp;
fastcgi_temp_path #{testpath}/fastcgi_temp;
proxy_temp_path #{testpath}/proxy_temp;
scgi_temp_path #{testpath}/scgi_temp;
uwsgi_temp_path #{testpath}/uwsgi_temp;
server {
listen 8080;
root #{testpath};
access_log #{testpath}/access.log;
error_log #{testpath}/error.log;
}
}
EOS
system "#{bin}/nginx", "-t", "-c", testpath/"nginx.conf"
end
end