Skip to content

Commit ad5bdef

Browse files
committed
configure unix socket on ssl vhost
1 parent fffe7a3 commit ad5bdef

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

spec/acceptance/nginx_server_spec.rb

+53
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,57 @@ class { 'nginx': }
247247
end
248248
end
249249
end
250+
251+
context 'should run with unix socket' do
252+
it 'configures a nginx server' do
253+
pp = "
254+
class { 'nginx': }
255+
nginx::resource::server { 'www.puppetlabs.com':
256+
ensure => present,
257+
www_root => '/var/www/www.puppetlabs.com',
258+
listen_unix_socket_enable => true,
259+
listen_unix_socket => '/tmp/nginx.sock'
260+
}
261+
host { 'www.puppetlabs.com': ip => '127.0.0.1', }
262+
file { ['/var/www','/var/www/www.puppetlabs.com']: ensure => directory }
263+
file { '/var/www/www.puppetlabs.com/index.html': ensure => file, content => 'Hello from www\n', }
264+
"
265+
266+
apply_manifest(pp, catch_failures: true)
267+
apply_manifest(pp, catch_changes: true)
268+
end
269+
270+
describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do
271+
it { is_expected.to be_file }
272+
it { is_expected.to contain 'www.puppetlabs.com' }
273+
end
274+
275+
describe file('/etc/nginx/sites-enabled/www.puppetlabs.com.conf') do
276+
it { is_expected.to be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' }
277+
end
278+
279+
describe service('nginx') do
280+
it { is_expected.to be_running }
281+
end
282+
283+
describe port(80) do
284+
it { is_expected.to be_listening }
285+
end
286+
287+
describe file('/tmp/nginx.sock') do
288+
it { is_expected.to be_file }
289+
end
290+
291+
it 'answers to www.puppetlabs.com and responds with "Hello from www"' do
292+
shell('/usr/bin/curl --unix-socket /tmp/nginx.sock http://www.puppetlabs.com') do |r|
293+
expect(r.stdout).to eq("Hello from www\n")
294+
end
295+
end
296+
297+
it 'answers to www.puppetlabs.com without error' do
298+
shell('/usr/bin/curl --unix-socket /tmp/nginx.sock --fail http://www.puppetlabs.com') do |r|
299+
expect(r.exit_code).to be_zero
300+
end
301+
end
302+
end
250303
end

templates/server/server_ssl_header.erb

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ server {
99
<%- else -%>
1010
listen <%= @listen_ip %>:<%= @ssl_port %> <% if @ssl_listen_option %>ssl<% end %><% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_options %> <%= @listen_options %><% end %>;
1111
<%- end -%>
12+
<%- if @listen_unix_socket_enable -%>
13+
<%- if @listen_unix_socket.is_a?(Array) then -%>
14+
<%- @listen_unix_socket.each do |unix_socket| -%>
15+
listen unix:<%= unix_socket %> <% if @ssl_listen_option %>ssl<% end %><% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_unix_socket_options %> <%= @listen_unix_socket_options %><% end %>;
16+
<%- end -%>
17+
<%- else -%>
18+
listen unix:<%= @listen_unix_socket %> <% if @ssl_listen_option %>ssl<% end %><% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_unix_socket_options %> <%= @listen_unix_socket_options %><% end %>;
19+
<%- end -%>
20+
<%- end -%>
1221
<%= scope.function_template(["nginx/server/server_ssl_ipv6_listen.erb"]) %>
1322
<%- if @rewrite_www_to_non_www -%>
1423
server_name www.<%= s.gsub(/^www\./, '') %>;
@@ -32,6 +41,15 @@ server {
3241
<%- else -%>
3342
listen <%= @listen_ip %>:<%= @ssl_port %> <% if @ssl_listen_option %>ssl<% end %><% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_options %> <%= @listen_options %><% end %>;
3443
<%- end -%>
44+
<%- if @listen_unix_socket_enable -%>
45+
<%- if @listen_unix_socket.is_a?(Array) then -%>
46+
<%- @listen_unix_socket.each do |unix_socket| -%>
47+
listen unix:<%= unix_socket %> <% if @ssl_listen_option %>ssl<% end %><% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_unix_socket_options %> <%= @listen_unix_socket_options %><% end %>;
48+
<%- end -%>
49+
<%- else -%>
50+
listen unix:<%= @listen_unix_socket %> <% if @ssl_listen_option %>ssl<% end %><% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_unix_socket_options %> <%= @listen_unix_socket_options %><% end %>;
51+
<%- end -%>
52+
<%- end -%>
3553
<%= scope.function_template(["nginx/server/server_ssl_ipv6_listen.erb"]) %>
3654
<%- if @rewrite_www_to_non_www -%>
3755
server_name <%= @server_name.join(" ").gsub(/(^| )(www\.)?(?=[a-z0-9])/, '') %>;

0 commit comments

Comments
 (0)