Apache httpd server

Questions answered

How to enable HTTP/2?

Apache v2.4.17 has HTTP/2 support via mod_http2 module (see announcement).

To enable support of SPDY on Apache:

SPDY is deprecated in favour of HTTP/2 which is supported by Chrome from v40.

Note that mod_http2 module has limitations with mod_mpm_prefork worker strategy (HTTP/2 is not supported in prefork from Apache v2.4.27), hence switch Apache from prefork to event.

Note that TLS should be at least v1.2 for HTTP/2 to function and there are cipher suite restrictions hence set SSLProtocol all -SSLv3 -TLSv1 or stricter.

See also:

How to set umask for Apache daemon?

# mkdir /etc/systemd/system/apache2.service.d
# cat > /etc/systemd/system/apache2.service.d/override.conf <<EOF
[Service]
UMask=0027
EOF

How to setup Apache custom error message

From ErrorDocument (see also International Customized Server Error Messages):

httpd.conf

<IfModule mod_negotiation.c>
<IfModule mod_include.c>
Alias /error/ "/usr/share/apache2/error/"
 
<Directory "/usr/share/apache2/error">
    AllowOverride None
    Options IncludesNoExec
    AddOutputFilter Includes html
    AddHandler type-map var
    Order allow,deny
    Allow from all
    LanguagePriority en es de fr
    ForceLanguagePriority Prefer Fallback
</Directory>
 
ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
</IfModule>
</IfModule>

httpd reports attempt to invoke directory as script: /usr/lib/cgi-bin/ to error log

From this page: This problems occurs when you try to access a directory marked only for CGI script execution with ScriptAlias or SetHandler. To overcome this use Alias + AddHandler:
Alias /exe/ /usr/lib/cgi-bin/
AddHandler cgi-script .pl

How to properly configure SSL?

How to send reverse-proxy request via another forward-proxy?

Suppose you want to redirect /external location of the service in Intranet to some external site. However external request should go via corporate proxy.

Solution:

httpd.conf

LoadModule proxy_module /usr/lib/apache2/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/mod_proxy_http.so

<VirtualHost 10.0.0.1>
    ...
    RewriteEngine on
    # Requests should be processed by reverse proxy:
    RewriteRule /external/(.*) http://external.site.com/$1 [QSA,P]
    # Reverse proxy should use this forward proxy for external URLs:
    ProxyRemoteMatch "http://.*\.com.*" http://proxy:8080
</VirtualHost>

httpd.conf

# Set the cookie if URL parameter is given:
RewriteCond %{QUERY_STRING} (^|&)action=setmycookie($|&) [NC]
RewriteRule ^ - [L,PT,CO=mycookie:true:%{HTTP_HOST}]

# If cookie is set, do something:
RewriteCond %{HTTP_COOKIE} (^|;\s*)mycookie=true
RewriteRule ^ - [L,PT]

SVN

SVN HTTP repository error: asks to use another URL

When trying to checkout the project, the following error message appears: svn: Repository moved permanently to 'http://myhost.com/'; please relocate

From FAQ:

Make sure your repository <Location> does not overlap or live within any areas already exported as e.g. DocumentRoot.

SVN HTTP repository: cannot open Berkeley DB

After recovering SVN database from backup the following error appears in Apache error log when trying to access the repository: (20014)Internal error: Berkeley DB error for filesystem '/var/lib/svn/public/db' while opening environment:\n or (20014)Internal error: Berkeley DB error for filesystem '/var/lib/svn/public/db' while opening 'nodes' table:\nInvalid argument

As to Subversion FAQ run the following commands:
db4.8_recover -c -v -h /var/lib/svn/public/db
svnadmin recover /var/lib/svn/public
cd /var/lib/svn/public && make proper

Run them when Apache server is shut down! If the repository continues to work until the next commit and then fails again, check the permissions (group should be writeable by Apache server).

SquirrelMail

There are some issues with SquirrelMail on PHP 5.6. The unfortunate is that the project is abandoned, some PHP functions have changed the signature and some became deprecated, so it's getting hard to keep SquirrelMail working on latest PHP engines.

The package squirrelmail_1.5.1-6_all.deb (check whole folder for sources) includes the following fixes:

See also SquirrelMail bug report and my post to maillist.

SquirrelMail logs out very soon

Try to play with Options → Folders → Automatic Refresh or put the following to the .htaccess file in squirrel root directory (see here):
php_value session.gc_maxlifetime 7200
php_value session.cookie_lifetime 7200

SquirrelMail breaks with error Error connecting to IMAP server: tls://localhost.

The error message reads:
Error connecting to IMAP server: tls://localhost.
0 :

It seems that you're running SquirrelMail < v1.5. Upgrade to e.g. v1.5.1.

SquirrelMail breaks with error Call to undefined function session_unregister()

The Apache error log reads:
PHP Fatal error:  Call to undefined function session_unregister() in /usr/share/squirrelmail/functions/global.php on line 111

Here comes the patch to fix it (download):
--- /usr/share/squirrelmail/functions/global.php.orig    2006-07-08 21:01:27.000000000 +0200
+++ /usr/share/squirrelmail/functions/global.php    2012-12-19 22:27:47.433789672 +0100
@@ -92,9 +92,9 @@

     sqsession_is_active();

-    $_SESSION["$name"] = $var;
+    session_start();

-    session_register("$name");
+    $_SESSION["$name"] = $var;
 }

 /**
@@ -107,8 +107,6 @@
     sqsession_is_active();

     unset($_SESSION[$name]);
-
-    session_unregister("$name");
 }

 /**

See also Some serious incompatibilities with wheezy php 5.4.

SquirrelMail breaks with error PHP Fatal error: Cannot redeclare hex2bin()

The Apache error log reads:
PHP Fatal error:  Cannot redeclare hex2bin() in /usr/share/squirrelmail/plugins/mail_fetch/functions.php on line 309

Just remove this function (download)::
--- /usr/share/squirrelmail/plugins/mail_fetch/functions.php.orig    2006-07-08 21:09:31.000000000 +0200
+++ /usr/share/squirrelmail/plugins/mail_fetch/functions.php    2012-12-19 22:32:26.273782351 +0100
@@ -293,21 +293,6 @@
 }
 // end of hooked functions

-/**
- * hex2bin - document me
- */
-function hex2bin( $data ) {
-
-    /* Original code by josh@superfork.com */
-
-    $len = strlen($data);
-    $newdata = '';
-    for( $i=0; $i < $len; $i += 2 ) {
-        $newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) );
-    }
-    return $newdata;
-}
-
 function mf_keyED( $txt ) {

     global $MF_TIT;

How to enable system aSpell dictionaries in SquirrelMail spellchecker?

Worth doing this just to support ancient browsers without build-in spell checker.

In Debian the utility /usr/sbin/update-dictcommon-aspell (check /usr/share/perl5/Debian/DictionariesCommon.pm) updates the system-wide file /var/cache/dictionaries-common/sqspell.php. To use this approach download latest stable version (e.g. v1.4.23) and take /etc/squirrelmail/sqspell_config.php from it.

Complete but outdated patch is here (check also aspell support for squirrelspell via dictionaries-common).

SquirrelMail shows deleted messages in the folder

From Externally deleted mail still shows up in Inbox:

The problem is that SquirrelMail and Thunderbird are configured differently. Deleting a mail on an IMAP server is a two step process: marking the mail as deleted, and then expunge the mail marked as deleted. Apparently Thunderbird only does the first step which is why you see the mail as gray with an icon in SquirrelMail. Your SquirrelMail is likely to be configured to expunge automatically when doing a delete. You can set mail.imap.expunge_after_delete=true using Thunderbird's Config Editor.

software/httpd.txt · Last modified: 2011/10/16 05:41 by dmitry
 
 
Recent changes RSS feed Driven by DokuWiki