Commit d3dd5de6cb53edec4958209d6866747c11849ec4
Committed by
Earth Ugat

1 parent
eee846a4
Bump to v0.3.1.
Revert most templates to :create action. Integrate restriction file directives into the virtual host files themselves.
Showing
8 changed files
with
137 additions
and
98 deletions
... | ... | @@ -18,31 +18,6 @@ |
18 | 18 | # limitations under the License. |
19 | 19 | # |
20 | 20 | |
21 | -# TODO defunct attribs | |
22 | -# The socket used PHP-FPM. If false, fastcgi is not used. | |
23 | -# Examples: | |
24 | -# '127.0.0.1:9000' | |
25 | -# '/var/run/php-fpm.sock' | |
26 | -# false | |
27 | -#default['cfe-nginx-php-fpm']['php_fastcgi_socket'] = '127.0.0.1:9000' | |
28 | - | |
29 | -# PHP-FPM sockets to be used. If unset, or set to string 'php-fpm-pools' (default), | |
30 | -# the recipe automatically gets this value from node['php-fpm']['pools']. | |
31 | -#default['cfe-nginx-php-fpm']['php_fastcgi_sockets'] = [ | |
32 | -# { | |
33 | -# :name => 'example_socket', | |
34 | -# # Example values: | |
35 | -# # '127.0.0.1:9000' | |
36 | -# # '127.0.0.1:9001' | |
37 | -# # '/var/run/php-fpm.sock' | |
38 | -# :listen => '127.0.0.1:9000', | |
39 | -# # An optional array of comments for this socket | |
40 | -# :comments => [] | |
41 | -# } | |
42 | -#] | |
43 | - | |
44 | - | |
45 | - | |
46 | 21 | # Setting 'update_cacert' to true will get the latest cacert from |
47 | 22 | # http://curl.haxx.se/ca/cacert.pem and use that as CAFile for postfix. |
48 | 23 | default['cfe-nginx-php-fpm']['postfix']['update_cacert'] = true |
... | ... | @@ -58,15 +33,6 @@ default['cfe-nginx-php-fpm']['php-fpm']['delete_pool_www'] = true |
58 | 33 | #default['cfe-nginx-php-fpm']['nginx']['priv_dir'] = |
59 | 34 | # "#{node['nginx']['dir']}/private" |
60 | 35 | |
61 | -default['cfe-nginx-php-fpm']['nginx']['restriction_file']['log_robots'] = false | |
62 | -default['cfe-nginx-php-fpm']['nginx']['restriction_file']['log_hidden'] = true | |
63 | -default['cfe-nginx-php-fpm']['nginx']['restriction_file']['log_static'] = false | |
64 | -default['cfe-nginx-php-fpm']['nginx']['restriction_file']['static_types'] = %w{ | |
65 | - js css ogg ogv svg svgz eot otf woff mp4 ttf rss atom | |
66 | - jpg jpeg gif png ico zip tgz gz rar bz2 | |
67 | - doc xls exe ppt tar mid midi wav bmp rtf | |
68 | -} | |
69 | - | |
70 | 36 | default['cfe-nginx-php-fpm']['nginx']['sites'] = [ |
71 | 37 | #{ |
72 | 38 | # Name of server. Mandatory. |
... | ... | @@ -86,16 +52,26 @@ default['cfe-nginx-php-fpm']['nginx']['sites'] = [ |
86 | 52 | # |
87 | 53 | #:index => 'index.php', |
88 | 54 | |
89 | - # Access log options as one long string. Default: nil | |
90 | - # | |
91 | - #:access_log_options => '<some options>', | |
92 | - | |
93 | 55 | # Whether to include a default virtual server named '_' or not. |
94 | 56 | # If there is more than one server given in this 'sites' array, |
95 | 57 | # :catch_all value will always be overriden to false. Default: true |
96 | 58 | # |
97 | 59 | #:catch_all => true, |
98 | 60 | |
61 | + # Access log options as one long string. Default: nil | |
62 | + # | |
63 | + #:access_log_options => '<some options>', | |
64 | + | |
65 | + # Whether to log access to /robots.txt | |
66 | + # Default: false | |
67 | + # | |
68 | + #:log_robots => false, | |
69 | + | |
70 | + # Whether to log attempted accesses to hidden directories and files | |
71 | + # Default: true | |
72 | + # | |
73 | + #:log_hidden => true, | |
74 | + | |
99 | 75 | # Necessary values for SSL/TLS setup. Default: nil |
100 | 76 | # |
101 | 77 | #:ssl => { |
... | ... | @@ -179,6 +155,16 @@ default['cfe-nginx-php-fpm']['nginx']['sites'] = [ |
179 | 155 | # Default: (an auto-generated string) |
180 | 156 | # :add_statements => Additional statements to put in the config file. |
181 | 157 | # Default: [] |
158 | + # :static_types => An array of strings that denote the file extensions | |
159 | + # to be included in a certain location directive that | |
160 | + # gives them a max expiration header. Set this value | |
161 | + # to false to disable this directive. Default: %w{ | |
162 | + # js css ogg ogv svg svgz eot otf woff mp4 ttf | |
163 | + # rss atom jpg jpeg gif png ico zip tgz gz rar | |
164 | + # bz2 doc xls exe ppt tar mid midi wav bmp rtf | |
165 | + # } | |
166 | + # :log_static => Whether to log accesses to the above static files | |
167 | + # or not. Default: false | |
182 | 168 | # |
183 | 169 | # Unique attributes for each type are indicated below: |
184 | 170 | # Basic PHP Site (:type => 'basic'): |
... | ... | @@ -208,8 +194,6 @@ default['php-fpm']['emergency_restart_threshold'] = '10' |
208 | 194 | default['php-fpm']['emergency_restart_interval'] = '1m' |
209 | 195 | default['php-fpm']['process_control_timeout'] = '10s' |
210 | 196 | default['php-fpm']['pools'] = [ |
211 | - # Most likely, just use one pool for all PHP needs. | |
212 | - # (But there are exceptions, of course) | |
213 | 197 | { |
214 | 198 | # Required attributes: |
215 | 199 | :name => 'example_pool', | ... | ... |
... | ... | @@ -4,11 +4,11 @@ maintainer_email 'sysadmin@chromedia.com' |
4 | 4 | license 'Apache License' |
5 | 5 | description 'Simplifies setup of Nginx+PHP-FPM in Chromedia.' |
6 | 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) |
7 | -version '0.3.0' | |
7 | +version '0.3.1' | |
8 | 8 | |
9 | 9 | { |
10 | 10 | 'php-fpm' => '0.7.5', |
11 | - 'mariadb' => '0.2.12', | |
11 | + 'mariadb' => '0.3.1', | |
12 | 12 | 'postfix' => '3.6.2', |
13 | 13 | 'nginx' => '2.7.6' |
14 | 14 | }.each { |cb, ver| depends cb, '~> ' + ver } | ... | ... |
... | ... | @@ -28,20 +28,6 @@ priv_dir = node['cfe-nginx-php-fpm']['nginx']['priv_dir'] |
28 | 28 | end |
29 | 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 | 31 | # Generate config files for each virtual server. |
46 | 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 | 51 | site_ss1 = site[:server_statements_1] || [] |
66 | 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 | 57 | temp_catch_all = site.has_key?(:catch_all) ? site[:catch_all] : true |
69 | 58 | site_catch_all = catch_all_def_false ? false : temp_catch_all |
70 | 59 | site_types = ( site[:types] || [] ).uniq { |e| e[:type] } |
... | ... | @@ -75,6 +64,11 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
75 | 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 | 72 | # If TLS/SSL is enabled, configure it: |
79 | 73 | if site_ssl |
80 | 74 | if site_ssl[:letsencrypt] |
... | ... | @@ -118,11 +112,6 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
118 | 112 | execute "openssl dhparam -out #{path_dhparam} #{dh_modulus}" do |
119 | 113 | not_if { ::File.exist?(path_dhparam) } |
120 | 114 | end |
121 | - | |
122 | - else | |
123 | - path_crt = '' | |
124 | - path_key = '' | |
125 | - path_dhparam = '' | |
126 | 115 | end |
127 | 116 | |
128 | 117 | # If basic auth is enabled, create htpasswd file |
... | ... | @@ -135,16 +124,13 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
135 | 124 | "\\n\" >> #{path_pass}" |
136 | 125 | action :run |
137 | 126 | sensitive true |
138 | - not_if { ::File.exist?(path_pass) } | |
139 | 127 | end |
140 | 128 | end |
141 | - else | |
142 | - path_pass = '' | |
143 | 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 | 135 | # :name => 'string', |
150 | 136 | # :servers => [ |
... | ... | @@ -155,13 +141,35 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
155 | 141 | |
156 | 142 | # Create necessary include files for each type of this site |
157 | 143 | site_types.each do |stype| |
144 | + | |
145 | + # Set default attributes for each site type | |
158 | 146 | stype_subp = stype[:subpath] ? stype[:subpath].gsub(/^\/+|\/+$|\s/, '') : '' |
159 | 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 | 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 | 173 | :name => stype_ups, |
166 | 174 | :servers => stype[:upstream_servers] || [] |
167 | 175 | } ) |
... | ... | @@ -169,40 +177,30 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
169 | 177 | case stype[:type] |
170 | 178 | # BASIC PHP SITE |
171 | 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 | 183 | stype[:fastcgi_intercept_errors] : false |
174 | 184 | |
175 | 185 | template "#{inc_dir}/inc_type_basic_#{site_sname}" do |
176 | 186 | source 'inc_type_basic.erb' |
177 | 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 | 189 | end |
187 | 190 | site_includes.push("#{inc_dir}/inc_type_basic_#{site_sname}") |
188 | 191 | |
189 | 192 | # STANDARD WORDPRESS SITE |
190 | 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 | 198 | stype[:fastcgi_intercept_errors] : false |
193 | 199 | |
194 | 200 | template "#{inc_dir}/inc_type_wordpress_#{site_sname}" do |
195 | 201 | source 'inc_type_wordpress.erb' |
196 | 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 | 204 | end |
207 | 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 | 209 | template "#{inc_dir}/inc_type_webserver_#{site_sname}" do |
212 | 210 | source 'inc_type_webserver.erb' |
213 | 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 | 213 | end |
221 | 214 | site_ins.push("map $http_upgrade $connection_upgrade {\n"\ |
222 | 215 | " default upgrade;\n"\ |
... | ... | @@ -233,7 +226,6 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
233 | 226 | # Create the main config file for this site |
234 | 227 | template "#{node['nginx']['dir']}/sites-available/#{site_sname}" do |
235 | 228 | source 'nginx_site.conf.erb' |
236 | - action :create_if_missing | |
237 | 229 | mode 0644 |
238 | 230 | notifies :restart, 'service[nginx]', :delayed |
239 | 231 | variables( |
... | ... | @@ -244,15 +236,17 @@ node['cfe-nginx-php-fpm']['nginx']['sites'].each do |site| |
244 | 236 | :ssl => site_ssl, |
245 | 237 | :auth => site_auth, |
246 | 238 | |
247 | - :access_log_options => site_alo, | |
248 | 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 | 244 | :path_crt => path_crt, |
251 | 245 | :path_key => path_key, |
252 | 246 | :path_pass => path_pass, |
253 | 247 | :path_dhparam => path_dhparam, |
254 | 248 | |
255 | - :upstreams => upstreams, | |
249 | + :upstreams => site_upstreams, | |
256 | 250 | :includes => site_includes, |
257 | 251 | :init_statements => site_ins, |
258 | 252 | :add_headers => site_aheads, | ... | ... |
... | ... | @@ -2,6 +2,17 @@ |
2 | 2 | # |
3 | 3 | # A basic PHP site config. |
4 | 4 | |
5 | +<% if @static_types -%> | |
6 | +# Send expires headers and (probably?) turn off 404 error logging. | |
7 | +location ~* ^/<%= @subpath %>.+\.(<%= @static_types.join('|') %>)$ { | |
8 | + expires max; | |
9 | +<% unless @log_static -%> | |
10 | + log_not_found off; | |
11 | + access_log off; | |
12 | +<% end -%> | |
13 | +} | |
14 | + | |
15 | +<% end -%> | |
5 | 16 | <% @add_statements.each do |ads| -%> |
6 | 17 | <%= ads %> |
7 | 18 | ... | ... |
... | ... | @@ -6,6 +6,17 @@ if ($http_user_agent ~ "MSIE") { |
6 | 6 | return 303 https://browser-update.org/update.html; |
7 | 7 | } |
8 | 8 | |
9 | +<% if @static_types -%> | |
10 | +# Send expires headers and (probably?) turn off 404 error logging. | |
11 | +location ~* ^/<%= @subpath %>.+\.(<%= @static_types.join('|') %>)$ { | |
12 | + expires max; | |
13 | +<% unless @log_static -%> | |
14 | + log_not_found off; | |
15 | + access_log off; | |
16 | +<% end -%> | |
17 | +} | |
18 | + | |
19 | +<% end -%> | |
9 | 20 | <% @add_statements.each do |ads| -%> |
10 | 21 | <%= ads %> |
11 | 22 | ... | ... |
... | ... | @@ -6,6 +6,17 @@ |
6 | 6 | # Add trailing slash to */wp-admin requests. |
7 | 7 | rewrite /<%= @subpath %>wp-admin$ $scheme://$host$uri/ permanent; |
8 | 8 | |
9 | +<% if @static_types -%> | |
10 | +# Send expires headers and (probably?) turn off 404 error logging. | |
11 | +location ~* ^/<%= @subpath %>.+\.(<%= @static_types.join('|') %>)$ { | |
12 | + expires max; | |
13 | +<% unless @log_static -%> | |
14 | + log_not_found off; | |
15 | + access_log off; | |
16 | +<% end -%> | |
17 | +} | |
18 | + | |
19 | +<% end -%> | |
9 | 20 | <% @add_statements.each do |ads| -%> |
10 | 21 | <%= ads %> |
11 | 22 | ... | ... |
... | ... | @@ -120,6 +120,28 @@ server { |
120 | 120 | access_log <%= @log_dir %>/<%= @server_name %>.access.log<% if @access_log_options %> <%= @access_log_options %><% end %>; |
121 | 121 | error_log <%= @log_dir %>/<%= @server_name %>.error.log; |
122 | 122 | |
123 | + location = /favicon.ico { | |
124 | + log_not_found off; | |
125 | + access_log off; | |
126 | + } | |
127 | + | |
128 | + location = /robots.txt { | |
129 | + allow all; | |
130 | +<% unless @log_robots -%> | |
131 | + log_not_found off; | |
132 | + access_log off; | |
133 | +<% end -%> | |
134 | + } | |
135 | + | |
136 | + # Deny all attempts to access hidden files and folders | |
137 | + location ~ (^|/)\. { | |
138 | + deny all; | |
139 | +<% unless @log_hidden -%> | |
140 | + log_not_found off; | |
141 | + access_log off; | |
142 | +<% end -%> | |
143 | + } | |
144 | + | |
123 | 145 | <% @server_statements_1.each do |s1| -%> |
124 | 146 | <%= sm %> |
125 | 147 | <% end -%> | ... | ... |