Class: NginxUtils::VirtualHost
- Inherits:
-
Object
- Object
- NginxUtils::VirtualHost
- Defined in:
- lib/nginx_utils/virtual_host.rb
Instance Attribute Summary collapse
-
#access_log_format ⇒ Object
Returns the value of attribute access_log_format.
-
#auth_basic ⇒ Object
Returns the value of attribute auth_basic.
-
#auth_basic_user_file ⇒ Object
Returns the value of attribute auth_basic_user_file.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#error_log_level ⇒ Object
Returns the value of attribute error_log_level.
-
#http ⇒ Object
Returns the value of attribute http.
-
#https ⇒ Object
Returns the value of attribute https.
-
#index ⇒ Object
Returns the value of attribute index.
-
#log_dir ⇒ Object
Returns the value of attribute log_dir.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#root ⇒ Object
Returns the value of attribute root.
-
#server_name ⇒ Object
Returns the value of attribute server_name.
-
#ssl_certificate ⇒ Object
Returns the value of attribute ssl_certificate.
-
#ssl_certificate_key ⇒ Object
Returns the value of attribute ssl_certificate_key.
-
#vhost_type ⇒ Object
Returns the value of attribute vhost_type.
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(options = {}) ⇒ VirtualHost
constructor
A new instance of VirtualHost.
- #set_common_params(options) ⇒ Object
- #set_log_params(options) ⇒ Object
- #set_protocols(options) ⇒ Object
- #set_vhost_type(options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ VirtualHost
Returns a new instance of VirtualHost.
7 8 9 10 11 12 13 |
# File 'lib/nginx_utils/virtual_host.rb', line 7 def initialize(={}) = .inject({}){|r,(k,v)| r.store(k.to_sym, v); r} set_vhost_type() set_common_params() set_protocols() set_log_params() end |
Instance Attribute Details
#access_log_format ⇒ Object
Returns the value of attribute access_log_format.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def access_log_format @access_log_format end |
#auth_basic ⇒ Object
Returns the value of attribute auth_basic.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def auth_basic @auth_basic end |
#auth_basic_user_file ⇒ Object
Returns the value of attribute auth_basic_user_file.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def auth_basic_user_file @auth_basic_user_file end |
#destination ⇒ Object
Returns the value of attribute destination.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def destination @destination end |
#error_log_level ⇒ Object
Returns the value of attribute error_log_level.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def error_log_level @error_log_level end |
#http ⇒ Object
Returns the value of attribute http.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def http @http end |
#https ⇒ Object
Returns the value of attribute https.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def https @https end |
#index ⇒ Object
Returns the value of attribute index.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def index @index end |
#log_dir ⇒ Object
Returns the value of attribute log_dir.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def log_dir @log_dir end |
#prefix ⇒ Object
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def prefix @prefix end |
#root ⇒ Object
Returns the value of attribute root.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def root @root end |
#server_name ⇒ Object
Returns the value of attribute server_name.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def server_name @server_name end |
#ssl_certificate ⇒ Object
Returns the value of attribute ssl_certificate.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def ssl_certificate @ssl_certificate end |
#ssl_certificate_key ⇒ Object
Returns the value of attribute ssl_certificate_key.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def ssl_certificate_key @ssl_certificate_key end |
#vhost_type ⇒ Object
Returns the value of attribute vhost_type.
5 6 7 |
# File 'lib/nginx_utils/virtual_host.rb', line 5 def vhost_type @vhost_type end |
Instance Method Details
#config ⇒ Object
70 71 72 73 |
# File 'lib/nginx_utils/virtual_host.rb', line 70 def config content = open(File.("../../../template/virtual_host.erb", __FILE__)).read ERB.new(content).result(binding).gsub(/^\s+$/, "").gsub(/\n+/, "\n") end |
#set_common_params(options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nginx_utils/virtual_host.rb', line 39 def set_common_params() # Arguments: prefix, server_name, root, index, auth_basic, auth_basic_user_file in options @prefix = .fetch(:prefix, "/usr/local/nginx") @server_name = .fetch(:server_name, "example.com") @root = .fetch(:root, File.join(@prefix, "vhosts", @server_name, "html")) @index = .fetch(:index, ["index.html", "index.htm"].join(" ")) @auth_basic = [:auth_basic] if @auth_basic @auth_basic_user_file = .fetch(:auth_basic_user_file, File.join(@prefix, "vhosts", @server_name, "etc", "users")) end end |
#set_log_params(options) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/nginx_utils/virtual_host.rb', line 63 def set_log_params() # Arguments: log_dir, access_log_format, error_log_level in options @log_dir = .fetch(:log_dir, File.join(@prefix, "vhosts", @server_name, "logs")) @access_log_format = .fetch(:access_log_format, :ltsv) @error_log_level = .fetch(:error_log_level, :info) end |
#set_protocols(options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/nginx_utils/virtual_host.rb', line 51 def set_protocols() # Arguments: http, https, ssl_certificate, ssl_certificate_key in options @http = [:http].nil? ? true : [:http] @https = [:https].nil? ? true : [:https] @http = false if [:only_https] @https = false if [:only_http] if @https @ssl_certificate = .fetch(:ssl_certificate, File.join(@prefix, "vhosts", @server_name, "ssl.crt", "server.crt")) @ssl_certificate_key = .fetch(:ssl_certificate_key, File.join(@prefix, "vhosts", @server_name, "ssl.key", "server.key")) end end |
#set_vhost_type(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nginx_utils/virtual_host.rb', line 15 def set_vhost_type() # Arguments: vhost_type, destination in options if [:vhost_type].nil? @vhost_type = :normal else case [:vhost_type].to_sym when :unicorn then @vhost_type = :unicorn @destination = .fetch(:destination, "127.0.0.1:8080") when :proxy then @vhost_type = :proxy @destination = .fetch(:destination, "127.0.0.1:8080") when :passenger then @vhost_type = :passenger else @vhost_type = :normal end end if @destination =~ /\.sock$/ && @destination !~ /^unix:/ @destination = "unix:#{@destination}" end end |