Module: Apache::Master

Included in:
Config
Defined in:
lib/apache/master.rb

Overview

Options that aren’t specific to a particular purpose go here. Once enough like methods for a particular purpose exist, break them out into a separate module.

Instance Method Summary collapse

Instance Method Details

#add_type!(mime, extension, options = {}) ⇒ Object

Add a MIME type, potentially also adding handlers and encodings

add_type! 'text/html', '.shtml', :handler => 'server-parsed'
add_type! 'text/html', '.gz', :encoding => 'gzip'


71
72
73
74
75
76
# File 'lib/apache/master.rb', line 71

def add_type!(mime, extension, options = {})
  self << "AddType #{mime} #{extension}"
  options.each do |type, value|
    self << "Add#{type.to_s.capitalize} #{value} #{extension}"
  end
end

#apache_alias(*opts) ⇒ Object

Alias a URL to a directory in the filesystem. Used to get around reserved Ruby keyword.



86
87
88
# File 'lib/apache/master.rb', line 86

def apache_alias(*opts)
  self << "Alias #{opts.quoteize * " "}"
end

#apache_include(*opts) ⇒ Object

Include other config files or directories. Used to get around reserved Ruby keyword.



80
81
82
# File 'lib/apache/master.rb', line 80

def apache_include(*opts)
  self << "Include #{opts * " "}"
end

#comment(what) ⇒ Object

Add a comment to the Apache config. Can pass in either a String or Array of comment lines.



56
57
58
# File 'lib/apache/master.rb', line 56

def comment(what)
  self + [ '', what.commentize, '' ].flatten.collect { |line| "# #{line.strip}".strip }
end

#document_root(*opts) ⇒ Object Also known as: document_root!



108
109
110
111
112
# File 'lib/apache/master.rb', line 108

def document_root(*opts)
  dir = opts.first
  directory? dir
  self << "DocumentRoot #{dir.quoteize}"
end

#enable_gzip!Object

Enable gzip compression server-wide on pretty much everything that can be gzip compressed



41
42
43
44
45
46
47
48
# File 'lib/apache/master.rb', line 41

def enable_gzip!
  directory '/' do
    add_output_filter_by_type! :DEFLATE, 'text/html', 'text/plain', 'text/css', 'text/javascript', 'application/javascript'
    browser_match! '^Mozilla/4', "gzip-only-text/html"
    browser_match! '^Mozilla/4\.0[678]', "no-gzip"
    browser_match! '\bMSIE', '!no-gzip', '!gzip-only-text/html'
  end
end

#listen(*opt) ⇒ Object Also known as: listen!

Listen on network interfaces and ports

Each provided parameter generates a new Listen line:

listen "1.2.3.4:80", "2.3.4.5:80" #=>
  Listen "1.2.3.4:80"
  Listen "2.3.4.5:80"


17
18
19
# File 'lib/apache/master.rb', line 17

def listen(*opt)
  opt.each { |adapter| self << "Listen #{adapter.quoteize}" }
end

#modules(*modules, &block) ⇒ Object

Build a module list. Wraps around Modules.build



7
8
9
# File 'lib/apache/master.rb', line 7

def modules(*modules, &block)
  @config += Modules.build(*modules, &block)
end

#passenger(ruby_root, ruby_version, passenger_version) ⇒ Object

Enable Passenger on this server

This assumes that Passenger was installed via the gem. This may or may not work for you, but it works for me.



34
35
36
37
38
# File 'lib/apache/master.rb', line 34

def passenger(ruby_root, ruby_version, passenger_version)
  load_module 'passenger_module', "#{ruby_root}/lib/ruby/gems/#{ruby_version}/gems/passenger-#{passenger_version}/ext/apache2/mod_passenger.so"
  passenger_root "#{ruby_root}/lib/ruby/gems/#{ruby_version}/gems/passenger-#{passenger_version}"
  passenger_ruby "#{ruby_root}/bin/ruby"
end

#runner(user, group) ⇒ Object

Add a User/Group block

runner('www', 'www-data') #=>
  User www
  Group www-data


26
27
28
29
# File 'lib/apache/master.rb', line 26

def runner(user, group)
  user! user
  group! group
end

#script_alias(uri, path) ⇒ Object Also known as: script_alias!

Create a ScriptAlias, checking to make sure the filesystem path exists.



61
62
63
64
# File 'lib/apache/master.rb', line 61

def script_alias(uri, path)
  directory? path
  self << %{ScriptAlias #{[ uri, path ].quoteize * ' '}}
end

#server_name(*opts) ⇒ Object



101
102
103
104
105
106
# File 'lib/apache/master.rb', line 101

def server_name(*opts)
  if first = opts.shift
    self << "ServerName #{first.quoteize}"
    opts.each { |name| server_alias name } if !opts.empty?
  end
end

#set_header(hash) ⇒ Object

Set multiple headers to be delivered for a particular section

set_header 'Content-type' => 'application/octet-stream',
           'Content-disposition' => [ 'attachment', 'env=only-for-downloads' ] #=>
Header set "Content-type" "application/octet-stream"
Header set "Content-dispoaition" "attachment" env=only-for-downloads


95
96
97
98
99
# File 'lib/apache/master.rb', line 95

def set_header(hash)
  hash.each do |key, value|
    self << "Header set #{key.quoteize} #{value.headerize}"
  end
end

#timeout(time) ⇒ Object

Set the TCP timeout. Defined here to get around various other timeout methods.



51
52
53
# File 'lib/apache/master.rb', line 51

def timeout(time)
  self << "Timeout #{time}"
end