1
- # [ Apache Server Configs] ( https://github.com/h5bp/server-configs-apache/ )
1
+ # [ Apache Server Configs] ( https://github.com/h5bp/server-configs-apache )
2
2
3
3
[ ![ Test] ( https://github.com/h5bp/server-configs-apache/workflows/server/badge.svg )] ( https://github.com/h5bp/server-configs-apache/actions?query=workflow%3Aserver )
4
4
@@ -10,93 +10,49 @@ accessible, if needed, even cross-domain.
10
10
11
11
## Getting Started
12
12
13
- There are a few options for getting the Apache server configs.
13
+ There are a two options for getting the Apache server configs:
14
+ * If you have access to the [ main server configuration
15
+ file] ( https://httpd.apache.org/docs/current/configuring.html#main )
16
+ (usually called ` httpd.conf ` ), you should configure Apache by this way.
17
+ This is usually the recommended way, as using ` .htaccess ` files [ slows
18
+ down] ( https://httpd.apache.org/docs/current/howto/htaccess.html#when )
19
+ Apache!
20
+ * If you don't have access to it, which is quite common with hosting services,
21
+ checkout the [ ` .htaccess ` guide] ( #htaccess-file ) .
14
22
15
- See also the [ Apache Getting Started] ( https://httpd.apache.org/docs/current/getting-started.html ) .
16
-
17
- ### Using the httpd configuration
18
-
19
- If you have access to the [ main server configuration
20
- file] ( https://httpd.apache.org/docs/current/configuring.html#main )
21
- (usually called ` httpd.conf ` ), you should configure Apache by this way.
22
- This is usually the recommended way, as using ` .htaccess ` files [ slows
23
- down] ( https://httpd.apache.org/docs/current/howto/htaccess.html#when )
24
- Apache!
25
-
26
- Getting options:
27
- * Download the [ zip archive] ( https://github.com/h5bp/server-configs-apache/archive/3.2.1.zip )
28
- * Checkout directly:
29
- ``` shell
30
- apache2ctl stop
31
- cd /usr/local
32
- mv apache2 apache2-previous
33
- git clone https://github.com/h5bp/server-configs-apache.git apache2
34
- # install-specific edits
35
- apache2ctl start
36
- ```
37
-
38
- See [ Apache httpd configuration usage guide] ( #Apache-httpd-configuration ) .
39
-
40
- ### Using the ` .htaccess ` file
41
-
42
- If you don't have access, which is quite common with hosting services,
43
- just copy the ` .htaccess ` file in the root of the website.
44
-
45
- Getting options:
46
- * Download the ` h5bp.htaccess ` on the [ latest release] ( https://github.com/h5bp/server-configs-apache/releases/latest )
47
- * Install them via [ npm] ( https://www.npmjs.com/ ) : ` npm install --save-dev apache-server-configs `
48
- Inside the ` dist/ ` folder, you'll find a ready-to-use ` .htaccess ` file.
49
-
50
-
51
- ## Usage
52
-
53
- ### Basic structure
54
-
55
- This repository has the following structure:
56
-
57
- ```
58
- ./
59
- ├── vhosts/
60
- │ ├── 000-default.conf
61
- │ └── templates/
62
- ├── h5bp/
63
- │ ├── basic.conf
64
- │ └── .../
65
- └── httpd.conf
66
- ```
67
-
68
- * ** ` vhosts/ ` **
69
-
70
- This directory should contain all the server definitions.
71
-
72
- Except if they are dot prefixed or non .conf extension, all files in this
73
- folder ** are** loaded automatically.
23
+ Using the Apache server configs repo directly has a few required steps to be able to work.
74
24
75
- * ** ` templates ` folder**
76
-
77
- Files in this folder contain a ` <VirtualHost/> ` template for secure and non-secure hosts.
78
- They are intended to be copied in the ` vhosts ` folder with all ` example.com `
79
- occurrences changed to the target host.
25
+ See also the [ Apache Getting Started] ( https://httpd.apache.org/docs/current/getting-started.html ) .
80
26
81
- * ** ` h5bp/ ` **
27
+ ### Check ` httpd.conf ` settings
82
28
83
- This directory contains config snippets (mixins) to be included as desired.
84
-
85
- There are two types of config files provided, individual config snippets and
86
- combined config files which provide convenient defaults.
29
+ The first thing to check is that the ` httpd.conf ` file contains appropriate values for
30
+ your specific install.
87
31
88
- * ** ` basic.conf ` **
32
+ Most specific variables are:
33
+ * ` ServerRoot `
34
+ * ` User `
35
+ * ` Group `
36
+ * ` ErrorLog `
37
+ * ` CustomLog `
38
+ * ` TypesConfig ` (ensure that the path for the ` mime.types ` file is valid)
89
39
90
- This file loads a small subset of the rules provided by this repository to add
91
- expires headers, allow cross domain fonts and protect system files from web
92
- access.
93
- The ` basic.conf ` file includes the rules which are recommended to always be
94
- defined.
40
+ ### Apache test and restart
95
41
96
- * ** ` httpd.conf ` **
42
+ * To verify Apache config
43
+ ``` shell
44
+ $ apache2 -t
45
+ ```
97
46
98
- The main Apache config file.
47
+ * To verify Apache config with a custom file
48
+ ``` shell
49
+ $ apache2 -t -f httpd.conf
50
+ ```
99
51
52
+ * To reload Apache and apply new config
53
+ ``` shell
54
+ $ apache2ctl reload
55
+ ```
100
56
101
57
### Enable Apache httpd modules
102
58
@@ -131,7 +87,7 @@ used to install Apache.
131
87
132
88
` sudo a2enmod setenvif headers deflate filter expires rewrite include `
133
89
134
- 2 . Restart apache by using the following command, so the new configuration takes
90
+ 2 . Restart apache by using the following command so the new configuration takes
135
91
effect.
136
92
137
93
` sudo /etc/init.d/apache2 restart `
@@ -152,41 +108,83 @@ used to install Apache.
152
108
* ** XAMPP** : ` /Applications/XAMPP/etc/httpd.conf `
153
109
* ** WAMP** : ` C:\apache\conf\httpd.conf `
154
110
155
- Open the file in a text editor and uncomment all the required modules.
111
+ Open the file in a text editor and uncomment all of the required modules.
156
112
Once you have done so, reset MAMP/WAMP/XAMPP.
157
113
158
- ### Apache httpd configuration
114
+ ### Basic structure
159
115
160
- #### Check ` httpd.conf ` settings
116
+ This repository has the following structure:
161
117
162
- The first thing to check is that the ` httpd.conf ` file contains appropriate values for
163
- your specific install.
118
+ ```
119
+ ./
120
+ ├── vhosts/
121
+ │ ├── 000-default.conf
122
+ │ └── templates/
123
+ ├── h5bp/
124
+ │ ├── basic.conf
125
+ │ └── .../
126
+ └── httpd.conf
127
+ ```
164
128
165
- Most specific variables are:
166
- * ` ServerRoot `
167
- * ` User `
168
- * ` Group `
169
- * ` ErrorLog `
170
- * ` CustomLog `
129
+ * ** ` vhosts/ ` **
171
130
172
- #### Apache test and restart
131
+ This directory should contain all the server definitions.
173
132
174
- * To verify Apache config
175
- ``` shell
176
- $ apache2 -t
177
- ```
133
+ Except if they are dot prefixed or non ` .conf ` extension, all files in this
134
+ folder ** are** loaded automatically.
178
135
179
- * To verify Apache config with a custom file
180
- ``` shell
181
- $ apache2 -t -f httpd.conf
182
- ```
136
+ * ** ` templates ` folder**
183
137
184
- * To reload Apache and apply new config
185
- ``` shell
186
- $ apache2ctl reload
187
- ```
138
+ Files in this folder contain a ` <VirtualHost/> ` template for secure and non-secure hosts.
139
+ They are intended to be copied in the ` vhosts ` folder with all ` example.com `
140
+ occurrences changed to the target host.
141
+
142
+ * ** ` h5bp/ ` **
143
+
144
+ This directory contains config snippets (mixins) to be included as desired.
145
+
146
+ There are two types of config files provided, individual config snippets and
147
+ combined config files which provide convenient defaults.
148
+
149
+ * ** ` basic.conf ` **
150
+
151
+ This file loads a small subset of the rules provided by this repository to add
152
+ expires headers, allow cross domain fonts and protect system files from web
153
+ access.
154
+ The ` basic.conf ` file includes the rules which are recommended to always be
155
+ defined.
156
+
157
+ * ** ` httpd.conf ` **
158
+
159
+ The main Apache config file.
160
+
161
+
162
+ ## Usage
163
+
164
+ ### As a reference
188
165
189
- #### Manage sites
166
+ To use as reference requires no special installation steps, download/checkout the
167
+ repository to a convenient location and adapt your existing httpd configuration
168
+ incorporating the desired functionality from this repository.
169
+
170
+ Download the [ latest release archive] ( https://github.com/h5bp/server-configs-apache/releases/latest ) .
171
+
172
+ ### Directly
173
+
174
+ To use directly, add httpd config files from this repository.
175
+ For example:
176
+
177
+ ``` shell
178
+ apache2ctl stop
179
+ git clone https://github.com/h5bp/server-configs-apache.git /tmp/h5bp-apache
180
+ cd /usr/local
181
+ cp -r apache2 apache2-previous
182
+ cp -r /tmp/h5bp-apache/* apache2
183
+ # install-specific edits
184
+ apache2ctl start
185
+ ```
186
+
187
+ ### Manage sites
190
188
191
189
``` bash
192
190
$ cd /usr/local/apache2/vhosts
@@ -213,7 +211,19 @@ $ apache2ctl reload
213
211
```
214
212
215
213
216
- ## Custom ` .htaccess ` builds
214
+ ## ` .htaccess ` file
215
+
216
+ ### Usage
217
+
218
+ Just copy the ` .htaccess ` file in the root of the website.
219
+
220
+ Getting options:
221
+ * Download the ` h5bp.htaccess ` on the [ latest release] ( https://github.com/h5bp/server-configs-apache/releases/latest )
222
+ and rename the file to ` .htaccess `
223
+ * Install them via [ npm] ( https://www.npmjs.com/ ) : ` npm install --save-dev apache-server-configs `
224
+ Inside the ` dist/ ` folder, you'll find a ready-to-use ` .htaccess ` file.
225
+
226
+ ### Custom ` .htaccess ` builds
217
227
218
228
Security, mime-type, and caching best practices evolve, and so should do your
219
229
` .htaccess ` file. In the past, with each new * Apache Server Configs* release
@@ -224,13 +234,13 @@ The [**build script**](#build-script-buildsh) with its re-usable and customizabl
224
234
[ ** build configuration** ] ( #configuration-file-htaccessconf ) lets you easily
225
235
update your ` .htaccess ` file. Each new ` .htaccess ` build will contain the
226
236
updated * Apache Server Configs* source files, enabled or commented-out according
227
- to your settings in the * htaccess.conf* of your project root.
237
+ to your settings in the ` htaccess.conf ` of your project root.
228
238
229
- ### Configuration file: * htaccess.conf*
239
+ #### Configuration file: ` htaccess.conf `
230
240
231
241
Allows you to define which module to [ enable] ( #enabling-modules ) or
232
242
[ disable] ( #disabling-modules ) for your project. Just copy the default
233
- [ ** htaccess.conf** ] ( https://github.com/h5bp/server-configs-apache/blob/master/bin/htaccess.conf )
243
+ [ ` htaccess.conf ` ] ( https://github.com/h5bp/server-configs-apache/blob/master/bin/htaccess.conf )
234
244
from this repo into your project directory. Adjust to your needs, and/or
235
245
[ add custom code] ( #adding-custom-modules ) snippets you need for your project.
236
246
Its syntax is straight and pretty much self-explanatory:
@@ -247,11 +257,11 @@ omit "src/example-module/not-needed-at-all.conf"
247
257
... more modules ...
248
258
```
249
259
250
- #### Disabling modules
260
+ ##### Disabling modules
251
261
252
262
For example, the * “Cross-origin web fonts”* snippet is always included in
253
263
our pre-built ` .htaccess ` file and enabled. If your project does not deal
254
- with web fonts, you can ** disable** or ** omit** this section:
264
+ with web fonts, you can ` disable ` or ` omit ` this section:
255
265
256
266
This will comment out the section:
257
267
@@ -265,17 +275,17 @@ disable "h5bp/cross-origin/web_fonts.conf"
265
275
omit "h5bp/cross-origin/web_fonts.conf"
266
276
```
267
277
268
- #### Enabling modules
278
+ ##### Enabling modules
269
279
270
280
For example, the * “Forcing https://”* snippet is disabled by default,
271
281
although being included in our pre-built ` .htaccess ` . To enable this
272
- snippet, change the ** disable** keyword to ** enable: **
282
+ snippet, change the ` disable ` keyword to ` enable ` :
273
283
274
284
```
275
285
enable "h5bp/rewrites/rewrite_http_to_https.conf"
276
286
```
277
287
278
- #### Adding custom modules
288
+ ##### Adding custom modules
279
289
280
290
Imagine you're passing all requests to non-existing files to your
281
291
favourite web framework. The according
@@ -286,21 +296,21 @@ snippet would go like this:
286
296
FallbackResource index.php
287
297
```
288
298
289
- Store this snippet in a file, e.g. ** config/framework_rewrites.conf, ** and add
290
- a reference in your ** htaccess.conf: **
299
+ Store this snippet in a file, e.g. ` config/framework_rewrites.conf ` , and add
300
+ a reference in your ` htaccess.conf ` :
291
301
292
302
```
293
303
# PROJECT MODULES
294
304
enable "config/framework_rewrites.conf"
295
305
```
296
306
297
- ### Build script: * build.sh*
307
+ #### Build script: ` build.sh `
298
308
299
309
Dive into your project root and call the build script from wherever you cloned
300
310
the repo. Here are three examples:
301
311
302
- ** 1. Create a default .htaccess**
303
- in current work directory. An existing ** htaccess.conf** in this directory will
312
+ ** 1. Create a default ` .htaccess ` **
313
+ in current work directory. An existing ` htaccess.conf ` in this directory will
304
314
be used; if none is present, the
305
315
[ ** default configuration** ] ( https://github.com/h5bp/server-configs-apache/blob/master/bin/htaccess.conf )
306
316
will apply.
@@ -316,7 +326,7 @@ $ path/to/server-configs-apache/bin/build.sh
316
326
317
327
** 2. Custom output location**
318
328
Just add output path and filename as parameter. By the way, if there's an
319
- existing * .htaccess* file, the build script will create a backup.
329
+ existing ` .htaccess ` file, the build script will create a backup.
320
330
321
331
``` bash
322
332
$ path/to/server-configs-apache/bin/build.sh htdocs/.htaccess
@@ -325,9 +335,9 @@ $ path/to/server-configs-apache/bin/build.sh htdocs/.htaccess
325
335
[✔] Moved in place: ' htdocs/.htaccess'
326
336
```
327
337
328
- ** 3. Custom .htaccess configuration**
329
- Why not maintain your personal ** ~ /htaccess.conf? ** This example creates a
330
- * .htaccess* in current work directory, according to your favourite settings
338
+ ** 3. Custom ` .htaccess ` configuration**
339
+ Why not maintain your personal ` ~/htaccess.conf ` ? This example creates a
340
+ ` .htaccess ` in current work directory, according to your favourite settings
331
341
you may have stored in your ` $HOME ` directory:
332
342
333
343
``` bash
0 commit comments