{"id":167,"date":"2012-06-11T04:29:12","date_gmt":"2012-06-11T04:29:12","guid":{"rendered":"http:\/\/rmohan.com\/?p=167"},"modified":"2012-06-11T04:29:12","modified_gmt":"2012-06-11T04:29:12","slug":"setup-caching-on-apache","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=167","title":{"rendered":"Setup Caching on Apache"},"content":{"rendered":"<p><strong>Setup Caching on Apache<\/strong><\/p>\n<p>Setup Caching<\/p>\n<p>Please note that caching will only work for non-secure data. It is not possible to cache data from a HTTPS url.<br \/>\nTo configure caching, we&#8217;ll first have to enable it in apache:<\/p>\n<p>    Start yast<br \/>\n    Go to network services<br \/>\n    Select the \u201cHTTP Server\u201d<br \/>\n    Go to \u201cServer Modules\u201d:<br \/>\n    Enable these modules<br \/>\n        cache<br \/>\n        diskcache<\/p>\n<p>Save the changes.<\/p>\n<p>    Note: If you forget to enable the cache module you&#8217;ll get this warning:<\/p>\n<p>sjoerd@reverseproxy:\/etc\/apache2\/vhosts.d> sudo \/etc\/init.d\/apache2 restart<br \/>\nhttpd2-prefork: Syntax error on line 116 of \/etc\/apache2\/httpd.conf: Syntax error on line 26 of \/etc\/apache2\/sysconfig.d\/loadmodule.conf: Cannot load \/usr\/lib64\/apache2-prefork\/mod_disk_cache.so into server<\/p>\n<p>Second disk<\/p>\n<p>Add a second disk to the VM and configure it to mount on \/var\/cache\/apache, the default location for apache cache.<\/p>\n<p>    Disk size: 8 GB<br \/>\n    file system ext3, no access time<br \/>\n    Mountpoint: \/var\/cache\/apache<\/p>\n<p>reverseproxy:~ # mount<br \/>\n&#8230;<br \/>\n\/dev\/sdb1 on \/var\/cache\/apache type ext3 (rw,noatime,acl,user_xattr)<\/p>\n<p>And set the owner:<\/p>\n<p>sudo chown -R wwwrun:root \/var\/cache\/apache<\/p>\n<p>Apache Cache<\/p>\n<p>Set the configuration below inside the vhost config file.<\/p>\n<p># Caching<br \/>\nCacheRoot \/var\/cache\/apache<br \/>\nCacheEnable disk \/<br \/>\nCacheDirLevels 1<br \/>\nCacheDirLength 1<br \/>\nCacheDefaultExpire 7200<br \/>\nCacheMaxExpire 86400<br \/>\nCacheIgnoreNoLastMod On<br \/>\nCacheMaxFileSize 2048000<br \/>\nCacheStorePrivate On<\/p>\n<p>Apache Cache Resources<br \/>\nhttp:\/\/httpd.apache.org\/docs\/2.2\/caching.html<br \/>\nhttp:\/\/httpd.apache.org\/docs\/2.2\/mod\/mod_disk_cache.html<br \/>\nhttp:\/\/www.mnot.net\/cache_docs\/<br \/>\nhttp:\/\/en.wikipedia.org\/wiki\/List_of_HTTP_status_codes<br \/>\nSwitch From https To http<\/p>\n<p>This is not really possible, if you need \u201cProxyPreserveHost on\u201d in Apache. Our application needs that to work through a reverse proxy, setting it to off breaks it. We wanted to configure the reverse proxy from https on the outside, to http on the inside but that seems impossible. It is either http to http, or https to https. I tested both, and they work, but unfortunely switching from https on the outside to http on the inside does not. I experimented with rewriterules, requestheader, and a couple of settings more, no luck.<br \/>\nMod Security<\/p>\n<p>We want to offload the application webserver as much as possible which means we&#8217;ll also implement mod_security on the reverse proxy. This will offload and simplify the application webserver.<\/p>\n<p>Mod Security 2.x has these requirements:<\/p>\n<p>    Apache 2.2.x (highly recommended)<br \/>\n    Apache module mod_unique_id<br \/>\n    libapr &#038; libapr-util<br \/>\n    libpcre<br \/>\n    libxml2<\/p>\n<p>All modules are already installed by default. Note that libpcre is known as &#8216;pcre&#8217; on SLES.<\/p>\n<p>You just have to enable the module mod_unique_id as it is not enabled by default.<br \/>\nRestart to make your changes effective and run httpd2 -M to see if all modules are loaded.<br \/>\nIf everything is loaded stop apache.<br \/>\nMod Security Installation<\/p>\n<p>Make sure you have access to the SLES SDK Sources. Since we have an SLES Installation Update Server 11 I could download the SDK ISO DVD1 (which holds all required files) and add it to my software repository.<\/p>\n<p>The ISO can be downloaded from here: SLES 11 SP1 SDK Download (A Novell account is required). The file you need to download is called: SLE-11-SP1-SDK-DVD-x86_64-GM-DVD1.iso<\/p>\n<p>After installing, it&#8217;s mostly just a module but not entirely. You need to to enable two modules now, the mod_unique_id which is a normal module and can be enabled the normal way:<\/p>\n<p>    yast2 ? network services ? http server ? server modules<br \/>\n    select the module and enable it<\/p>\n<p>The second module to enable is mod_security. Since it is not recognized by apache as a module we have to manually add the module to the modulelist.<br \/>\nFind the APACHE_MODULES in the apache2 sysconfig file and add the module like below:<\/p>\n<p>reverseproxy:\/var\/log\/apache2 # vi \/etc\/sysconfig\/apache2<br \/>\nAPACHE_MODULES=&#8221;authz_host actions alias auth_basic authz_groupfile authn_file authz_user autoindex cgi dir include log_config mime negotiation setenvif status userdir asis cache disk_cache imagemap proxy<\/p>\n<p>Restart apache and check wether the modules are running by issuing the &#8216;httpd2 -M&#8217; command:<\/p>\n<p>reverseproxy:\/var\/log\/apache2 # httpd2 -M<br \/>\nLoaded Modules:<br \/>\n core_module (static)<br \/>\n mpm_prefork_module (static)<br \/>\n http_module (static)<br \/>\n so_module (static)<br \/>\n authz_host_module (shared)<br \/>\n actions_module (shared)<br \/>\n alias_module (shared)<br \/>\n auth_basic_module (shared)<br \/>\n authz_groupfile_module (shared)<br \/>\n authn_file_module (shared)<br \/>\n authz_user_module (shared)<br \/>\n autoindex_module (shared)<br \/>\n cgi_module (shared)<br \/>\n dir_module (shared)<br \/>\n include_module (shared)<br \/>\n log_config_module (shared)<br \/>\n mime_module (shared)<br \/>\n negotiation_module (shared)<br \/>\n setenvif_module (shared)<br \/>\n status_module (shared)<br \/>\n userdir_module (shared)<br \/>\n asis_module (shared)<br \/>\n cache_module (shared)<br \/>\n disk_cache_module (shared)<br \/>\n imagemap_module (shared)<br \/>\n proxy_module (shared)<br \/>\n proxy_connect_module (shared)<br \/>\n proxy_http_module (shared)<br \/>\n rewrite_module (shared)<br \/>\n ssl_module (shared)<br \/>\n unique_id_module (shared)<br \/>\n authz_default_module (shared)<br \/>\n security2_module (shared)<br \/>\nSyntax OK<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setup Caching on Apache<\/p>\n<p>Setup Caching<\/p>\n<p>Please note that caching will only work for non-secure data. It is not possible to cache data from a HTTPS url. To configure caching, we&#8217;ll first have to enable it in apache:<\/p>\n<p> Start yast Go to network services Select the \u201cHTTP Server\u201d Go to \u201cServer Modules\u201d: Enable these [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/167"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions\/168"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}