|
@@ -28,20 +28,6 @@ priv_dir = node['cfe-nginx-php-fpm']['nginx']['priv_dir'] |
|
@@ -28,20 +28,6 @@ priv_dir = node['cfe-nginx-php-fpm']['nginx']['priv_dir'] |
|
28
|
end
|
28
|
end
|
|
29
|
end
|
29
|
end
|
|
30
|
|
30
|
|
|
31
|
-# The restrictions file containing default rules for virtual servers.
|
|
|
|
32
|
-path_rest = "#{inc_dir}/inc_restrictions"
|
|
|
|
33
|
-restfa = node['cfe-nginx-php-fpm']['nginx']['restriction_file']
|
|
|
|
34
|
-template path_rest do
|
|
|
|
35
|
- action :create_if_missing
|
|
|
|
36
|
- mode 0644
|
|
|
|
37
|
- variables(
|
|
|
|
38
|
- :log_robots => restfa['log_robots'],
|
|
|
|
39
|
- :log_hidden => restfa['log_hidden'],
|
|
|
|
40
|
- :log_static => restfa['log_static'],
|
|
|
|
41
|
- :static_types => restfa['static_types']
|
|
|
|
42
|
- )
|
|
|
|
43
|
-end
|
|
|
|
44
|
-
|
|
|
|
45
|
# Generate config files for each virtual server.
|
31
|
# Generate config files for each virtual server.
|
|
46
|
catch_all_def_false = node['cfe-nginx-php-fpm']['nginx']['sites'].length > 1
|
32
|
catch_all_def_false = node['cfe-nginx-php-fpm']['nginx']['sites'].length > 1
|
|
47
|
|
33
|
|
|
@@ -65,6 +51,9 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
@@ -65,6 +51,9 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
65
|
site_ss1 = site[:server_statements_1] || []
|
51
|
site_ss1 = site[:server_statements_1] || []
|
|
66
|
site_ss2 = site[:server_statements_2] || []
|
52
|
site_ss2 = site[:server_statements_2] || []
|
|
67
|
|
53
|
|
|
|
|
54
|
+ site_logrobots = site.has_key?(:log_robots) ? site[:log_robots] : false
|
|
|
|
55
|
+ site_loghidden = site.has_key?(:log_hidden) ? site[:log_hidden] : true
|
|
|
|
56
|
+
|
|
68
|
temp_catch_all = site.has_key?(:catch_all) ? site[:catch_all] : true
|
57
|
temp_catch_all = site.has_key?(:catch_all) ? site[:catch_all] : true
|
|
69
|
site_catch_all = catch_all_def_false ? false : temp_catch_all
|
58
|
site_catch_all = catch_all_def_false ? false : temp_catch_all
|
|
70
|
site_types = ( site[:types] || [] ).uniq { |e| e[:type] }
|
59
|
site_types = ( site[:types] || [] ).uniq { |e| e[:type] }
|
|
@@ -75,6 +64,11 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
@@ -75,6 +64,11 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
75
|
'X-Permitted-Cross-Domain-Policies' => 'none'
|
64
|
'X-Permitted-Cross-Domain-Policies' => 'none'
|
|
76
|
}
|
65
|
}
|
|
77
|
|
66
|
|
|
|
|
67
|
+ path_crt = ''
|
|
|
|
68
|
+ path_key = ''
|
|
|
|
69
|
+ path_dhparam = ''
|
|
|
|
70
|
+ path_pass = ''
|
|
|
|
71
|
+
|
|
78
|
# If TLS/SSL is enabled, configure it:
|
72
|
# If TLS/SSL is enabled, configure it:
|
|
79
|
if site_ssl
|
73
|
if site_ssl
|
|
80
|
if site_ssl[:letsencrypt]
|
74
|
if site_ssl[:letsencrypt]
|
|
@@ -118,11 +112,6 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
@@ -118,11 +112,6 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
118
|
execute "openssl dhparam -out #{path_dhparam} #{dh_modulus}" do
|
112
|
execute "openssl dhparam -out #{path_dhparam} #{dh_modulus}" do
|
|
119
|
not_if { ::File.exist?(path_dhparam) }
|
113
|
not_if { ::File.exist?(path_dhparam) }
|
|
120
|
end
|
114
|
end
|
|
121
|
-
|
|
|
|
122
|
- else
|
|
|
|
123
|
- path_crt = ''
|
|
|
|
124
|
- path_key = ''
|
|
|
|
125
|
- path_dhparam = ''
|
|
|
|
126
|
end
|
115
|
end
|
|
127
|
|
116
|
|
|
128
|
# If basic auth is enabled, create htpasswd file
|
117
|
# If basic auth is enabled, create htpasswd file
|
|
@@ -135,16 +124,13 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
@@ -135,16 +124,13 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
135
|
"\\n\" >> #{path_pass}"
|
124
|
"\\n\" >> #{path_pass}"
|
|
136
|
action :run
|
125
|
action :run
|
|
137
|
sensitive true
|
126
|
sensitive true
|
|
138
|
- not_if { ::File.exist?(path_pass) }
|
|
|
|
139
|
end
|
127
|
end
|
|
140
|
end
|
128
|
end
|
|
141
|
- else
|
|
|
|
142
|
- path_pass = ''
|
|
|
|
143
|
end
|
129
|
end
|
|
144
|
|
130
|
|
|
145
|
- site_includes = [path_rest]
|
|
|
|
146
|
- upstreams = []
|
|
|
|
147
|
- # upstreams element:
|
131
|
+ site_includes = []
|
|
|
|
132
|
+ site_upstreams = []
|
|
|
|
133
|
+ # site_upstreams element:
|
|
148
|
# {
|
134
|
# {
|
|
149
|
# :name => 'string',
|
135
|
# :name => 'string',
|
|
150
|
# :servers => [
|
136
|
# :servers => [
|
|
@@ -155,13 +141,35 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
@@ -155,13 +141,35 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
155
|
|
141
|
|
|
156
|
# Create necessary include files for each type of this site
|
142
|
# Create necessary include files for each type of this site
|
|
157
|
site_types.each do |stype|
|
143
|
site_types.each do |stype|
|
|
|
|
144
|
+
|
|
|
|
145
|
+ # Set default attributes for each site type
|
|
158
|
stype_subp = stype[:subpath] ? stype[:subpath].gsub(/^\/+|\/+$|\s/, '') : ''
|
146
|
stype_subp = stype[:subpath] ? stype[:subpath].gsub(/^\/+|\/+$|\s/, '') : ''
|
|
159
|
stype_subp = stype_subp.length > 0 ? "#{stype_subp}/" : stype_subp
|
147
|
stype_subp = stype_subp.length > 0 ? "#{stype_subp}/" : stype_subp
|
|
160
|
- stype_ads = stype[:add_statements] || []
|
|
|
|
161
|
- stype_ups = stype[:upstream_name] ||
|
148
|
+
|
|
|
|
149
|
+ stype_ads = stype[:add_statements] || []
|
|
|
|
150
|
+ stype_ups = stype[:upstream_name] ||
|
|
162
|
"#{stype[:type]}_#{site_sname.gsub('.', '_')}"
|
151
|
"#{stype[:type]}_#{site_sname.gsub('.', '_')}"
|
|
163
|
|
152
|
|
|
164
|
- upstreams.push( {
|
153
|
+ stype_logstatic = stype.has_key?(:log_static) ? stype[:log_static] : false
|
|
|
|
154
|
+ stype_statics = if stype.has_key?(:static_types)
|
|
|
|
155
|
+ stype[:static_types]
|
|
|
|
156
|
+ else
|
|
|
|
157
|
+ %w{
|
|
|
|
158
|
+ js css ogg ogv svg svgz eot otf woff mp4 ttf rss atom
|
|
|
|
159
|
+ jpg jpeg gif png ico zip tgz gz rar bz2
|
|
|
|
160
|
+ doc xls exe ppt tar mid midi wav bmp rtf
|
|
|
|
161
|
+ }
|
|
|
|
162
|
+ end
|
|
|
|
163
|
+
|
|
|
|
164
|
+ vars = {
|
|
|
|
165
|
+ :subpath => stype_subp,
|
|
|
|
166
|
+ :upstream_name => stype_ups,
|
|
|
|
167
|
+ :add_statements => stype_ads,
|
|
|
|
168
|
+ :static_types => stype_statics,
|
|
|
|
169
|
+ :log_static => stype_logstatic
|
|
|
|
170
|
+ }
|
|
|
|
171
|
+
|
|
|
|
172
|
+ site_upstreams.push( {
|
|
165
|
:name => stype_ups,
|
173
|
:name => stype_ups,
|
|
166
|
:servers => stype[:upstream_servers] || []
|
174
|
:servers => stype[:upstream_servers] || []
|
|
167
|
} )
|
175
|
} )
|
|
@@ -169,40 +177,30 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
@@ -169,40 +177,30 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
169
|
case stype[:type]
|
177
|
case stype[:type]
|
|
170
|
# BASIC PHP SITE
|
178
|
# BASIC PHP SITE
|
|
171
|
when 'basic'
|
179
|
when 'basic'
|
|
172
|
- stype_intererror = stype.has_key?(:fastcgi_intercept_errors) ?
|
180
|
+ vars[:index] = site_index
|
|
|
|
181
|
+ vars[:fastcgi_intercept_errors] =
|
|
|
|
182
|
+ stype.has_key?(:fastcgi_intercept_errors) ?
|
|
173
|
stype[:fastcgi_intercept_errors] : false
|
183
|
stype[:fastcgi_intercept_errors] : false
|
|
174
|
|
184
|
|
|
175
|
template "#{inc_dir}/inc_type_basic_#{site_sname}" do
|
185
|
template "#{inc_dir}/inc_type_basic_#{site_sname}" do
|
|
176
|
source 'inc_type_basic.erb'
|
186
|
source 'inc_type_basic.erb'
|
|
177
|
mode 0644
|
187
|
mode 0644
|
|
178
|
- action :create_if_missing
|
|
|
|
179
|
- variables(
|
|
|
|
180
|
- :index => site_index,
|
|
|
|
181
|
- :subpath => stype_subp,
|
|
|
|
182
|
- :upstream_name => stype_ups,
|
|
|
|
183
|
- :add_statements => stype_ads,
|
|
|
|
184
|
- :fastcgi_intercept_errors => stype_intererror
|
|
|
|
185
|
- )
|
188
|
+ variables vars
|
|
186
|
end
|
189
|
end
|
|
187
|
site_includes.push("#{inc_dir}/inc_type_basic_#{site_sname}")
|
190
|
site_includes.push("#{inc_dir}/inc_type_basic_#{site_sname}")
|
|
188
|
|
191
|
|
|
189
|
# STANDARD WORDPRESS SITE
|
192
|
# STANDARD WORDPRESS SITE
|
|
190
|
when 'wordpress'
|
193
|
when 'wordpress'
|
|
191
|
- stype_intererror = stype.has_key?(:fastcgi_intercept_errors) ?
|
194
|
+ vars[:index] = site_index
|
|
|
|
195
|
+ vars[:loginpage_statements] = stype[:loginpage_statements] || []
|
|
|
|
196
|
+ vars[:fastcgi_intercept_errors] =
|
|
|
|
197
|
+ stype.has_key?(:fastcgi_intercept_errors) ?
|
|
192
|
stype[:fastcgi_intercept_errors] : false
|
198
|
stype[:fastcgi_intercept_errors] : false
|
|
193
|
|
199
|
|
|
194
|
template "#{inc_dir}/inc_type_wordpress_#{site_sname}" do
|
200
|
template "#{inc_dir}/inc_type_wordpress_#{site_sname}" do
|
|
195
|
source 'inc_type_wordpress.erb'
|
201
|
source 'inc_type_wordpress.erb'
|
|
196
|
mode 0644
|
202
|
mode 0644
|
|
197
|
- action :create_if_missing
|
|
|
|
198
|
- variables(
|
|
|
|
199
|
- :index => site_index,
|
|
|
|
200
|
- :subpath => stype_subp,
|
|
|
|
201
|
- :upstream_name => stype_ups,
|
|
|
|
202
|
- :add_statements => stype_ads,
|
|
|
|
203
|
- :loginpage_statements => stype[:loginpage_statements] || [],
|
|
|
|
204
|
- :fastcgi_intercept_errors => stype_intererror
|
|
|
|
205
|
- )
|
203
|
+ variables vars
|
|
206
|
end
|
204
|
end
|
|
207
|
site_includes.push("#{inc_dir}/inc_type_wordpress_#{site_sname}")
|
205
|
site_includes.push("#{inc_dir}/inc_type_wordpress_#{site_sname}")
|
|
208
|
|
206
|
|
|
@@ -211,12 +209,7 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
@@ -211,12 +209,7 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
211
|
template "#{inc_dir}/inc_type_webserver_#{site_sname}" do
|
209
|
template "#{inc_dir}/inc_type_webserver_#{site_sname}" do
|
|
212
|
source 'inc_type_webserver.erb'
|
210
|
source 'inc_type_webserver.erb'
|
|
213
|
mode 0644
|
211
|
mode 0644
|
|
214
|
- action :create_if_missing
|
|
|
|
215
|
- variables(
|
|
|
|
216
|
- :subpath => stype_subp,
|
|
|
|
217
|
- :upstream_name => stype_ups,
|
|
|
|
218
|
- :add_statements => stype_ads
|
|
|
|
219
|
- )
|
212
|
+ variables vars
|
|
220
|
end
|
213
|
end
|
|
221
|
site_ins.push("map $http_upgrade $connection_upgrade {\n"\
|
214
|
site_ins.push("map $http_upgrade $connection_upgrade {\n"\
|
|
222
|
" default upgrade;\n"\
|
215
|
" default upgrade;\n"\
|
|
@@ -233,7 +226,6 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
@@ -233,7 +226,6 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
233
|
# Create the main config file for this site
|
226
|
# Create the main config file for this site
|
|
234
|
template "#{node['nginx']['dir']}/sites-available/#{site_sname}" do
|
227
|
template "#{node['nginx']['dir']}/sites-available/#{site_sname}" do
|
|
235
|
source 'nginx_site.conf.erb'
|
228
|
source 'nginx_site.conf.erb'
|
|
236
|
- action :create_if_missing
|
|
|
|
237
|
mode 0644
|
229
|
mode 0644
|
|
238
|
notifies :restart, 'service[nginx]', :delayed
|
230
|
notifies :restart, 'service[nginx]', :delayed
|
|
239
|
variables(
|
231
|
variables(
|
|
@@ -244,15 +236,17 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
@@ -244,15 +236,17 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
|
244
|
:ssl => site_ssl,
|
236
|
:ssl => site_ssl,
|
|
245
|
:auth => site_auth,
|
237
|
:auth => site_auth,
|
|
246
|
|
238
|
|
|
247
|
- :access_log_options => site_alo,
|
|
|
|
248
|
:catch_all => site_catch_all,
|
239
|
:catch_all => site_catch_all,
|
|
|
|
240
|
+ :access_log_options => site_alo,
|
|
|
|
241
|
+ :log_robots => site_logrobots,
|
|
|
|
242
|
+ :log_hidden => site_loghidden,
|
|
249
|
|
243
|
|
|
250
|
:path_crt => path_crt,
|
244
|
:path_crt => path_crt,
|
|
251
|
:path_key => path_key,
|
245
|
:path_key => path_key,
|
|
252
|
:path_pass => path_pass,
|
246
|
:path_pass => path_pass,
|
|
253
|
:path_dhparam => path_dhparam,
|
247
|
:path_dhparam => path_dhparam,
|
|
254
|
|
248
|
|
|
255
|
- :upstreams => upstreams,
|
249
|
+ :upstreams => site_upstreams,
|
|
256
|
:includes => site_includes,
|
250
|
:includes => site_includes,
|
|
257
|
:init_statements => site_ins,
|
251
|
:init_statements => site_ins,
|
|
258
|
:add_headers => site_aheads,
|
252
|
:add_headers => site_aheads,
|