nginx-osx 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ .idea/
data/HELP ADDED
@@ -0,0 +1,25 @@
1
+ USAGE:
2
+ nginx-osx [cmd]
3
+
4
+ install [--passenger]
5
+ - install nginx via macports
6
+ install_passenger
7
+ - install passenger for nginx
8
+ setup
9
+ - setup the basic nginx.conf file and the vhost directories
10
+ add [--passenger, --host Hostname]
11
+ - add the current directory as a vhost
12
+ run
13
+ - run the current directory as the default vhost (symlinks in the vhost)
14
+ start
15
+ - start nginx
16
+ stop
17
+ - stop nginx
18
+ restart
19
+ - restart and check the config for errors
20
+ reload
21
+ - reload the config and check for errors
22
+ current_config
23
+ - show vhost config of current directory
24
+ tail_error_log
25
+ - tail the main nginx error log
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Gabe Varela
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = nginx-osx
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Gabe Varela. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "nginx-osx"
8
+ gem.summary = 'gem for using nginx in development'
9
+ gem.email = "gvarela@gmail.com"
10
+ gem.homepage = "http://github.com/gvarela/nginx-osx"
11
+ gem.authors = ["Gabe Varela"]
12
+ gem.add_dependency('ghost', '~> 0.2.3')
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ begin
41
+ require 'cucumber/rake/task'
42
+ Cucumber::Rake::Task.new(:features)
43
+ rescue LoadError
44
+ task :features do
45
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
46
+ end
47
+ end
48
+
49
+ task :default => :test
50
+
51
+ require 'rake/rdoctask'
52
+ Rake::RDocTask.new do |rdoc|
53
+ if File.exist?('VERSION.yml')
54
+ config = YAML.load(File.read('VERSION.yml'))
55
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
56
+ else
57
+ version = ""
58
+ end
59
+
60
+ rdoc.rdoc_dir = 'rdoc'
61
+ rdoc.title = "nginx-osx #{version}"
62
+ rdoc.rdoc_files.include('README*')
63
+ rdoc.rdoc_files.include('lib/**/*.rb')
64
+ end
65
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/bin/nginx-osx ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require "#{File.dirname(__FILE__)}/../lib/nginx-osx.rb"
3
+
4
+ trap "INT" do
5
+ exit!
6
+ end
7
+
8
+ NginxOsx.new(*ARGV)
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
File without changes
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'nginx-osx'
3
+
4
+ require 'test/unit/assertions'
5
+
6
+ World(Test::Unit::Assertions)
data/lib/nginx-osx.rb ADDED
@@ -0,0 +1,127 @@
1
+ require 'open-uri'
2
+ require 'erb'
3
+ require 'optparse'
4
+
5
+ class NginxOsx
6
+ TEMPLATES_DIR = File.join(File.dirname(__FILE__), '../', 'templates')
7
+ attr_accessor :port, :passenger, :host
8
+
9
+ def initialize(*args)
10
+ cmd = args.shift
11
+ parse(args)
12
+ if cmd && respond_to?(cmd.to_sym)
13
+ self.send(cmd.to_sym)
14
+ else
15
+ help
16
+ end
17
+ end
18
+
19
+ def help
20
+ puts usage
21
+ end
22
+
23
+ def install
24
+ cmd = <<-CMD;
25
+ git clone git://github.com/crigor/admoolabs-ports.git ports
26
+ cd ports/nginx-0.7.64-passenger-2.2.8
27
+ sudo port -v install +passenger
28
+ cd ../../
29
+ rm -rf ports
30
+ CMD
31
+ exec cmd
32
+ end
33
+
34
+ def setup
35
+ config = ''
36
+ File.open(File.join(TEMPLATES_DIR, 'nginx.conf.erb')) do |f|
37
+ config = f.read
38
+ end
39
+ File.open('/opt/local/etc/nginx/nginx.conf', 'w+') do |f|
40
+ f.puts ERB.new(config).result(binding)
41
+ end
42
+ `mkdir -p /opt/local/etc/nginx/vhosts`
43
+ `mkdir -p /opt/local/etc/nginx/configs`
44
+ `mkdir -p /var/log/nginx`
45
+ `sudo cp /opt/local/etc/nginx/mime.types.example /opt/local/etc/nginx/mime.types`
46
+ `sudo /opt/local/sbin/nginx -t`
47
+ end
48
+
49
+ def add
50
+ config = ''
51
+ File.open(File.join(TEMPLATES_DIR, 'nginx.vhost.conf.erb')) do |f|
52
+ config = f.read
53
+ end
54
+ File.open(current_config_path, 'w+') do |f|
55
+ f.puts ERB.new(config).result(binding)
56
+ end
57
+ if host
58
+ `ghost add #{host}`
59
+ end
60
+ end
61
+
62
+ def run
63
+ `sudo ln -fs #{current_config_path} /opt/local/etc/nginx/vhosts/current.conf`
64
+ `sudo /opt/local/sbin/nginx -t`
65
+ puts `sudo /opt/local/sbin/nginx`
66
+ end
67
+
68
+ def start
69
+ puts `sudo /opt/local/sbin/nginx`
70
+ end
71
+
72
+ def stop
73
+ puts `sudo killall nginx`
74
+ end
75
+
76
+ def restart
77
+ `sudo killall nginx`
78
+ `sudo /opt/local/sbin/nginx -t`
79
+ puts `sudo /opt/local/sbin/nginx`
80
+ end
81
+
82
+ def reload
83
+ `sudo /opt/local/sbin/nginx -t`
84
+ pid = `ps ax | grep 'nginx: master' | grep -v grep | awk '{print $1}'`
85
+ puts `sudo kill -HUP #{pid}` if pid
86
+ end
87
+
88
+ def current_config
89
+ puts current_config_path
90
+ exec "cat #{current_config_path}"
91
+ end
92
+
93
+ def tail_error_log
94
+ exec "tail -f /var/log/nginx/default.error.log"
95
+ end
96
+
97
+ private
98
+ def current_config_name
99
+ Dir.pwd.downcase.gsub(/^\//, '').gsub(/\.|\/|\s/, '-')
100
+ end
101
+
102
+ def current_config_path
103
+ passenger && host ? "/opt/local/etc/nginx/vhosts/#{current_config_name}.conf" : "/opt/local/etc/nginx/configs/#{current_config_name}.conf"
104
+ end
105
+
106
+ def usage
107
+ File.read(File.join(File.dirname(__FILE__), '../', 'HELP'))
108
+ end
109
+
110
+ def parse(args)
111
+ options = {}
112
+ OptionParser.new do |opts|
113
+ opts.banner = usage
114
+
115
+ opts.on("-p", "--port PORT", Integer, "Use a specific port (default is 3000)") do |p|
116
+ self.port = p || 3000
117
+ end
118
+ opts.on("-h", "--host HOST", "Use a hostname instead of default host") do |h|
119
+ self.host = h
120
+ end
121
+ opts.on("--passenger", "Use passenger") do |p|
122
+ self.passenger = true
123
+ end
124
+ end.parse!
125
+
126
+ end
127
+ end
data/nginx-osx.gemspec ADDED
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{nginx-osx}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Gabe Varela"]
12
+ s.date = %q{2010-01-07}
13
+ s.default_executable = %q{nginx-osx}
14
+ s.email = %q{gvarela@gmail.com}
15
+ s.executables = ["nginx-osx"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "HELP",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/nginx-osx",
29
+ "features/nginx-osx.feature",
30
+ "features/step_definitions/nginx-osx_steps.rb",
31
+ "features/support/env.rb",
32
+ "lib/nginx-osx.rb",
33
+ "nginx-osx.gemspec",
34
+ "templates/nginx.conf.erb",
35
+ "templates/nginx.vhost.conf.erb",
36
+ "test/nginx-osx_test.rb",
37
+ "test/test_helper.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/gvarela/nginx-osx}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{gem for using nginx in development}
44
+ s.test_files = [
45
+ "test/nginx-osx_test.rb",
46
+ "test/test_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<ghost>, ["~> 0.2.3"])
55
+ else
56
+ s.add_dependency(%q<ghost>, ["~> 0.2.3"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<ghost>, ["~> 0.2.3"])
60
+ end
61
+ end
62
+
@@ -0,0 +1,55 @@
1
+ # taken mostly from "The Rails Way" page 663
2
+
3
+ # user and group to run as
4
+ # user nginx;
5
+ # number of nginx workers
6
+ # worker_processes 2;
7
+ # pid of nginx master process
8
+ pid /var/run/nginx.pid;
9
+
10
+ error_log /var/log/nginx/default.error.log debug;
11
+ #error_log /var/log/nginx/error.log notice;
12
+ #error_log /var/log/nginx/error.log info;
13
+
14
+ # number of worker connections. 1024 is a good default
15
+ events {
16
+ worker_connections 256;
17
+ }
18
+
19
+
20
+ http {
21
+ # pull in mime-types. You can break out your config
22
+ # into as many include's as you want.
23
+ include /opt/local/etc/nginx/mime.types;
24
+ # set a default type for the rare situation that nothing matches.
25
+ default_type application/octet-stream;
26
+ # configure log format
27
+ log_format main '$remote_addr - $remote_user [$time_local] $request '
28
+ '"$status" $body_bytes_sent "$http_referer" '
29
+ '"$http_user_agent" "$http_x_forwarded_for"';
30
+
31
+ # no sendfile on OS X
32
+ tcp_nopush on;
33
+ tcp_nodelay on;
34
+
35
+ #keepalive_timeout 0;
36
+ keepalive_timeout 65;
37
+
38
+ gzip on;
39
+ gzip_http_version 1.0;
40
+ gzip_comp_level 2;
41
+ gzip_proxied any;
42
+
43
+ gzip_types text/plain text/html text/css application/x-javascript text/javascript;
44
+
45
+ # upload_progress proxied 1m;
46
+
47
+ access_log /var/log/nginx/nginx.default.access.log main;
48
+ error_log /var/log/nginx/nginx.default.error.log info;
49
+
50
+ passenger_root /opt/local/lib/passenger;
51
+ # <%= `passenger-config --root` %>;
52
+ passenger_ruby <%= `which ruby`%>;
53
+
54
+ include vhosts/*.conf;
55
+ }
@@ -0,0 +1,97 @@
1
+ <% unless passenger %>
2
+ # location of mongrel servers to proxy too
3
+ upstream mongrel {
4
+ server 127.0.0.1:<%= port || '3000'%>;
5
+ }
6
+ <% end %>
7
+
8
+ server {
9
+ # port to listen on. Can also be set to an IP:PORT
10
+ listen <%= host ? "80" : '80 default' %>;
11
+ # set max size for file uploads to 50mb
12
+ client_max_body_size 150M;
13
+ # sets the domain[s] that this vhost server requests for
14
+ # if two apps are on this box remove the ip and setup your hosts file
15
+ server_name <%= host || '_' %>;
16
+ # doc root
17
+ root <%= Dir.pwd %>/public;
18
+
19
+ <% if passenger %>
20
+ passenger_enabled on;
21
+ rails_env development;
22
+ <% end %>
23
+
24
+ # vhost specific logs
25
+ access_log <%= Dir.pwd %>/log/nginx.access.log main;
26
+ error_log <%= Dir.pwd %>/log/nginx.error.log notice;
27
+
28
+ <% unless passenger %>
29
+
30
+ # hack to prevent image 404s from getting to rails
31
+ location /images {
32
+ if (-f $request_filename) {
33
+ break;
34
+ }
35
+
36
+ # instead of a 404 could rewrite to an fpo image
37
+ # rewrite ^.*(_thumb|_small)\.(jpg|jpeg|JPG|JPEG) /images/fpo$1.jpg last;
38
+ return 404;
39
+ }
40
+
41
+ location / {
42
+
43
+ index index.html index.htm;
44
+
45
+
46
+ # forward the user's IP address to Rails
47
+ proxy_set_header X-Real-IP $remote_addr;
48
+ # needed for HTTPS must add an additional server block to configure it.
49
+ # see "The Rails Way" page 665 for more info
50
+ proxy_set_header X-FORWARD_PROTO https;
51
+ # Forward information about the client and host
52
+ # Otherwise our Rails app wouldn't have access to it
53
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
54
+ proxy_set_header Host $http_host;
55
+ proxy_redirect false;
56
+ proxy_max_temp_file_size 0;
57
+
58
+
59
+ # if file exists break execution and serve up file for example files in images, javascripts, and stylesheets
60
+ if (-f $request_filename) {
61
+ break;
62
+ }
63
+
64
+ # Rails page caching, if file path plus index.html exists break execution and serve up file
65
+ if (-f $request_filename/index.html) {
66
+ rewrite (.*) $1/index.html break;
67
+ }
68
+
69
+ # Rails page caching, if file.html exists break execution and serve up file
70
+ if (-f $request_filename.html) {
71
+ rewrite (.*) $1.html break;
72
+ }
73
+
74
+ # if file does not exist forward to mongrel
75
+ if (!-f $request_filename) {
76
+ proxy_pass http://mongrel;
77
+ break;
78
+ }
79
+
80
+ # uncomment below and comment out above to configure the upload progress module
81
+ # proxy_pass http://mongrel;
82
+ # track_uploads proxied 30s;
83
+
84
+ }
85
+ # must be an error so point to error page.
86
+ error_page 500 502 503 504 /500.html;
87
+ location = /500.html {
88
+ root <%= Dir.pwd %>/public;
89
+ }
90
+ # uncomment below to configure upload progress module
91
+ # location ^~ /progress {
92
+ # report_uploads proxied;
93
+ # }
94
+
95
+ }
96
+
97
+ <% end %>
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class NginxOsxTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'nginx-osx'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nginx-osx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabe Varela
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-07 00:00:00 -07:00
13
+ default_executable: nginx-osx
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ghost
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.3
24
+ version:
25
+ description:
26
+ email: gvarela@gmail.com
27
+ executables:
28
+ - nginx-osx
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - HELP
38
+ - LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - bin/nginx-osx
43
+ - features/nginx-osx.feature
44
+ - features/step_definitions/nginx-osx_steps.rb
45
+ - features/support/env.rb
46
+ - lib/nginx-osx.rb
47
+ - nginx-osx.gemspec
48
+ - templates/nginx.conf.erb
49
+ - templates/nginx.vhost.conf.erb
50
+ - test/nginx-osx_test.rb
51
+ - test/test_helper.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/gvarela/nginx-osx
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.5
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: gem for using nginx in development
80
+ test_files:
81
+ - test/nginx-osx_test.rb
82
+ - test/test_helper.rb