gvarela-nginx-osx 0.1.1

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,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
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,64 @@
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 is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ begin
40
+ require 'cucumber/rake/task'
41
+ Cucumber::Rake::Task.new(:features)
42
+ rescue LoadError
43
+ task :features do
44
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
45
+ end
46
+ end
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ if File.exist?('VERSION.yml')
53
+ config = YAML.load(File.read('VERSION.yml'))
54
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
55
+ else
56
+ version = ""
57
+ end
58
+
59
+ rdoc.rdoc_dir = 'rdoc'
60
+ rdoc.title = "nginx-osx #{version}"
61
+ rdoc.rdoc_files.include('README*')
62
+ rdoc.rdoc_files.include('lib/**/*.rb')
63
+ end
64
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
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,112 @@
1
+ require 'open-uri'
2
+ require 'erb'
3
+
4
+ class NginxOsx
5
+ TEMPLATES_DIR = File.join(File.dirname(__FILE__), '../', 'templates')
6
+
7
+ def initialize(args)
8
+ cmd = args.is_a?(Array) ? args[0] : args
9
+ if cmd && respond_to?(cmd.to_sym)
10
+ self.send(cmd.to_sym)
11
+ else
12
+ help
13
+ end
14
+ end
15
+
16
+ def help
17
+ usage = <<-'USAGE'
18
+ USAGE:
19
+ nginx-osx [cmd]
20
+
21
+ install
22
+ - install nginx via macports
23
+ setup
24
+ - setup the basic nginx.conf file and the vhost directories
25
+ add
26
+ - add the current directory as a vhost
27
+ run
28
+ - run the current directory as the default vhost (symlinks in the vhost)
29
+ start
30
+ - start nginx
31
+ stop
32
+ - stop nginx
33
+ restart
34
+ - restart and check the config for errors
35
+ reload
36
+ - reload the config and check for errors
37
+ USAGE
38
+ puts usage
39
+ end
40
+
41
+ def install
42
+ `sudo port install nginx`
43
+ end
44
+
45
+ def setup
46
+ config = ''
47
+ File.open(File.join(TEMPLATES_DIR, 'nginx.conf.erb')) do |f|
48
+ config = f.read
49
+ end
50
+ File.open('/opt/local/etc/nginx/nginx.conf', 'w+') do |f|
51
+ f.puts ERB.new(config).result(binding)
52
+ end
53
+ `mkdir -p /opt/local/etc/nginx/vhosts`
54
+ `mkdir -p /opt/local/etc/nginx/configs`
55
+ `sudo /opt/local/sbin/nginx -t`
56
+ end
57
+
58
+ def add
59
+ port = ENV['PORT'] || '3000'
60
+ config = ''
61
+ File.open(File.join(TEMPLATES_DIR, 'nginx.vhost.conf.erb')) do |f|
62
+ config = f.read
63
+ end
64
+ File.open(current_config_path, 'w+') do |f|
65
+ f.puts ERB.new(config).result(binding)
66
+ end
67
+ end
68
+
69
+ def run
70
+ `sudo ln -fs #{current_config_path} /opt/local/etc/nginx/vhosts/current.conf`
71
+ `sudo /opt/local/sbin/nginx -t`
72
+ `sudo /opt/local/sbin/nginx`
73
+ end
74
+
75
+ def start
76
+ `sudo /opt/local/sbin/nginx`
77
+ end
78
+
79
+ def stop
80
+ `sudo killall nginx`
81
+ end
82
+
83
+ def restart
84
+ `sudo killall nginx`
85
+ `sudo /opt/local/sbin/nginx -t`
86
+ `sudo /opt/local/sbin/nginx`
87
+ end
88
+
89
+ def reload
90
+ `sudo /opt/local/sbin/nginx -t`
91
+ pid = `ps ax | grep 'nginx: master' | grep -v grep | awk '{print $1}'`
92
+ `sudo kill -HUP #{pid}` if pid
93
+ end
94
+
95
+ def current_config
96
+ puts current_config_path
97
+ exec "cat #{current_config_path}"
98
+ end
99
+
100
+ def tail_error_log
101
+ exec "tail -f /var/log/nginx/default.error.log"
102
+ end
103
+
104
+ private
105
+ def current_config_name
106
+ Dir.pwd.downcase.gsub(/^\//,'').gsub(/\.|\/|\s/,'-')
107
+ end
108
+
109
+ def current_config_path
110
+ "/opt/local/etc/nginx/configs/#{current_config_name}.conf"
111
+ end
112
+ end
data/nginx-osx.gemspec ADDED
@@ -0,0 +1,54 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{nginx-osx}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Gabe Varela"]
9
+ s.date = %q{2009-07-09}
10
+ s.default_executable = %q{nginx-osx}
11
+ s.email = %q{gvarela@gmail.com}
12
+ s.executables = ["nginx-osx"]
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".document",
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "bin/nginx-osx",
25
+ "features/nginx-osx.feature",
26
+ "features/step_definitions/nginx-osx_steps.rb",
27
+ "features/support/env.rb",
28
+ "lib/nginx-osx.rb",
29
+ "nginx-osx.gemspec",
30
+ "templates/nginx.conf.erb",
31
+ "templates/nginx.vhost.conf.erb",
32
+ "test/nginx-osx_test.rb",
33
+ "test/test_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/gvarela/nginx-osx}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.4}
39
+ s.summary = %q{gem for using nginx in development}
40
+ s.test_files = [
41
+ "test/nginx-osx_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ else
51
+ end
52
+ else
53
+ end
54
+ end
@@ -0,0 +1,51 @@
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/conf/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
+ include vhosts/*.conf;
51
+ }
@@ -0,0 +1,78 @@
1
+ # location of mongrel servers to proxy too
2
+ upstream mongrel {
3
+ server 127.0.0.1:<%= port || '3000'%>;
4
+ }
5
+
6
+ server {
7
+ # port to listen on. Can also be set to an IP:PORT
8
+ listen 80 default;
9
+ # set max size for file uploads to 50mb
10
+ client_max_body_size 150M;
11
+ # sets the domain[s] that this vhost server requests for
12
+ # if two apps are on this box remove the ip and setup your hosts file
13
+ server_name _;
14
+ # doc root
15
+ root <%= Dir.pwd %>/public;
16
+ # vhost specific logs
17
+ access_log <%= Dir.pwd %>/log/nginx.access.log main;
18
+ error_log <%= Dir.pwd %>/log/nginx.error.log notice;
19
+
20
+
21
+ location / {
22
+
23
+ index index.html index.htm;
24
+ # forward the user's IP address to Rails
25
+ proxy_set_header X-Real-IP $remote_addr;
26
+ # needed for HTTPS must add an additional server block to configure it.
27
+ # see "The Rails Way" page 665 for more info
28
+ proxy_set_header X-FORWARD_PROTO https;
29
+ # Forward information about the client and host
30
+ # Otherwise our Rails app wouldn't have access to it
31
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
32
+ proxy_set_header Host $http_host;
33
+ proxy_redirect false;
34
+ proxy_max_temp_file_size 0;
35
+
36
+
37
+ # if file exists break execution and serve up file for example files in images, javascripts, and stylesheets
38
+ if (-f $request_filename) {
39
+ break;
40
+ }
41
+
42
+ # hack to prevent image 404s from getting to rails
43
+ if ($request_filename ~ '(/images|\.ico|\.gif|\.jpg|\.png)') {
44
+ return 404;
45
+ }
46
+
47
+ # Rails page caching, if file path plus index.html exists break execution and serve up file
48
+ if (-f $request_filename/index.html) {
49
+ rewrite (.*) $1/index.html break;
50
+ }
51
+
52
+ # Rails page caching, if file.html exists break execution and serve up file
53
+ if (-f $request_filename.html) {
54
+ rewrite (.*) $1.html break;
55
+ }
56
+
57
+ # if file does not exist forward to mongrel
58
+ if (!-f $request_filename) {
59
+ proxy_pass http://mongrel;
60
+ break;
61
+ }
62
+
63
+ # uncomment below and comment out above to configure the upload progress module
64
+ # proxy_pass http://mongrel;
65
+ # track_uploads proxied 30s;
66
+
67
+ }
68
+ # must be an error so point to error page.
69
+ error_page 500 502 503 504 /500.html;
70
+ location = /500.html {
71
+ root <%= Dir.pwd %>/public;
72
+ }
73
+ # uncomment below to configure upload progress module
74
+ # location ^~ /progress {
75
+ # report_uploads proxied;
76
+ # }
77
+
78
+ }
@@ -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,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gvarela-nginx-osx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabe Varela
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-09 00:00:00 -07:00
13
+ default_executable: nginx-osx
14
+ dependencies: []
15
+
16
+ description:
17
+ email: gvarela@gmail.com
18
+ executables:
19
+ - nginx-osx
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - bin/nginx-osx
33
+ - features/nginx-osx.feature
34
+ - features/step_definitions/nginx-osx_steps.rb
35
+ - features/support/env.rb
36
+ - lib/nginx-osx.rb
37
+ - nginx-osx.gemspec
38
+ - templates/nginx.conf.erb
39
+ - templates/nginx.vhost.conf.erb
40
+ - test/nginx-osx_test.rb
41
+ - test/test_helper.rb
42
+ has_rdoc: false
43
+ homepage: http://github.com/gvarela/nginx-osx
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.2.0
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: gem for using nginx in development
68
+ test_files:
69
+ - test/nginx-osx_test.rb
70
+ - test/test_helper.rb