Wilt u leren hoe u de Apache Browser Caching-functie kunt configureren? In deze zelfstudie laten we je alle stappen zien die nodig zijn om de Apache Browser Caching-functie te configureren op een computer waarop Ubuntu Linux draait.

• Ubuntu-versie: 18.04

Hardware Lijst:

In het volgende gedeelte wordt de lijst met apparaten weergegeven die zijn gebruikt om deze WordPress-zelfstudie te maken.

Elk onderdeel van de hierboven genoemde hardware is te vinden op de Amazon-website.

WordPress Playlist:

Op deze pagina bieden we snelle toegang tot een lijst met video's gerelateerd aan WordPress-installatie.

Vergeet niet je te abonneren op ons YouTube-kanaal met de naam FKIT.

WordPress Gerelateerde Tutorial:

Op deze pagina bieden we snelle toegang tot een lijst van tutorials gerelateerd aan WordPress-installatie.

Tutorial - Apache Browser Caching-configuratie

Eerst moet u de Apache-webserver installeren.

Gebruik op de Linux-console de volgende opdrachten om Apache te installeren.

# apt-get update
# apt-get install apache2

Nu moet u de volgende Apache-modules inschakelen:

• mod_headers
• mod_expires

Gebruik de volgende opdrachten om mod_headers en mod_expires in te schakelen.

# a2enmod headers
# a2enmod expires

# systemctl restart apache2

Bewerk het apache2.conf-configuratiebestand.

# vi /etc/apache2/apache2.conf

Voer aan het einde van het bestand de gewenste Browser Caching-configuratie in.

Als voorbeeld, hier is onze configuratie.

<IfModule mod_expires.c>
ExpiresActive On
FileETag None
ExpiresDefault "access plus 14 days"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/css "now plus 1 month"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/html "access plus 1 days"
</IfModule>

Om de nieuwe configuratie te activeren, moet u Apache opnieuw opstarten.

# systemctl restart apache2

Houd er rekening mee dat u de gewenste hoeveelheid Browser-cachetijd moet opgeven om aan uw behoeften te voldoen.

Testen - Apache Browser Caching-configuratie

Om de configuratie van uw browsercache te testen, maken we een eenvoudige HTML-pagina met een afbeelding

# cd /var/www/html
# wget https://techexpert.tips/wp-content/uploads/2017/12/TechExpert-Logo-Small.png
# vi test.html

Hier is de inhoud van het test.html-bestand.

<html>
<body>
<h1>TEST header</h1><br>
<img src="TechExpert-Logo-Small.png">
</body>

</html>

Installeer de vereiste software om de Apache Browser Caching-functie te testen.

# apt-get update
# apt-get install wget curl

Gebruik de volgende opdracht om de browsercachefunctie te testen op HTML-documenten met WGET.

Houd er rekening mee dat u 200.200.200.200 moet wijzigen in het IP-adres van uw server.

# wget -S http://200.200.200.200/test.html

Dit is het configuratie-resultaat Browser Caching vóór onze configuratie:

HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Date: Fri, 14 Dec 2018 16:58:36 GMT
Server: Apache/2.4.29 (Ubuntu)
Last-Modified: Fri, 14 Dec 2018 16:19:49 GMT
ETag: "64-57cfdcce7b707"
Accept-Ranges: bytes
Content-Length: 100
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Length: 100 [text/html]

Dit is het configuratie-resultaat Browser Caching na onze configuratie:

HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Date: Fri, 14 Dec 2018 17:05:04 GMT
Server: Apache/2.4.29 (Ubuntu)
Last-Modified: Fri, 14 Dec 2018 16:19:49 GMT
Accept-Ranges: bytes
Content-Length: 100
Cache-Control: max-age=86400
Expires: Sat, 15 Dec 2018 17:05:04 GMT
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Length: 100 [text/html] Saving to: ‘test.html.3’

Zoals u kunt zien, specificeert onze configuratie een dagcache voor HTML-documenten.

• ExpiresByType text / html "toegang plus 1 dagen"

Het WGET-resultaat laat zien dat het HTML-bestand tot morgen wordt bewaard.

• Vervalt: za, 15 dec 2018 17:05:04 GMT

Gebruik de volgende opdracht om de browsercachefunctie te testen op PNG-afbeeldingen met CURL.

# curl -svo /dev/null http://200.200.200.200/TechExpert-Logo-Small.png

Dit is het configuratie-resultaat Browser Caching vóór onze configuratie:

* TCP_NODELAY set
* Connected to 34.220.19.99 (34.220.19.99) port 80 (#0)
> GET /TechExpert-Logo-Small.png HTTP/1.1
> Host: 34.220.19.99
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 14 Dec 2018 17:24:32 GMT
< Server: Apache/2.4.29 (Ubuntu)
< Last-Modified: Sat, 24 Nov 2018 02:49:53 GMT
< ETag: "483-57b60277af640"
< Accept-Ranges: bytes
< Content-Length: 1155
< Content-Type: image/png
<
{ [1155 bytes data]

Dit is het configuratie-resultaat Browser Caching na onze configuratie:

* TCP_NODELAY set
* Connected to 34.220.19.99 (34.220.19.99) port 80 (#0)
> GET /TechExpert-Logo-Small.png HTTP/1.1
> Host: 34.220.19.99
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 14 Dec 2018 17:18:04 GMT
< Server: Apache/2.4.29 (Ubuntu)
< Last-Modified: Sat, 24 Nov 2018 02:49:53 GMT
< Accept-Ranges: bytes
< Content-Length: 1155
< Cache-Control: max-age=2592000
< Expires: Sun, 13 Jan 2019 17:18:04 GMT
< Content-Type: image/png
<
{ [1155 bytes data]

Zoals u kunt zien, specificeert onze configuratie cache van één maand voor PNG-afbeeldingen.

• ExpiresByType image / png "toegang plus 1 maand"

Het resultaat CURL geeft aan dat het PNG-bestand tot 13 januari wordt bewaard.

• Vervalt: zon, 13 januari 2019 17:18:04 GMT