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.

401 lines
13KB

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