Class: Appserver::Nginx

Inherits:
Struct
  • Object
show all
Defined in:
lib/appserver/nginx.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_dir) ⇒ Nginx

Returns a new instance of Nginx.



8
9
10
# File 'lib/appserver/nginx.rb', line 8

def initialize (server_dir)
  self.server_dir = server_dir
end

Instance Attribute Details

#server_dirObject

Returns the value of attribute server_dir

Returns:

  • (Object)

    the current value of server_dir



2
3
4
# File 'lib/appserver/nginx.rb', line 2

def server_dir
  @server_dir
end

Class Method Details

.write_config(server_dir) ⇒ Object



4
5
6
# File 'lib/appserver/nginx.rb', line 4

def self.write_config (server_dir)
  new(server_dir).write_config
end

Instance Method Details

#write_configObject



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
# File 'lib/appserver/nginx.rb', line 12

def write_config
  Utils.safe_replace_file(server_dir.nginx_conf) do |f|
    f.puts "# Nginx configuration automagically generated by the \"appserver\" gem using"
    f.puts "# the appserver directory config #{server_dir.config_file}"
    f.puts "# Include this file into your system's nginx.conf (using an include statement"
    f.puts "# inside a http statement) to use it. See http://github.com/zargony/appserver"
    f.puts "# for details."
    # The default server always responds with 403 Forbidden
    f.puts "server {"
    f.puts "  listen 80 default;"
    f.puts "  server_name _;"
    f.puts "  deny all;"
    f.puts "}"
    # Add application-specific Nginx configuration
    server_dir.apps.each do |app|
      f.puts ""
      f.puts "# Application: #{app.name}"
      if app.socket
        f.puts "upstream #{app.name} {"
        f.puts "  server unix:#{app.socket} fail_timeout=0;"
        f.puts "}"
        write_server_definition(f, app)
        write_server_definition(f, app, true) if app.ssl?
      end
    end
  end
end