vhost_ssl_header.erb 5.7 KB

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