httpd.apache.org/docs/2.4
Rich Bowen - rbowen@apache.org
@rbowen
@apache_httpd
Let's dive right in
(Assume appropriate marketing hyperbole here: New and Improved)
2.4 is httpd for the cloud, and so many of the features are geared in that direction.
Build:
./configure --enable-mpms-shared=all
Configure:
LoadModule mpm_event_module modules/mod_mpm_event.so
LogLevel info ssl:warn
Get the log info from just the module you're interested in
LogLevel info <Directory "/usr/local/apache/htdocs/app"> LogLevel debug </Directory>
Just log the app that you know is giving you problems.
# Compare the host name to example.com and # redirect to www.example.com if it matches <If "%{HTTP_HOST} == 'example.com'"> Redirect permanent / http://www.example.com/ </If>
<Macro VHost $name $domain> <VirtualHost *:80> ServerName $domain ServerAlias www.$domain DocumentRoot /var/www/vhosts/$name ErrorLog /var/log/httpd/$name.error_log CustomLog /var/log/httpd/$name.access_log combined </VirtualHost> </Macro>
# Create three vhosts Use VHost example example.com Use VHost myhost hostname.org Use VHost apache apache.org # Clean up UndefMacro VHost
# Compare the host name to example.com and # redirect to www.example.com if it matches <If "%{HTTP_HOST} == 'example.com'"> Redirect permanent / http://www.example.com/ </If>
# Force text/plain if requesting a file with the # query string contains 'forcetext' <If "%{QUERY_STRING} =~ /forcetext/"> ForceType text/plain </If>
# Only allow access to this content during business hours <Directory "/foo/bar/business"> Require expr "%{TIME_HOUR} -gt 9 && %{TIME_HOUR} -lt 17" </Directory>
# Images should be from local pages # (Prevent image "hotlinking") <FilesMatch \.(jpg|png|gif)$> <If "%{HTTP_HOST} !~ 'example.com'> Require all denied </If> </FilesMatch>
NameVirtualHost *:80 <VirtualHost *:80> ServerName foo.com ... </VirtualHost> <VirtualHost *:80> ServerName bar.com ... </VirtualHost>
<VirtualHost *:80> ServerName foo.com ... </VirtualHost> <VirtualHost *:80> ServerName bar.com ... </VirtualHost>
The new AllowOverrideList directive allows more fine grained control which directives are allowed in .htaccess files.
AllowOverride None AllowOverrideList Redirect RedirectMatch
Define docroot /var/www/htdocs DocumentRoot ${docroot} <Directory ${docroot}> Require all granted </Directory>
FastCGI and SCGI Protocol backends for mod_proxy
ProxyPass / backend.server:port ProxyPassReverse / backend.server:port
## ## express-map.txt: ## www1.example.com http://192.168.211.2:8080 www2.example.com http://192.168.211.12:8088 www3.example.com http://192.168.212.10
httxt2dbm -i express-map.txt -o emap
ProxyExpressEnable on ProxyExpressDBMFile emap
Allow mod_proxy_balancer to base loadbalancing decisions on the number of active connections on the backend servers.
An advanced replacement of mod_substitute, allows to edit the response body with the full power of sed.
# In the following example, the sed filter # will change the string # "monday" to "MON" # and the string "sunday" to SUN in html documents # before sending to the client. <Directory "/var/www/docs/sed"> AddOutputFilter Sed html OutputSed "s/monday/MON/g" OutputSed "s/sunday/SUN/g" </Directory>
Allows to add customizable debug logging at different phases of the request processing.
<Location /foo/> LogMessage "subrequest to /foo/" \ hook=type_checker expr=%{IS_SUBREQ} </Location>
Can specify a hook (phase of transaction) and an expression to check
<Location /> LogMessage "%{reqenv:X-Foo}" hook=all </Location>
<Location /downloads> SetOutputFilter RATE_LIMIT SetEnv rate-limit 400 # That's KB/s </Location>
Replaces nasty old order/allow/deny crap
Access is allowed unconditionally.
Access is denied unconditionally.
Access is allowed only if one of the given environment variables is set.
Access is allowed only for the given HTTP methods.
Require ip 10 172.20 192.168.2 Require host example.com Require local
Arbitrary expressions
Require expr "%{TIME_HOUR} -ge 9 && %{TIME_HOUR} -le 17"
<RequireAll> Require method GET POST OPTIONS Require valid-user </RequireAll>
Or ...
<RequireAny> Require method GET POST OPTIONS Require valid-user </RequireAny>
<Directory /www/mydocs> <RequireAll> <RequireAny> Require user superadmin <RequireAll> Require group admins Require ldap-group cn=Administrators,o=Airius <RequireAny> Require group sales Require ldap-attribute dept="sales" </RequireAny> </RequireAll> </RequireAny> <RequireNone> Require group temps Require ldap-group cn=Temporary Employees,o=Airius </RequireNone> </RequireAll> </Directory>
Actually, this was backported and is available in 2.2.
FallBackResource /index.php
Implements the "front controller" model that you've been doing with RewriteRules up until now.
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteBase / RewriteRule . index.php [PT]
httpd.apache.org/docs/2.4
@rbowen
@modrewrite
#httpd on Freenode
Space | Forward |
---|---|
Left, Down, Page Down | Next slide |
Right, Up, Page Up | Previous slide |
P | Open presenter console |
H | Toggle this help |