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.

150 line
4.0KB

  1. ======
  2. apache
  3. ======
  4. Formulas to set up and configure the Apache HTTP server.
  5. This Formula uses the concepts of ``directive`` and ``container`` in pillars
  6. * ``directive`` is an httpd directive https://httpd.apache.org/docs/2.4/en/mod/directives.html
  7. * ``container`` is what described the `configuration sections` https://httpd.apache.org/docs/2.4/en/sections.html
  8. see examples below for more explanation
  9. Also it includes and enforce some hardening rules to prevent security issues
  10. See `<Hardening.md>`_ and `<apache/hardening-values.yaml>`_.
  11. .. note::
  12. See the full `Salt Formulas installation and usage instructions
  13. <http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html>`_.
  14. Available states
  15. ================
  16. .. contents::
  17. :local:
  18. ``apache``
  19. ----------
  20. Installs the Apache package and starts the service.
  21. ``apache.config-ng``
  22. -----------------
  23. Configures apache server.
  24. The configuration is done by merging the pillar content with defaults
  25. present in the state `<apache/defaults/RedHat/defaults-apache-2.4.yaml>`_
  26. .. code:: yaml
  27. apache:
  28. server_apache_config:
  29. directives:
  30. - Timeout: 5
  31. containers:
  32. IfModule:
  33. -
  34. item: 'mime_module'
  35. directives:
  36. - AddType: 'application/x-font-ttf ttc ttf'
  37. - AddType: 'application/x-font-opentype otf'
  38. - AddType: 'application/x-font-woff woff2'
  39. ``apache.modules-ng``
  40. ------------------
  41. Enables and disables Apache modules.
  42. ``apache.vhosts.vhost-ng``
  43. --------------------------
  44. Configures Apache name-based virtual hosts and creates virtual host directories using data from Pillar.
  45. All necessary data must be provided in the pillar
  46. Exceptions are :
  47. * ``CustomLog`` default is ``/path/apache/log/ServerName-access.log combined``
  48. * if ``Logformat`` is defined in pillar, ``CustomLog`` is enforced to ``/path/apache/log/ServerName-access.log Logformat``
  49. * ``ErrorLog`` is enforced to ``/path/apache/log/ServerName-error.log``
  50. Example Pillar:
  51. Create two vhosts ``example.com.conf`` and ``test.example.com.conf``
  52. .. code:: yaml
  53. apache:
  54. VirtualHost:
  55. example.com: # <-- this is an id decalaration used in salt and default ServerName
  56. item: '*:80'
  57. directives:
  58. - RewriteEngine: 'on'
  59. - Header: 'set Access-Control-Allow-Methods GET,PUT,POST,DELETE,OPTIONS'
  60. containers:
  61. Location:
  62. item: '/test.html'
  63. directives:
  64. - Require: 'all granted'
  65. site_id_declaration:
  66. item: '10.10.1.1:8080'
  67. directives:
  68. - ServerName: 'test.example.com'
  69. - LogFormat: '"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %{ms}T"'
  70. Files produced by these pillars :
  71. ``example.com.conf``
  72. .. code:: bash
  73. <VirtualHost *:80>
  74. ServerName example.com
  75. CustomLog /var/log/httpd/example.com-access.log combined
  76. ErrorLog /var/log/httpd/example.com-error.log
  77. RewriteEngine on
  78. Header set Access-Control-Allow-Methods GET,PUT,POST,DELETE,OPTIONS
  79. <Location /test.html>
  80. Require all granted
  81. </Location>
  82. </VirtualHost>
  83. ``test.example.com.conf``
  84. .. code:: bash
  85. <VirtualHost 10.10.1.1:8080>
  86. ServerName test.example.com
  87. CustomLog /var/log/httpd/test.example.com-access.log "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %{ms}T"
  88. ErrorLog /var/log/httpd/test.example.com-error.log
  89. </VirtualHost>
  90. this will delete ``test.example.com.conf``
  91. .. code:: yaml
  92. apache:
  93. VirtualHost:
  94. test.example.com:
  95. item: '10.10.1.1:8080'
  96. absent: True # <-- delete test.example.com.conf
  97. directives:
  98. - ServerName: 'test.example.com'
  99. ``apache.uninstall``
  100. ----------
  101. Stops the Apache service and uninstalls the package.