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.

129 lines
5.2KB

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