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.

135 lines
5.6KB

  1. {# Define default values here so the template below can just focus on layout #}
  2. {%- set sitename = site.get('ServerName', id) -%}
  3. {%- set vals = {
  4. 'interfaces': site.get('interface', '*').split(),
  5. 'port': site.get('port', '80'),
  6. 'ServerName': sitename,
  7. 'ServerAlias': site.get('ServerAlias', ''),
  8. 'ServerAdmin': site.get('ServerAdmin', 'webmaster@{0}'.format(sitename)),
  9. 'DirectoryIndex': site.get('DirectoryIndex'),
  10. 'UseCanonicalName': site.get('UseCanonicalName'),
  11. 'AllowEncodedSlashes': site.get('AllowEncodedSlashes', 'Off'),
  12. 'LogLevel': site.get('LogLevel', 'warn'),
  13. 'ErrorLog': site.get('ErrorLog', '{0}/{1}-error.log'.format(map.logdir, sitename)),
  14. 'LogFormat': site.get('LogFormat', '"%h %l %u %t \\\"%r\\\" %>s"'),
  15. 'CustomLog': site.get('CustomLog', '{0}/{1}-access.log'.format(map.logdir, sitename)),
  16. 'DocumentRoot': site.get('DocumentRoot', '{0}/{1}'.format(map.wwwdir, sitename)),
  17. 'VirtualDocumentRoot': site.get('VirtualDocumentRoot'),
  18. 'Timeout': site.get('Timeout'),
  19. 'LimitRequestFields': site.get('LimitRequestFields'),
  20. 'Directory_default': '{0}/{1}'.format(map.wwwdir, sitename),
  21. 'Directory': {
  22. 'Options': '-Indexes +FollowSymLinks',
  23. 'Order': 'allow,deny',
  24. 'Allow': 'from all',
  25. 'Require': 'all granted',
  26. 'AllowOverride': 'None',
  27. },
  28. 'Location': {
  29. 'Order': 'allow,deny',
  30. 'Allow': 'from all',
  31. 'Require': 'all granted',
  32. },
  33. } -%}
  34. <VirtualHost {% for intf in vals.interfaces %} {{intf}}:{{ vals.port }}{% endfor -%}>
  35. ServerName {{ vals.ServerName }}
  36. {% if site.get('ServerAlias') != False %}ServerAlias {{ vals.ServerAlias }}{% endif %}
  37. {% if site.get('ServerAdmin') != False %}ServerAdmin {{ vals.ServerAdmin }}{% endif %}
  38. {% if site.get('DirectoryIndex') -%}DirectoryIndex {{ vals.DirectoryIndex }}{% endif %}
  39. {% if site.get('UseCanonicalName') -%}UseCanonicalName {{ vals.UseCanonicalName }}{% endif %}
  40. {% if site.get('AllowEncodedSlashes') != False -%}AllowEncodedSlashes {{ vals.AllowEncodedSlashes }}{% endif %}
  41. {% if site.get('LogLevel') != False -%}LogLevel {{ vals.LogLevel }}{% endif %}
  42. {% if site.get('ErrorLog') != False -%}ErrorLog {{ vals.ErrorLog }}{% endif %}
  43. {% if site.get('LogFormat') != False -%}LogFormat {{ vals.LogFormat }}{% endif %}
  44. {% if site.get('CustomLog') != False -%}LogFormat {{ vals.LogFormat }} {{ sitename }}
  45. CustomLog {{ vals.CustomLog }} {{ sitename }}{% endif %}
  46. {% if site.get('DocumentRoot') != False -%}DocumentRoot {{ vals.DocumentRoot }}{% endif %}
  47. {% if site.get('VirtualDocumentRoot') -%}VirtualDocumentRoot {{ vals.VirtualDocumentRoot }}{% endif %}
  48. {% if site.get('Timeout') != False and site.get('Timeout') != None %}Timeout {{ vals.Timeout }}{% endif %}
  49. {% if site.get('LimitRequestFields') %}LimitRequestFields {{ vals.LimitRequestFields }}{% endif %}
  50. {% if site.get('SSLCertificateFile') %}SSLEngine on
  51. SSLCertificateFile {{ site.SSLCertificateFile }}
  52. {% if site.get('SSLCertificateKeyFile') %}SSLCertificateKeyFile {{ site.SSLCertificateKeyFile }}{% endif %}
  53. {% if site.get('SSLCertificateChainFile') %}SSLCertificateChainFile {{ site.SSLCertificateChainFile}}{% endif %}
  54. {% endif %}
  55. {% if site.get('Rewrite') %}RewriteEngine on
  56. {{ site.Rewrite }}
  57. {% endif %}
  58. {%- for loc, path in site.get('Alias', {}).items() %}
  59. Alias {{ loc }} {{ path }}
  60. {%- endfor %}
  61. {%- for path, dir in site.get('Directory', {}).items() -%}
  62. {%- set dvals = {
  63. 'Options': dir.get('Options', vals.Directory.Options),
  64. 'Order': dir.get('Order', vals.Directory.Order),
  65. 'Allow': dir.get('Allow', vals.Directory.Allow),
  66. 'Require': dir.get('Require', vals.Directory.Require),
  67. 'AllowOverride': dir.get('AllowOverride', vals.Directory.AllowOverride),
  68. 'Dav': dir.get('Dav', False),
  69. } %}
  70. {%- if path == 'default' %}{% set path = vals.Directory_default %}{% endif %}
  71. <Directory "{{ path }}">
  72. {% if dvals.get('Options') != False %}Options {{ dvals.Options }}{% endif %}
  73. {% if map.version == '2.4' %}
  74. {% if dvals.get('Require') != False %}Require {{dvals.Require}}{% endif %}
  75. {% else %}
  76. {% if dvals.get('Order') != False %}Order {{ dvals.Order }}{% endif %}
  77. {% if dvals.get('Allow') != False %}Allow {{ dvals.Allow }}{% endif %}
  78. {% endif %}
  79. {% if dvals.get('AllowOverride') != False %}AllowOverride {{ dvals.AllowOverride }}{% endif %}
  80. {% if dvals.get('Dav') != False %}Dav On{% endif %}
  81. {% if dir.get('Formula_Append') %}
  82. {{ dir.Formula_Append|indent(8) }}
  83. {% endif %}
  84. </Directory>
  85. {%- endfor %}
  86. {%- for path, loc in site.get('Location', {}).items() %}
  87. {%- set lvals = {
  88. 'Order': loc.get('Order', vals.Location.Order),
  89. 'Allow': loc.get('Allow', vals.Location.Allow),
  90. 'Require': loc.get('Require', vals.Location.Require),
  91. 'Dav': loc.get('Dav', False),
  92. } %}
  93. <Location "{{ path }}">
  94. {% if map.version == '2.4' %}
  95. {%- if lvals.get('Require') != False %}Require {{lvals.Require}}{% endif %}
  96. {% else %}
  97. {%- if lvals.get('Order') != False %}Order {{ lvals.Order }}{% endif %}
  98. {%- if lvals.get('Allow') != False %}Allow {{ lvals.Allow }}{% endif %}
  99. {% endif %}
  100. {%- if lvals.get('Dav') != False %}Dav On{% endif %}
  101. {%- if loc.get('Formula_Append') %}
  102. {{ loc.Formula_Append|indent(8) }}
  103. {% endif %}
  104. </Location>
  105. {% endfor %}
  106. {%- if site.get('Formula_Append') %}
  107. {{ site.Formula_Append|indent(4) }}
  108. {% endif %}
  109. </VirtualHost>