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.

400 lines
13KB

  1. {% from "apache/map.jinja" import apache with context %}
  2. #
  3. # This is the main Apache HTTP server configuration file. It contains the
  4. # configuration directives that give the server its instructions.
  5. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
  6. # In particular, see
  7. # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
  8. # for a discussion of each configuration directive.
  9. #
  10. # Do NOT simply read the instructions in here without understanding
  11. # what they do. They're here only as hints or reminders. If you are unsure
  12. # consult the online docs. You have been warned.
  13. #
  14. # Configuration and logfile names: If the filenames you specify for many
  15. # of the server's control files begin with "/" (or "drive:/" for Win32), the
  16. # server will use that explicit path. If the filenames do *not* begin
  17. # with "/", the value of ServerRoot is prepended -- so 'log/access_log'
  18. # with ServerRoot set to '/www' will be interpreted by the
  19. # server as '/www/log/access_log', where as '/log/access_log' will be
  20. # interpreted as '/log/access_log'.
  21. #
  22. # ServerRoot: The top of the directory tree under which the server's
  23. # configuration, error, and log files are kept.
  24. #
  25. # Do not add a slash at the end of the directory path. If you point
  26. # ServerRoot at a non-local disk, be sure to specify a local disk on the
  27. # Mutex directive, if file-based mutexes are used. If you wish to share the
  28. # same ServerRoot for multiple httpd daemons, you will need to change at
  29. # least PidFile.
  30. #
  31. ServerRoot "/etc/httpd"
  32. #
  33. # Listen: Allows you to bind Apache to specific IP addresses and/or
  34. # ports, instead of the default. See also the <VirtualHost>
  35. # directive.
  36. #
  37. # Change this to Listen on specific IP addresses as shown below to
  38. # prevent Apache from glomming onto all bound IP addresses.
  39. #
  40. #Listen 12.34.56.78:80
  41. # Managed by saltstack
  42. {% if salt['pillar.get']('apache:sites') is mapping %}
  43. {%- set listen_directives = [] %}
  44. {%- for id, site in salt['pillar.get']('apache:sites').items() %}
  45. {%- set interfaces = site.get('interface', '*').split() %}
  46. {%- set port = site.get('port', 80) %}
  47. {%- for interface in interfaces %}
  48. {%- if not site.get('exclude_listen_directive', False) %}
  49. {%- set listen_directive = interface ~ ':' ~ port %}
  50. {%- if listen_directive not in listen_directives %}
  51. {%- do listen_directives.append(listen_directive) %}
  52. {%- endif %}
  53. {%- endif %}
  54. {%- endfor %}
  55. {%- endfor %}
  56. {%- for listen in listen_directives %}
  57. Listen {{ listen }}
  58. {%- endfor %}
  59. {%- else %}
  60. Listen 80
  61. <IfModule mod_ssl.c>
  62. Listen 443
  63. </IfModule>
  64. <IfModule mod_gnutls.c>
  65. Listen 443
  66. </IfModule>
  67. {%- endif %}
  68. #
  69. # Dynamic Shared Object (DSO) Support
  70. #
  71. # To be able to use the functionality of a module which was built as a DSO you
  72. # have to place corresponding `LoadModule' lines at this location so the
  73. # directives contained in it are actually available _before_ they are used.
  74. # Statically compiled modules (those listed by `httpd -l') do not need
  75. # to be loaded here.
  76. #
  77. # Example:
  78. # LoadModule foo_module modules/mod_foo.so
  79. #
  80. Include conf.modules.d/*.conf
  81. #
  82. # If you wish httpd to run as a different user or group, you must run
  83. # httpd as root initially and it will switch.
  84. #
  85. # User/Group: The name (or #number) of the user/group to run httpd as.
  86. # It is usually good practice to create a dedicated user and group for
  87. # running httpd, as with most system services.
  88. #
  89. User apache
  90. Group apache
  91. # 'Main' server configuration
  92. #
  93. # The directives in this section set up the values used by the 'main'
  94. # server, which responds to any requests that aren't handled by a
  95. # <VirtualHost> definition. These values also provide defaults for
  96. # any <VirtualHost> containers you may define later in the file.
  97. #
  98. # All of these directives may appear inside <VirtualHost> containers,
  99. # in which case these default settings will be overridden for the
  100. # virtual host being defined.
  101. #
  102. #
  103. # ServerAdmin: Your address, where problems with the server should be
  104. # e-mailed. This address appears on some server-generated pages, such
  105. # as error documents. e.g. admin@your-domain.com
  106. #
  107. ServerAdmin root@localhost
  108. #
  109. # ServerName gives the name and port that the server uses to identify itself.
  110. # This can often be determined automatically, but we recommend you specify
  111. # it explicitly to prevent problems during startup.
  112. #
  113. # If your host doesn't have a registered DNS name, enter its IP address here.
  114. #
  115. #ServerName www.example.com:80
  116. #
  117. # Deny access to the entirety of your server's filesystem. You must
  118. # explicitly permit access to web content directories in other
  119. # <Directory> blocks below.
  120. #
  121. <Directory />
  122. AllowOverride none
  123. Require all denied
  124. </Directory>
  125. #
  126. # Note that from this point forward you must specifically allow
  127. # particular features to be enabled - so if something's not working as
  128. # you might expect, make sure that you have specifically enabled it
  129. # below.
  130. #
  131. #
  132. # DocumentRoot: The directory out of which you will serve your
  133. # documents. By default, all requests are taken from this directory, but
  134. # symbolic links and aliases may be used to point to other locations.
  135. #
  136. DocumentRoot "{{ apache.wwwdir }}"
  137. #
  138. # Relax access to content within /var/www.
  139. #
  140. <Directory "/var/www">
  141. AllowOverride None
  142. # Allow open access:
  143. Require all granted
  144. </Directory>
  145. # Further relax access to the default document root:
  146. <Directory "{{ apache.wwwdir }}">
  147. #
  148. # Possible values for the Options directive are "None", "All",
  149. # or any combination of:
  150. # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
  151. #
  152. # Note that "MultiViews" must be named *explicitly* --- "Options All"
  153. # doesn't give it to you.
  154. #
  155. # The Options directive is both complicated and important. Please see
  156. # http://httpd.apache.org/docs/2.4/mod/core.html#options
  157. # for more information.
  158. #
  159. Options Indexes FollowSymLinks
  160. #
  161. # AllowOverride controls what directives may be placed in .htaccess files.
  162. # It can be "All", "None", or any combination of the keywords:
  163. # Options FileInfo AuthConfig Limit
  164. #
  165. AllowOverride None
  166. #
  167. # Controls who can get stuff from this server.
  168. #
  169. Require all granted
  170. </Directory>
  171. #
  172. # DirectoryIndex: sets the file that Apache will serve if a directory
  173. # is requested.
  174. #
  175. <IfModule dir_module>
  176. DirectoryIndex index.html
  177. </IfModule>
  178. #
  179. # The following lines prevent .htaccess and .htpasswd files from being
  180. # viewed by Web clients.
  181. #
  182. <Files ".ht*">
  183. Require all denied
  184. </Files>
  185. #
  186. # ErrorLog: The location of the error log file.
  187. # If you do not specify an ErrorLog directive within a <VirtualHost>
  188. # container, error messages relating to that virtual host will be
  189. # logged here. If you *do* define an error logfile for a <VirtualHost>
  190. # container, that host's errors will be logged there and not here.
  191. #
  192. ErrorLog "{{ apache.logdir }}/error_log"
  193. #
  194. # LogLevel: Control the number of messages logged to the error_log.
  195. # Possible values include: debug, info, notice, warn, error, crit,
  196. # alert, emerg.
  197. #
  198. LogLevel warn
  199. <IfModule log_config_module>
  200. #
  201. # The following directives define some format nicknames for use with
  202. # a CustomLog directive (see below).
  203. #
  204. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  205. LogFormat "%h %l %u %t \"%r\" %>s %b" common
  206. {%- for log_format in salt['pillar.get']('apache:log_formats', []) %}
  207. LogFormat {{ log_format }}
  208. {%- endfor %}
  209. <IfModule logio_module>
  210. # You need to enable mod_logio.c to use %I and %O
  211. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
  212. </IfModule>
  213. #
  214. # The location and format of the access logfile (Common Logfile Format).
  215. # If you do not define any access logfiles within a <VirtualHost>
  216. # container, they will be logged here. Contrariwise, if you *do*
  217. # define per-<VirtualHost> access logfiles, transactions will be
  218. # logged therein and *not* in this file.
  219. #
  220. #CustomLog "logs/access_log" common
  221. #
  222. # If you prefer a logfile with access, agent, and referer information
  223. # (Combined Logfile Format) you can use the following directive.
  224. #
  225. CustomLog "{{ apache.logdir }}/access_log" combined
  226. </IfModule>
  227. <IfModule alias_module>
  228. #
  229. # Redirect: Allows you to tell clients about documents that used to
  230. # exist in your server's namespace, but do not anymore. The client
  231. # will make a new request for the document at its new location.
  232. # Example:
  233. # Redirect permanent /foo http://www.example.com/bar
  234. #
  235. # Alias: Maps web paths into filesystem paths and is used to
  236. # access content that does not live under the DocumentRoot.
  237. # Example:
  238. # Alias /webpath /full/filesystem/path
  239. #
  240. # If you include a trailing / on /webpath then the server will
  241. # require it to be present in the URL. You will also likely
  242. # need to provide a <Directory> section to allow access to
  243. # the filesystem path.
  244. #
  245. # ScriptAlias: This controls which directories contain server scripts.
  246. # ScriptAliases are essentially the same as Aliases, except that
  247. # documents in the target directory are treated as applications and
  248. # run by the server when requested rather than as documents sent to the
  249. # client. The same rules about trailing "/" apply to ScriptAlias
  250. # directives as to Alias.
  251. #
  252. ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
  253. </IfModule>
  254. #
  255. # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
  256. # CGI directory exists, if you have that configured.
  257. #
  258. <Directory "/var/www/cgi-bin">
  259. AllowOverride None
  260. Options None
  261. Require all granted
  262. </Directory>
  263. <IfModule mime_module>
  264. #
  265. # TypesConfig points to the file containing the list of mappings from
  266. # filename extension to MIME-type.
  267. #
  268. TypesConfig /etc/mime.types
  269. #
  270. # AddType allows you to add to or override the MIME configuration
  271. # file specified in TypesConfig for specific file types.
  272. #
  273. #AddType application/x-gzip .tgz
  274. #
  275. # AddEncoding allows you to have certain browsers uncompress
  276. # information on the fly. Note: Not all browsers support this.
  277. #
  278. #AddEncoding x-compress .Z
  279. #AddEncoding x-gzip .gz .tgz
  280. #
  281. # If the AddEncoding directives above are commented-out, then you
  282. # probably should define those extensions to indicate media types:
  283. #
  284. AddType application/x-compress .Z
  285. AddType application/x-gzip .gz .tgz
  286. #
  287. # AddHandler allows you to map certain file extensions to "handlers":
  288. # actions unrelated to filetype. These can be either built into the server
  289. # or added with the Action directive (see below)
  290. #
  291. # To use CGI scripts outside of ScriptAliased directories:
  292. # (You will also need to add "ExecCGI" to the "Options" directive.)
  293. #
  294. #AddHandler cgi-script .cgi
  295. # For type maps (negotiated resources):
  296. #AddHandler type-map var
  297. #
  298. # Filters allow you to process content before it is sent to the client.
  299. #
  300. # To parse .shtml files for server-side includes (SSI):
  301. # (You will also need to add "Includes" to the "Options" directive.)
  302. #
  303. AddType text/html .shtml
  304. AddOutputFilter INCLUDES .shtml
  305. </IfModule>
  306. #
  307. # Specify a default charset for all content served; this enables
  308. # interpretation of all content as UTF-8 by default. To use the
  309. # default browser choice (ISO-8859-1), or to allow the META tags
  310. # in HTML content to override this choice, comment out this
  311. # directive:
  312. #
  313. AddDefaultCharset {{ apache.default_charset }}
  314. <IfModule mime_magic_module>
  315. #
  316. # The mod_mime_magic module allows the server to use various hints from the
  317. # contents of the file itself to determine its type. The MIMEMagicFile
  318. # directive tells the module where the hint definitions are located.
  319. #
  320. MIMEMagicFile conf/magic
  321. </IfModule>
  322. #
  323. # Customizable error responses come in three flavors:
  324. # 1) plain text 2) local redirects 3) external redirects
  325. #
  326. # Some examples:
  327. #ErrorDocument 500 "The server made a boo boo."
  328. #ErrorDocument 404 /missing.html
  329. #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
  330. #ErrorDocument 402 http://www.example.com/subscription_info.html
  331. #
  332. #
  333. # EnableMMAP and EnableSendfile: On systems that support it,
  334. # memory-mapping or the sendfile syscall may be used to deliver
  335. # files. This usually improves server performance, but must
  336. # be turned off when serving from networked-mounted
  337. # filesystems or if support for these functions is otherwise
  338. # broken on your system.
  339. # Defaults if commented: EnableMMAP On, EnableSendfile Off
  340. #
  341. #EnableMMAP off
  342. EnableSendfile on
  343. {%- for directive, dvalue in salt['pillar.get']('apache:global', {}).items() %}
  344. {{ directive }} {{ dvalue }}
  345. {%- endfor %}
  346. # Supplemental configuration
  347. #
  348. # Load config files in the "/etc/httpd/conf.d" directory, if any.
  349. IncludeOptional {{ apache.confdir }}/*.conf
  350. {% if apache.vhostdir != apache.confdir %}
  351. IncludeOptional {{ apache.vhostdir }}/*.conf
  352. {% endif %}
  353. # Added for security enhancements
  354. TraceEnable off
  355. ServerSignature off
  356. ServerTokens Prod