Support vhosts that listen on alternative ports

- Include the port in the listen directive
- Add an optional $server_name parameter to nginx::resource::vhost so
  server_name doesn't have to match the resource's name.  This allows
  the creation of multiple vhosts with the same server_name that listen
  on different ports.
This commit is contained in:
Christian G. Warden 2012-01-11 10:43:18 -08:00
parent 84257dcb9b
commit a214b0ff21
4 changed files with 14 additions and 4 deletions

View file

@ -3,6 +3,7 @@
# This definition creates a virtual host
#
# Parameters:
# [*server_name*] - Server name (value to match in Host: header). Defaults to the resource's name.
# [*ensure*] - Enables or disables the specified vhost (present|absent)
# [*listen_ip*] - Default IP Address for NGINX to listen with this vHost on. Defaults to all interfaces (*)
# [*listen_port*] - Default IP Port for NGINX to listen with this vHost on. Defaults to TCP 80
@ -31,6 +32,7 @@
# ssl_key => '/tmp/server.pem',
# }
define nginx::resource::vhost(
$server_name = $name,
$ensure = 'enable',
$listen_ip = '*',
$listen_port = '80',

View file

@ -1,6 +1,6 @@
server {
listen <%= listen_ip %>;
listen <%= listen_ip %>:<%= listen_port %>;
<% # check to see if ipv6 support exists in the kernel before applying %>
<% if ipv6_enable == 'true' && (defined? ipaddress6) %>listen [<%= ipv6_listen_ip %>]:<%= ipv6_listen_port %> default ipv6only=on;<% end %>
server_name <%= name %>;
server_name <%= server_name %>;
access_log <%= scope.lookupvar('nginx::params::nx_logdir')%>/<%= name %>.access.log;

View file

@ -1,7 +1,7 @@
server {
listen 443;
<% if ipv6_enable == 'true' && (defined? ipaddress6) %>listen [<%= ipv6_listen_ip %>]:<%= ipv6_listen_port %> default ipv6only=on;<% end %>
server_name <%= name %>;
server_name <%= server_name %>;
ssl on;
ssl_certificate <%= ssl_cert %>;

View file

@ -1,4 +1,4 @@
include nginix
include nginx
nginx::resource::vhost { 'test.local':
ensure => present,
@ -6,3 +6,11 @@ nginx::resource::vhost { 'test.local':
proxy => 'http://proxypass',
}
nginx::resource::vhost { 'test.local:8080':
listen_port => 8080,
server_name => 'test.local',
ensure => present,
ipv6_enable => 'true',
proxy => 'http://proxypass',
}