Class: Nginx::Builder::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/shared_infrastructure/nginx/builder.rb

Direct Known Subclasses

ReverseProxyHttp, ReverseProxyHttps, Site

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain_name, *server_blocks) ⇒ Base

Returns a new instance of Base.



34
35
36
37
38
39
# File 'lib/shared_infrastructure/nginx/builder.rb', line 34

def initialize(domain_name, *server_blocks)
  # puts "Base#initialize domain_name: #{domain_name}"
  # puts "Base#initialize server_blocks.inspect: #{server_blocks.inspect}"
  @server_blocks = server_blocks
  @domain_name = domain_name
end

Instance Attribute Details

#domain_nameObject (readonly)

Returns the value of attribute domain_name.



52
53
54
# File 'lib/shared_infrastructure/nginx/builder.rb', line 52

def domain_name
  @domain_name
end

#server_blocksObject (readonly)

Returns the value of attribute server_blocks.



52
53
54
# File 'lib/shared_infrastructure/nginx/builder.rb', line 52

def server_blocks
  @server_blocks
end

Instance Method Details

#https_reminder_messageObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shared_infrastructure/nginx/builder.rb', line 16

def https_reminder_message
  puts %(You have to obtain a certificate and enable TLS for the site.
To do so, reload the Nginx configuration:

sudo nginx -s reload

Then run the following command:

sudo certbot certonly --webroot -w #{Nginx.root_directory(domain_name)} #{Nginx.certbot_domain_names(domain_name)}

You can test renewal with:

sudo certbot renew --dry-run

Finally, re-run this script to configure nginx for TLS.
)
end

#saveObject



41
42
43
44
45
46
# File 'lib/shared_infrastructure/nginx/builder.rb', line 41

def save
  File.open(Nginx.server_block_location(domain_name), "w") do |f|
    f << to_s
  end
  `ln -fs ../sites-available/#{domain_name} #{Nginx.enabled_server_block_location(domain_name)}`
end

#to_sObject



48
49
50
# File 'lib/shared_infrastructure/nginx/builder.rb', line 48

def to_s
  server_blocks.map(&:to_s).join("\n")
end