Saltstack Official Apache Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
6.2KB

  1. #
  2. # This file is managed by Salt! Do not edit by hand!
  3. #
  4. {# Define default values here so the template below can just focus on layout #}
  5. {% set sitename = site.get('ServerName', id) -%}
  6. {% set vals = {
  7. 'interfaces': site.get('interface', '*').split(),
  8. 'port': site.get('port', '80'),
  9. 'ServerName': sitename,
  10. 'ServerAlias': site.get('ServerAlias', ''),
  11. 'ServerAdmin': site.get('ServerAdmin', 'webmaster@{0}'.format(sitename)),
  12. 'UseCanonicalName': site.get('UseCanonicalName'),
  13. 'LogLevel': site.get('LogLevel', 'warn'),
  14. 'ErrorLog': site.get('ErrorLog', '{0}/{1}-error.log'.format(map.logdir, sitename)),
  15. 'LogFormat': site.get('LogFormat', '"%a %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\""'),
  16. 'CustomLog': site.get('CustomLog', '{0}/{1}-access.log'.format(map.logdir, sitename)),
  17. 'ProxyRequests': site.get('ProxyRequests', 'Off'),
  18. 'ProxyPreserveHost': site.get('ProxyPreserveHost', 'On'),
  19. 'ProxyRoute': site.get('ProxyRoute', {}),
  20. 'Location': {
  21. 'Order': 'allow,deny',
  22. 'Allow': 'from all',
  23. 'Require': 'all granted',
  24. },
  25. 'LocationMatch': {
  26. 'Order': 'allow,deny',
  27. 'Allow': 'from all',
  28. 'Require': 'all granted',
  29. },
  30. } -%}
  31. <VirtualHost {%- for intf in vals.interfaces %} {{ intf }}:{{ vals.port }}{% endfor -%}>
  32. ServerName {{ vals.ServerName }}
  33. {% if site.get('ServerAlias') != False %}ServerAlias {{ vals.ServerAlias }}{% endif %}
  34. {% if site.get('ServerAdmin') != False %}ServerAdmin {{ vals.ServerAdmin }}{% endif %}
  35. {% if site.get('UseCanonicalName') %}UseCanonicalName {{ vals.UseCanonicalName }}{% endif %}
  36. {% if site.get('LogLevel') != False %}LogLevel {{ vals.LogLevel }}{% endif %}
  37. {% if site.get('ErrorLog') != False %}ErrorLog {{ vals.ErrorLog }}{% endif %}
  38. {% if site.get('LogFormat') != False -%}LogFormat {{ vals.LogFormat }}{% endif %}
  39. {% if site.get('CustomLog') != False -%}LogFormat {{ vals.LogFormat }} {{ sitename }}
  40. CustomLog {{ vals.CustomLog }} {{ sitename }}{% endif %}
  41. {% if site.get('SSLCertificateFile') %}SSLEngine on
  42. SSLCertificateFile {{ site.SSLCertificateFile }}
  43. {% if site.get('SSLCertificateKeyFile') %}SSLCertificateKeyFile {{ site.SSLCertificateKeyFile }}{% endif %}
  44. {% if site.get('SSLCertificateChainFile') %}SSLCertificateChainFile {{ site.SSLCertificateChainFile }}{% endif %}
  45. {%- endif %}
  46. {% if site.get('Rewrite') %}RewriteEngine on
  47. {{ site.Rewrite|indent(4) }}
  48. {%- endif %}
  49. {% if site.get('SSLProxyEngine') %}SSLProxyEngine {{ site.SSLProxyEngine }}{% endif %}
  50. ProxyRequests {{ vals.ProxyRequests }}
  51. ProxyPreserveHost {{ vals.ProxyPreserveHost }}
  52. {% if site.get('ProxyErrorOverride') %}ProxyErrorOverride {{ site.ProxyErrorOverride }} {% endif %}
  53. {% if site.get('ProxyErrorDir') %}ProxyPass /{{ site.ProxyErrorDir }}/ ! {% endif %}
  54. {%- for proxy, proxyargs in vals.ProxyRoute|dictsort|reverse %}
  55. {%- set proxyvals = {
  56. 'ProxyPassSource': proxyargs.get('ProxyPassSource', '/'),
  57. 'ProxyPassTarget': proxyargs.get('ProxyPassTarget', 'https://{0}'.format(sitename)),
  58. 'ProxyPassTargetOptions': proxyargs.get('ProxyPassTargetOptions', ''),
  59. 'ProxyPassReverseSource': proxyargs.get('ProxyPassReverseSource', '/'),
  60. 'ProxyPassReverseTarget': proxyargs.get('ProxyPassReverseTarget', proxyargs.get('ProxyPassTarget', 'https://{0}'.format(sitename))),
  61. } %}
  62. ######### {{proxy}} #########
  63. ProxyPass {{ proxyvals.ProxyPassSource }} {{ proxyvals.ProxyPassTarget }} {{ proxyvals.ProxyPassTargetOptions }}
  64. ProxyPassReverse {{ proxyvals.ProxyPassReverseSource }} {{ proxyvals.ProxyPassReverseTarget }}
  65. {% endfor %}
  66. {%- for path, loc in site.get('Location', {}).items() %}
  67. {%- set lvals = {
  68. 'Order': loc.get('Order', vals.Location.Order),
  69. 'Allow': loc.get('Allow', vals.Location.Allow),
  70. 'Require': loc.get('Require', vals.Location.Require),
  71. 'Dav': loc.get('Dav', False),
  72. } %}
  73. <Location "{{ path }}">
  74. {%- if map.version == '2.4' %}
  75. {% if lvals.get('Require') != False %}Require {{ lvals.Require }}{% endif %}
  76. {%- else %}
  77. {% if lvals.get('Order') != False %}Order {{ lvals.Order }}{% endif %}
  78. {% if lvals.get('Allow') != False %}Allow {{ lvals.Allow }}{% endif %}
  79. {%- endif %}
  80. {% if loc.get('Formula_Append') %} {{ loc.Formula_Append|indent(8) }} {% endif %}
  81. </Location>
  82. {% endfor %}
  83. {%- for regpath, locmat in site.get('LocationMatch', {}).items() %}
  84. {%- set lmvals = {
  85. 'Order': locmat.get('Order', vals.LocationMatch.Order),
  86. 'Allow': locmat.get('Allow', vals.LocationMatch.Allow),
  87. 'Require': locmat.get('Require', vals.LocationMatch.Require),
  88. 'Dav': locmat.get('Dav', False),
  89. } %}
  90. <LocationMatch "{{ regpath }}">
  91. {%- if map.version == '2.4' %}
  92. {% if lmvals.get('Require') != False %}Require {{ lmvals.Require }}{% endif %}
  93. {%- else %}
  94. {% if lmvals.get('Order') != False %}Order {{ lmvals.Order }}{% endif %}
  95. {% if lmvals.get('Allow') != False %}Allow {{ lmvals.Allow }}{% endif %}
  96. {%- endif %}
  97. {% if locmat.get('Formula_Append') %} {{ locmat.Formula_Append|indent(8) }} {% endif %}
  98. </LocationMatch>
  99. {% endfor %}
  100. {%- for proxypath, prox in site.get('Proxy_control', {}).items() %}
  101. {%- set proxvals = {
  102. 'AllowAll': prox.get('AllowAll', vals.AllowAll),
  103. 'AllowCountry': prox.get('AllowCountry', vals.AllowCountry),
  104. 'AllowIP': prox.get('AllowIP', vals.AllowIP),
  105. } %}
  106. <Proxy "{{ proxypath }}">
  107. {%- if proxvals.get('AllowAll') != False %}
  108. Require all granted
  109. {%- else %}
  110. {% if proxvals.get('AllowCountry') != False %}{% set country_list = proxvals.get('AllowCountry', {}) %}GeoIPEnable On
  111. {% for every_country in country_list %}SetEnvIf GEOIP_COUNTRY_CODE {{ every_country }} AllowCountry
  112. {% endfor %}Require env AllowCountry {% endif %}
  113. {% if proxvals.get('AllowIP') is defined %}{% set ip_list = proxvals.get('AllowIP', {}) %}
  114. Require ip {% for every_ip in ip_list %}{{ every_ip }} {% endfor %} {% endif %}
  115. {%- endif %}
  116. </Proxy>
  117. {%- endfor %}
  118. {%- if site.get('Formula_Append') %}
  119. {{ site.Formula_Append|indent(4) }}
  120. {%- endif %}
  121. </VirtualHost>