vhost_header.erb 5.8 KB

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