vhost_header.erb 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
  8. <%- end -%>
  9. <%- else -%>
  10. listen <%= @listen_ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
  11. <%- 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 @listen_unix_socket_options %> <%= @listen_unix_socket_options %><% end %>;
  16. <%- end -%>
  17. <%- else -%>
  18. listen unix:<%= @listen_unix_socket %><% if @listen_unix_socket_options %> <%= @listen_unix_socket_options %><% end %>;
  19. <%- end -%>
  20. <%- end -%>
  21. <%# check to see if ipv6 support exists in the kernel before applying -%>
  22. <%- if @ipv6_enable && (defined? @ipaddress6) -%>
  23. <%- if @ipv6_listen_ip.is_a?(Array) then -%>
  24. <%- @ipv6_listen_ip.each do |ipv6| -%>
  25. listen [<%= ipv6 %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
  26. <%- end -%>
  27. <%- else -%>
  28. listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
  29. <%- end -%>
  30. <%- end -%>
  31. server_name www.<%= s.gsub(/^www\./, '') %>;
  32. return 301 http://<%= s.gsub(/^www\./, '') %>$request_uri;
  33. }
  34. <% end -%>
  35. <% end -%>
  36. server {
  37. <%- if @listen_ip.is_a?(Array) then -%>
  38. <%- @listen_ip.each do |ip| -%>
  39. listen <%= ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
  40. <%- end -%>
  41. <%- else -%>
  42. listen <%= @listen_ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
  43. <%- 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 @listen_unix_socket_options %> <%= @listen_unix_socket_options %><% end %>;
  48. <%- end -%>
  49. <%- else -%>
  50. listen unix:<%= @listen_unix_socket %><% if @listen_unix_socket_options %> <%= @listen_unix_socket_options %><% end %>;
  51. <%- end -%>
  52. <%- end -%>
  53. <%# check to see if ipv6 support exists in the kernel before applying -%>
  54. <%- if @ipv6_enable && (defined? @ipaddress6) -%>
  55. <%- if @ipv6_listen_ip.is_a?(Array) then -%>
  56. <%- @ipv6_listen_ip.each do |ipv6| -%>
  57. listen [<%= ipv6 %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
  58. <%- end -%>
  59. <%- else -%>
  60. listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
  61. <%- end -%>
  62. <%- end -%>
  63. server_name <%= @rewrite_www_to_non_www ? @server_name.join(" ").gsub(/(^| )(www\.)?(?=[a-z0-9])/, '') : @server_name.join(" ") %>;
  64. <%- if instance_variables.any? { |iv| iv.to_s.include? 'auth_basic' } -%>
  65. <%- if defined? @auth_basic -%>
  66. auth_basic "<%= @auth_basic %>";
  67. <%- end -%>
  68. <%- if defined? @auth_basic_user_file -%>
  69. auth_basic_user_file <%= @auth_basic_user_file %>;
  70. <%- end -%>
  71. <% end -%>
  72. <% if instance_variables.any? { |iv| iv.to_s.include? 'client_' } -%>
  73. <%- if defined? @client_body_timeout -%>
  74. client_body_timeout <%= @client_body_timeout %>;
  75. <%- end -%>
  76. <%- if defined? @client_header_timeout -%>
  77. client_header_timeout <%= @client_header_timeout %>;
  78. <%- end -%>
  79. <%- if defined? @client_max_body_size -%>
  80. client_max_body_size <%= @client_max_body_size %>;
  81. <%- end -%>
  82. <% end -%>
  83. <% if defined? @gzip_types -%>
  84. gzip_types <%= @gzip_types %>;
  85. <% end -%>
  86. <%# make sure that allow comes before deny by forcing the allow key (if it -%>
  87. <%# exists) to be first in the output order. The hash keys also need to be -%>
  88. <%# sorted so that the ordering is stable. -%>
  89. <% if @vhost_cfg_prepend -%>
  90. <%- @vhost_cfg_prepend.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%>
  91. <%- if value.is_a?(Hash) -%>
  92. <%- value.sort_by {|k,v| k}.each do |subkey,subvalue| -%>
  93. <%- Array(subvalue).each do |asubvalue| -%>
  94. <%= key %> <%= subkey %> <%= asubvalue %>;
  95. <%- end -%>
  96. <%- end -%>
  97. <%- else -%>
  98. <%- Array(value).each do |asubvalue| -%>
  99. <%= key %> <%= asubvalue %>;
  100. <%- end -%>
  101. <%- end -%>
  102. <%- end -%>
  103. <% end -%>
  104. <% Array(@raw_prepend).each do |line| -%>
  105. <%= line %>
  106. <% end %>
  107. <% if @root -%>
  108. root <%= @root %>;
  109. <% end -%>
  110. <% if @passenger_cgi_param -%>
  111. <%- @passenger_cgi_param.keys.sort.each do |key| -%>
  112. passenger_set_cgi_param <%= key %> <%= @passenger_cgi_param[key] %>;
  113. <%- end -%>
  114. <% end -%>
  115. <% if @passenger_set_header -%>
  116. <%- @passenger_set_header.keys.sort.each do |key| -%>
  117. passenger_set_header <%= key %> <%= @passenger_set_header[key] %>;
  118. <%- end -%>
  119. <% end -%>
  120. <% if @passenger_env_var -%>
  121. <%- @passenger_env_var.keys.sort.each do |key| -%>
  122. passenger_env_var <%= key %> <%= @passenger_env_var[key] %>;
  123. <%- end -%>
  124. <% end -%>
  125. <% if Array(@resolver).count > 0 -%>
  126. resolver <% Array(@resolver).each do |r| %> <%= r %><% end %>;
  127. <% end -%>
  128. <% if @add_header -%>
  129. <%- @add_header.keys.sort.each do |key| -%>
  130. add_header <%= key %> <%= @add_header[key] %>;
  131. <%- end -%>
  132. <% end -%>
  133. <% if @maintenance -%>
  134. <%= @maintenance_value %>;
  135. <% end -%>
  136. <% if @rewrite_to_https -%>
  137. if ($ssl_protocol = "") {
  138. return 301 https://$host<% if @ssl_port.to_i != 443 %>:<%= @ssl_port %><% end %>$request_uri;
  139. }
  140. <% end -%>
  141. <% if @index_files.count > 0 -%>
  142. index <% Array(@index_files).each do |i| %> <%= i %><% end %>;
  143. <% end -%>
  144. <% if defined? @log_by_lua -%>
  145. log_by_lua '<%= @log_by_lua %>';
  146. <% end -%>
  147. <% if defined? @log_by_lua_file -%>
  148. log_by_lua_file "<%= @log_by_lua_file %>";
  149. <% end -%>
  150. access_log <%= @access_log_real %>;
  151. error_log <%= @error_log_real %>;