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.

133 lines
5.5KB

  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', 'www.{0}'.format(sitename)),
  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('CustomLog') != False -%}CustomLog {{ vals.CustomLog }} {{ vals.LogFormat }}{% endif %}
  44. {% if site.get('DocumentRoot') != False -%}DocumentRoot {{ vals.DocumentRoot }}{% endif %}
  45. {% if site.get('VirtualDocumentRoot') -%}VirtualDocumentRoot {{ vals.VirtualDocumentRoot }}{% endif %}
  46. {% if site.get('Timeout') != False and site.get('Timeout') != None %}Timeout {{ vals.Timeout }}{% endif %}
  47. {% if site.get('LimitRequestFields') %}LimitRequestFields {{ vals.LimitRequestFields }}{% endif %}
  48. {% if site.get('SSLCertificateFile') %}SSLEngine on
  49. SSLCertificateFile {{ site.SSLCertificateFile }}
  50. {% if site.get('SSLCertificateKeyFile') %}SSLCertificateKeyFile {{ site.SSLCertificateKeyFile }}{% endif %}
  51. {% if site.get('SSLCertificateChainFile') %}SSLCertificateChainFile {{ site.SSLCertificateChainFile}}{% endif %}
  52. {% endif %}
  53. {% if site.get('Rewrite') %}RewriteEngine on
  54. {{ site.Rewrite }}
  55. {% endif %}
  56. {%- for loc, path in site.get('Alias', {}).items() %}
  57. Alias {{ loc }} {{ path }}
  58. {%- endfor %}
  59. {%- for path, dir in site.get('Directory', {}).items() -%}
  60. {%- set dvals = {
  61. 'Options': dir.get('Options', vals.Directory.Options),
  62. 'Order': dir.get('Order', vals.Directory.Order),
  63. 'Allow': dir.get('Allow', vals.Directory.Allow),
  64. 'Require': dir.get('Require', vals.Directory.Require),
  65. 'AllowOverride': dir.get('AllowOverride', vals.Directory.AllowOverride),
  66. 'Dav': dir.get('Dav', False),
  67. } %}
  68. {%- if path == 'default' %}{% set path = vals.Directory_default %}{% endif %}
  69. <Directory "{{ path }}">
  70. {% if dvals.get('Options') != False %}Options {{ dvals.Options }}{% endif %}
  71. {% if map.use_require %}
  72. {% if dvals.get('Require') != False %}Require {{dvals.Require}}{% endif %}
  73. {% else %}
  74. {% if dvals.get('Order') != False %}Order {{ dvals.Order }}{% endif %}
  75. {% if dvals.get('Allow') != False %}Allow {{ dvals.Allow }}{% endif %}
  76. {% endif %}
  77. {% if dvals.get('AllowOverride') != False %}AllowOverride {{ dvals.AllowOverride }}{% endif %}
  78. {% if dvals.get('Dav') != False %}Dav On{% endif %}
  79. {% if dir.get('Formula_Append') %}
  80. {{ dir.Formula_Append|indent(8) }}
  81. {% endif %}
  82. </Directory>
  83. {%- endfor %}
  84. {%- for path, loc in site.get('Location', {}).items() %}
  85. {%- set lvals = {
  86. 'Order': loc.get('Order', vals.Location.Order),
  87. 'Allow': loc.get('Allow', vals.Location.Allow),
  88. 'Require': loc.get('Require', vals.Location.Require),
  89. 'Dav': loc.get('Dav', False),
  90. } %}
  91. <Location "{{ path }}">
  92. {% if map.use_require %}
  93. {%- if lvals.get('Require') != False %}Require {{lvals.Require}}{% endif %}
  94. {% else %}
  95. {%- if lvals.get('Order') != False %}Order {{ lvals.Order }}{% endif %}
  96. {%- if lvals.get('Allow') != False %}Allow {{ lvals.Allow }}{% endif %}
  97. {% endif %}
  98. {%- if lvals.get('Dav') != False %}Dav On{% endif %}
  99. {%- if loc.get('Formula_Append') %}
  100. {{ loc.Formula_Append|indent(8) }}
  101. {% endif %}
  102. </Location>
  103. {% endfor %}
  104. {%- if site.get('Formula_Append') %}
  105. {{ site.Formula_Append|indent(4) }}
  106. {% endif %}
  107. </VirtualHost>