Lukáš Bařinka
© 2021
REV 2.10
mod_so
)mod_so
)LoadModule
identifier
module_pathname
ServerRoot
, suffix is .so
by default<IfModule …>
container follows usualyLoadModule
identifikátor
cesta_k_modulu
ServerRoot
, název modulu obvykle s příponou .so
<IfModule …>
LoadModule alias_module modules/mod_alias.so
<IfModule alias_module>
Alias /vhosts /var/www/vhosts
<Directory /var/www/vhosts>
DefaultType text/html
AddDefaultCharset utf-8
Require all granted
</Directory>
</IfModule>
-D def
)
Kontrola (testování) konfigurace
Je nutné uvést používané definice (-D def
)
apachectl -t -D SSL -D PHP5 -D USERDIR -D INFO
[time] [warn] The Alias directive in .../00_mod_autoindex.conf at line 5 will probably never
match because it overlaps an earlier Alias.
apachectl -M
Loaded Modules:
core_module (static)
mpm_worker_module (static)
…
alias_module (shared)
auth_basic_module (shared)
…
apachectl -l
Compiled in modules:
core.c
worker.c
http_core.c
mod_so.c
--with-mpm=name
prefork
– processes (contemporary)
worker
– threads (old)
event
– threads (contemporary)
mpm_winnt
beos
mpm_netware
mpmt_os2
--with-mpm=jméno
prefork
– procesy (aktuální)
worker
– vlákna (starší)
event
– vlákna (aktuální)
mpm_winnt
beos
mpm_netware
mpmt_os2
Requests served by processes
Obsluhu požadavků zajišťují procesy
Requests served by threads inside processes
Obsluhu požadavků zajišťují vlákna procesů
mod_reqtimeout
type=timeout-maxtimeout,MinRate=data_rate
RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
408 REQUEST TIME OUT
mod_reqtimeout
type=timeout-maxtimeout,MinRate=data_rate
RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
408 REQUEST TIME OUT
Requests served by threads inside processes, dedicated thread to handle connections
Obsluhu požadavků zajišťují vlákna procesů, dedikované vlánkno pro obsluhu spojení
mod_status
Provides information on server activity and performance
Provides information about running environment
mod_info
Provides a comprehensive overview of the server configuration
mod_log_config
Provides ability to requests logging customization
Allows to configure custom formats and log storage
mod_logio
Adds logging of input and output bytes per request
mod_status
Umožňuje kontrolovat výkon serveru
Poskytuje informace o jeho běhu
mod_info
Poskytuje informace o nastavení serveru
mod_log_config
Poskytuje prostředky pro logování požadavků
Umožňuje nastavení různých formátů logů a jejich úložišť
mod_logio
Přidává možnost logovat množství příchozích a odchozích dat
<Location /server-status>
SetHandler server-status
<RequireAny>
Require host .admin.company.com
Require local
</RequireAny>
</Location>
ExtendedStatus
Off|On
Keep track of extended status information for each requestSeeRequestTail
Off|On
Displays first/last 63 characters of request line/server-status
/server-status?refresh=N
Refresh the page every N seconds/server-status?auto
Machine-readable outputExtendedStatus
Off|On
Umožňuje logovat jednotlivé požadavkySeeRequestTail
Off|On
Ovládá záznam prvních/posledních 63 znaků z požadavku/server-status
/server-status?refresh=N
Automatická obnova po N sekundách/server-status?auto
Strojově zpracovatelný výstup
<Location /server-info>
SetHandler server-info
Require local
</Location>
<Location /server-info>
SetHandler server-info
Require local
</Location>
/server-info
Full information/server-info?module_name
Only information relevant to the named moduleE.g. mod_alias.c
/server-info?config
Just the configuration directives, not sorted by module,/server-info?list
Only a simple list of enabled modules/server-info?server
Only the basic server information/server-info
Komplexní informace/server-info?název_modulu
Informace o zvoleném modulu (např. mod_alias.c)/server-info?config
Konfigurace bez komentářů a bílých znaků/server-info?list
Seznam použitých modulů/server-info?server
Základní informace o serverucore
)ErrorLog
file-path|syslog[:[facility][:tag]]
file-path
logging into file|file-path
logging into commandsyslog[:facility]
using (UNIX) logging daemonsyslogd
syslog-ng
ErrorLogFormat
ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"
core
)ErrorLog
file-path|syslog[:[facility][:tag]]
file-path
logování do souboru|file-path
logování do příkazusyslog[:facility]
využít logovacího démona (UNIX)syslogd
syslog-ng
ErrorLogFormat
ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common
147.32.80.98 - - [15/Jul/2011:14:45:49 +0200] "GET /y36aws-0 3/total.png HTTP/1.1" 200 10099
127.0.0.1 - - [15/Jul/2011:14:46:01 +0200] "GET /server-stat us?auto HTTP/1.0" 200 1201
<
/ >
specifie origin/final request
%s
, %U
, %T
, %D
, and %r
look at the original request, all others look at the final request
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common
147.32.80.98 - - [15/Jul/2011:14:45:49 +0200] "GET /y36aws-0 3/total.png HTTP/1.1" 200 10099
127.0.0.1 - - [15/Jul/2011:14:46:01 +0200] "GET /server-stat us?auto HTTP/1.0" 200 1201
<
/ >
určuje první/poslední požadavek
%s
, %U
, %T
, %D
, and %r
používají původní požadavek, ostatní konečný požadavek%h | Remote host |
%r | First line of request |
%u | Remote user if the request was authenticated (! HTTP 401) |
%l | Remote logname (connecting process owner) From identd/authd/pidnetd/…, if supplied, else – |
%b | Size of response in bytes, excluding HTTP headers, 0 → - |
%B | Size of response in bytes, excluding HTTP headers |
%t | Time the request was received Standard format, %{format}t according to strftime (3) |
%s | HTTP response status |
%I | Actual number of bytes sent over the network (in/out), headers included, requires mod_logio |
%h | remote host |
%r | první řádek z požadavku |
%u | remote user - z autentizace (! stavový kód HTTP 401) |
%l | remote logname (vlastník procesu, který inicioval spojení) Vyžaduje modul mod_ident a na vzdáleném počítači běžící démon (authd, pidentd atp.), jinak bude místo hodnoty – |
%b | velikost odpovědi bez http hlavičky v bytech, místo 0 je – |
%B | velikost odpovědi bez http hlavičky v bytech |
%t | čas požadavku (std. formát, %{format}t podle strftime (3)) |
%s | HTTP status požadavku |
%I | počet přijatých/odeslaných bytů vč. HTTP hlaviček, vyžaduje modul mod_logio |
The goal is to configure error logging for entire web server and access log per virtualhosts. Access log can be joined for entire server or separated per virtualhost. It it possible to combine both approaches.
Cílem je nakonfigurovat logování chyb pro celý server a logování všech požadavků na jednotlivé virtualhosty. Logování přístupů může probíhat pro každý virtualhost zvlášť, nebo pro všechny dohromady. Možná je i kombinace.
Place the configuration along main server and/or virtualhost configuration. The output buffers need to be flushed sometime during logging into files using sync
command.
Konfiguraci umístěte k hlavnímu serveru a k virtuálnímu hostiteli. Při logování do souboru (pokud se zprávy neobjevují a měly by) může být potřeba vynutit vyprázdnění bufferů příkazem sync
.
ErrorLog
for entire server into /var/log/apache2/main_error_log
fileErrorLog
for www.mycorp.net
virtualhost into syslog
daemonsyslog
ErrorLog
do souboru /var/log/apache2/main_error_log
www.mycorp.net
směrujte ErrorLog
na syslog
syslog
fungujemy-common
server IP, client (hostname), remote user, time of request arrival, request line in double-quotes, response status (final), response size in bytes (headers excluded)my-referer
request header Referer
content, string ::
, requested URLmy-combined
concatenation of my-common and my-referer formats"LogFormat cannot use one nickname to define another nickname!"
my-common
server IP, klient (hostname), vzdálený uživatel, čas přijetí požadavku, první řádka požadavku v uvozovkách, stav požadavku (po všech přesměrováních), velikost odpovědi v bytech bez HTTP hlavičekmy-referer
obsah hlavičky Referer
odeslané serveru v požadavku, řetězec ::
, požadovaná URLmy-combined
spojení předchozích dvou formátů"LogFormat cannot use one nickname to define another nickname!"
/var/log/apache2/my-access_log
in my-common
format
/var/log/apache2/my-referer_log
in my-referer
format
www.mycorp.net
virtualhost in my-combined
format using /usr/bin/logger
tool, that will send messages to syslog/var/log/apache2/my-access_log
ve formátu my-common
/var/log/apache2/my-referer_log
ve formátu my-referer
www.mycorp.net
logujte rourou ve formátu my-combined
pomocí nástroje /usr/bin/logger
, který zprávy předává na syslogServerRoot
E.g. /etc/apache2
|/usr/bin/logger
Logging to process-t apache
Tag message with apache
insead of root
in recordcurl
command
curl -H 'Referer: foo' www.mycorp.net
ServerRoot
Např. /etc/apache2
|/usr/bin/logger
Logování do procesu-t apache
Tag, zapíše apache
místo root
do logucurl
curl -H 'Referer: foo' www.mycorp.net
Content-Type: image/gif
Content-Language: cs, en
Content-Type: text/html; charset=ISO-8859-2
Content-Encoding: x-gzip
Content-Type: image/gif
Content-Language: cs, en
Content-Type: text/html; charset=ISO-8859-2
Content-Encoding: x-gzip
Last-Modified
information stays the same when mime-type has changed
touch
command can be used for this purposeLast-Modified
touch
<FilesMatch \.cgi$>
SetHandler cgi-script
</FilesMatch>
<FilesMatch \.cgi$>
SetHandler cgi-script
</FilesMatch>
# Example: Filename = info.cs.utf8.html
Content-Type: text/html; charset=UTF-8
Content-Language: cs
# Příklad: Soubor s názvem info.cs.utf8.html
Content-Type: text/html; charset=UTF-8
Content-Language: cs
TypesConfig /etc/mime.types
TypesConfig /etc/mime.types
egrep '(zip|html|pdf|jpg|png|mp3)' /etc/mime.types
...
application/pdf pdf
application/xhtml+xml xhtml xht
application/zip zip
audio/mpeg mpga mpega mp2 mp3 m4a
image/jpeg jpeg jpg jpe
image/png png
text/html html htm shtml
...
AddType
MIME-type
extension…
Adds relation between extension and mime-type
Přidává vazbu mezi příponou (extension) a mime-typem
AddType image/gif .gif
DefaultType
MIME-type|None
Specifies default mime-type (core
) [ignored since 2.4.]
Určuje implicitní mime-type (core
) [od 2.4. se ignoruje]
DefaultType text/plain
ForceType
MIME-type|None
Enforces MIME-type (core
)
Vynucuje nastavení MIME-type (core
)
ForceType None
RemoveType
extension…
Removes relation between extension and mime-type
Odstraňuje vazby na příponou (extension)
To disable mime-type database usage use empty file
Pro zamezení použití databáze mime-type lze použít prázdný soubor
TypesConfig /dev/null
AddLanguage
MIME-lang
extension…
AddLanguage cs .cz .cs
DefaultLanguage
MIME-lang
DefaultLanguage en
RemoveLanguage
extension…
AddCharset
charset
extension…
AddCharset ISO-8859-2 .iso8859-2 .latin2 .cen
AddDefaultCharset
charset
Applied to text/plain or text/html only (core
)
Aplikuje se na text/plain, text/html (core
)
Takes precedence over others (META tag), use with care!
Má přednost před ostatními (META tag), používat s rozmyslem!
RemoveCharset extension...
AddEncoding
MIME-enc
extension…
AddEncoding x-gzip .gz
RemoveEncoding
extension…
mod_mime_magic
module
file
commandmod_mime
module cannot be used to determine mime-typeMimeMagicFile
directive enables the moduleMimeMagicFile
file
MimeMagicFile conf/magic
mod_mime_magic
file
mod_mime
MimeMagicFile
povoluje použití moduluMimeMagicFile
file
MimeMagicFile conf/magic
AddHandler
handler
extension…
AddHandler cgi-script .cgi
SetHandler
handler
(core
)RemoveHandler
extension…
AddInputFilter
filter[;filter…]
extension…
SetInputFilter
directiveSetInputFilter
SetInputFilter
filter[;filter…]
(core
)RemoveInputFilter
extension…
AddOutputFilter
filter[;filter…]
extension…
SetOutputFilter
directiveSetOutputFilter
AddOutputFilter INCLUDES;DEFLATE shtml
SetOutputFilter
filter[;filter…]
(core
)
<Directory /www/data/>
SetOutputFilter INCLUDES
</Directory>
RemoveOutputFilter
extension…
Accept*
Accept-Language: fr; q=1.0, en; q=0.5
Accept: text/html; q=1.0, text/*; q=0.8, q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1
mod_negotiation
moduleAccept
Accept-Language
Accept-Encoding
Accept-Charset
Accept*
Accept-Language: fr; q=1.0, en; q=0.5
Accept: text/html; q=1.0, text/*; q=0.8, q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1
mod_negotiation
Accept
Accept-Language
Accept-Encoding
Accept-Charset
Accept*
header field and assign a quality to each variantVary
is set to indicate the dimensions of negotiationAccept*
a její příslušnou kvalituVary
obsahující dimenzi dojednáváníAccept
quality factorAccept-Language
or else LanguagePriority
orderAccept-Charset
Or Latin1, non Latin1Accept
Accept-Language
nebo LanguagePriority
Multiviews
option
Options +Multiviews
MultiviewsMatch
directive (mod_mime
)
MultiviewsMatch Any | NegotiatedOnly | Filters | Handlers
NegotiatedOnly
Content-Type/Language/Encoding must match (default)Filters
, Handlers
Filters / handlers taken into account as wellAny
Processes files with any extension
Options +Multiviews
MultiviewsMatch
(mod_mime
)
MultiviewsMatch Any | NegotiatedOnly | Filters | Handlers
NegotiatedOnly
Musí odpovídat Content-Type/Language/Encoding (default)Filters
, Handlers
Zpracovává přípony asociované s filtry / handleryAny
Zpracovává soubory s libovolnou příponouLanguagePriority
MIME-lang
[MIME-lang]
…
LanguagePriority cs en de fr
ForceLanguagePriority
None
| Prefer
| Fallback
# According to LanguagePriority
ForceLanguagePriority Prefer
LanguagePriority
MIME-lang
[MIME-lang]
…
LanguagePriority cs en de fr
ForceLanguagePriority
None
| Prefer
| Fallback
# Podle LanguagePriority
ForceLanguagePriority Prefer
.var
qs
=<0.0,1.0>Content-Type
/Language
/Encoding
type-map
handler
AddHandler type-map .var
URI: text.html
URI: text.html.cs
Content-Language: cs-cz
Content-Type: text/html; qs=0.8
URI: text.html.en
Content-Language: en-us
Content-Type: text/html; qs=1
.var
qs
=<0.0,1.0>Content-Type
/Language
/Encoding
type-map
AddHandler type-map .var
URI: text.html
URI: text.html.cs
Content-Language: cs-cz
Content-Type: text/html; qs=0.8
URI: text.html.en
Content-Language: en-us
Content-Type: text/html; qs=1
Accept-Encoding: gzip,deflate
Else server sends uncompressed data
mod_mime
and mod_deflate
are enabled
AddType text/plain .log
AddOutputFilter DEFLATE .log
AddOutputFilterByType DEFLATE text/html text/plain
DeflateCompressionLevel
1 = low compression, 9 = high compression
Accept-Encoding: gzip,deflate
Jinak server pošle nekomprimovaná data
mod_mime
a mod_deflate
AddType text/plain .log
AddOutputFilter DEFLATE .log
AddOutputFilterByType DEFLATE text/html text/plain
DeflateCompressionLevel
Stupeň komprese
1 = nejméně komprese, 9 = nejvíce komprese
CustomLog
%{name}n
Informace o kompresi Přidává další možnosti jako typ poznámky %{název}n
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat "%{outstream}n/%{instream}n (%{ratio}n%%)" …
The goal is to configure content negotiation using Multiviews and using Type-map as well. The part of it is also a configuration of preferred language variants according to client needs and server abilities.
Cílem je nakonfigurovat dojednávání obsahu pomocí Multiviews i pomocí Type-map. Součástí je také nastavení preferovaných jazykových variant podle přání klienta i možností serveru.
index.html.{en,de}
files in /var/www/main/manual
directory and set /manual
alias for that directoryindex.html
requests according to client language preferences
Change preferred language in web browser or add request header
Type-map
fileMultiviews
method/var/www/main/manual
zkontrolujte existenci a obsah souborů index.html.{en,de}
a nastavte alias /manual
pro tento adresářindex.html
v závislosti na požadavcích klienta
Změňte v prohlížeči národní prostředí, případně odesílané hlavičky požadavků
type-map
Multiviews
curl -I -H 'Accept-Language: de' …
<Directory /var/www/main/manual>
<FilesMatch "\.html$">
SetHandler type-map
</FilesMatch>
</Directory>
Options +Multiviews
mv index.html index-bak.html
ForceLanguagePriority
and LanguagePriority
directives and see a corresponding server behaviorForceLanguagePriority
a LanguagePriority
na přání klienta a možnosti serveruForceLanguagePriority |
unset language |
unavailable language |
---|---|---|
Prefer |
LanguagePriority | 406 |
Fallback |
smallest | LanguagePriority |
Fallback Prefer |
LanguagePriority | LanguagePriority |
Prefer Fallback |
LanguagePriority | LanguagePriority |
None |
smallest | 406 |
ForceLanguagePriority |
žádný jazyk |
neexistující jazyk |
---|---|---|
Prefer |
LanguagePriority | 406 |
Fallback |
nejmenší | LanguagePriority |
Fallback Prefer |
LanguagePriority | LanguagePriority |
Prefer Fallback |
LanguagePriority | LanguagePriority |
None |
nejmenší | 406 |