Saltstack Official Apache Formula
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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