vhost_ssl_header.erb 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # MANAGED BY PUPPET
  2. <% if @rewrite_www_to_non_www -%>
  3. <%- @server_name.each do |s| -%>
  4. server {
  5. <%- if @listen_ip.is_a?(Array) then -%>
  6. <%- @listen_ip.each do |ip| -%>
  7. 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 %>;
  8. <%- end -%>
  9. <%- else -%>
  10. 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 %>;
  11. <%- end -%>
  12. <%# check to see if ipv6 support exists in the kernel before applying -%>
  13. <%- if @ipv6_enable && (defined? @ipaddress6) -%>
  14. <%- if @ipv6_listen_ip.is_a?(Array) then -%>
  15. <%- @ipv6_listen_ip.each do |ipv6| -%>
  16. listen [<%= ipv6 %>]:<%= @ssl_port %> ssl<% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
  17. <%- end -%>
  18. <%- else -%>
  19. listen [<%= @ipv6_listen_ip %>]:<%= @ssl_port %> ssl<% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
  20. <%- end -%>
  21. <%- end -%>
  22. server_name www.<%= s.gsub(/^www\./, '') %>;
  23. return 301 https://<%= s.gsub(/^www\./, '') %>$request_uri;
  24. <%= scope.function_template(["nginx/vhost/vhost_ssl_settings.erb"]) %>
  25. }
  26. <% end -%>
  27. <% end -%>
  28. server {
  29. <%- if @listen_ip.is_a?(Array) then -%>
  30. <%- @listen_ip.each do |ip| -%>
  31. 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 %>;
  32. <%- end -%>
  33. <%- else -%>
  34. 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 %>;
  35. <%- end -%>
  36. <%# check to see if ipv6 support exists in the kernel before applying -%>
  37. <%- if @ipv6_enable && (defined? @ipaddress6) -%>
  38. <%- if @ipv6_listen_ip.is_a?(Array) then -%>
  39. <%- @ipv6_listen_ip.each do |ipv6| -%>
  40. listen [<%= ipv6 %>]:<%= @ssl_port %> ssl<% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
  41. <%- end -%>
  42. <%- else -%>
  43. listen [<%= @ipv6_listen_ip %>]:<%= @ssl_port %> ssl<% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
  44. <%- end -%>
  45. <%- end -%>
  46. server_name <%= @rewrite_www_to_non_www ? @server_name.join(" ").gsub(/(^| )(www\.)?(?=[a-z0-9])/, '') : @server_name.join(" ") %>;
  47. <%= scope.function_template(["nginx/vhost/vhost_ssl_settings.erb"]) %>
  48. <% if @maintenance -%>
  49. <%= @maintenance_value %>;
  50. <% end -%>
  51. <% if Array(@resolver).count > 0 -%>
  52. resolver <% Array(@resolver).each do |r| %> <%= r %><% end %>;
  53. <% end -%>
  54. <%- if instance_variables.any? { |iv| iv.to_s.include? 'auth_basic' } -%>
  55. <% if defined? @auth_basic -%>
  56. auth_basic "<%= @auth_basic %>";
  57. <% end -%>
  58. <% if defined? @auth_basic_user_file -%>
  59. auth_basic_user_file "<%= @auth_basic_user_file %>";
  60. <% end -%>
  61. <%- end -%>
  62. <%- if instance_variables.any? { |iv| iv.to_s.include? 'client_' } -%>
  63. <%- if defined? @client_body_timeout -%>
  64. client_body_timeout <%= @client_body_timeout %>;
  65. <%- end -%>
  66. <%- if defined? @client_header_timeout -%>
  67. client_header_timeout <%= @client_header_timeout %>;
  68. <%- end -%>
  69. <%- if defined? @client_max_body_size -%>
  70. client_max_body_size <%= @client_max_body_size %>;
  71. <%- end -%>
  72. <% end -%>
  73. <% if defined? @gzip_types -%>
  74. gzip_types <%= @gzip_types %>;
  75. <% end -%>
  76. <% if @index_files.count > 0 -%>
  77. index <% Array(@index_files).each do |i| %> <%= i %><% end %>;
  78. <% end -%>
  79. access_log <%= @ssl_access_log_real %>;
  80. error_log <%= @ssl_error_log_real %>;
  81. <% if @vhost_cfg_prepend -%>
  82. <%- @vhost_cfg_prepend.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%>
  83. <%- if value.is_a?(Hash) -%>
  84. <%- value.sort_by {|k,v| k}.each do |subkey,subvalue| -%>
  85. <%- Array(subvalue).each do |asubvalue| -%>
  86. <%= key %> <%= subkey %> <%= asubvalue %>;
  87. <%- end -%>
  88. <%- end -%>
  89. <%- else -%>
  90. <%- Array(value).each do |asubvalue| -%>
  91. <%= key %> <%= asubvalue %>;
  92. <%- end -%>
  93. <%- end -%>
  94. <%- end -%>
  95. <% end -%>
  96. <% if @vhost_cfg_ssl_prepend -%>
  97. <%- @vhost_cfg_ssl_prepend.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%>
  98. <%- if value.is_a?(Hash) -%>
  99. <%- value.sort_by {|k,v| k}.each do |subkey,subvalue| -%>
  100. <%- Array(subvalue).each do |asubvalue| -%>
  101. <%= key %> <%= subkey %> <%= asubvalue %>;
  102. <%- end -%>
  103. <%- end -%>
  104. <%- else -%>
  105. <%- Array(value).each do |asubvalue| -%>
  106. <%= key %> <%= asubvalue %>;
  107. <%- end -%>
  108. <%- end -%>
  109. <%- end -%>
  110. <% end -%>
  111. <% Array(@raw_prepend).each do |line| -%>
  112. <%= line %>
  113. <% end -%>
  114. <% if @root -%>
  115. root <%= @root %>;
  116. <% end -%>
  117. <% Array(@passenger_cgi_param).each do |key,value| -%>
  118. passenger_set_cgi_param <%= key %> <%= value %>;
  119. <% end -%>
  120. <% Array(@passenger_set_header).each do |key,value| -%>
  121. passenger_set_header <%= key %> <%= value %>;
  122. <% end -%>
  123. <% Array(@passenger_env_var).each do |key,value| -%>
  124. passenger_env_var <%= key %> <%= value %>;
  125. <% end -%>
  126. <% if @add_header -%>
  127. <%- @add_header.keys.sort.each do |key| -%>
  128. add_header '<%= key %>' '<%= @add_header[key] %>';
  129. <%- end -%>
  130. <% end -%>