|
| 1 | +.. _litespeed configuration: |
| 2 | + |
| 3 | +LiteSpeed Configuration |
| 4 | +----------------------- |
| 5 | + |
| 6 | +Below you will find detailed LiteSpeed configuration recommendations for the |
| 7 | +features provided by this library. |
| 8 | + |
| 9 | +Preamble |
| 10 | +~~~~~~~~ |
| 11 | + |
| 12 | +First of all, let's get one thing straight here: You'll find a lot of documentation |
| 13 | +and noise around LiteSpeed cache on the Internet, mostly involving plugins, specifically the |
| 14 | +Wordpress one. You **don't** need any plugin to benefit from LiteSpeed cache! |
| 15 | +As long as you follow the HTTP specification regarding the caching headers, you can use it as |
| 16 | +a general reverse proxy just like NGINX or Varnish. |
| 17 | + |
| 18 | +LiteSpeed comes in two different variants: |
| 19 | + |
| 20 | +* OpenLiteSpeed (OLS) - the open source product with less features |
| 21 | +* LiteSpeed Web Server (LSWS) - the enterprise version with more features and professional support |
| 22 | + |
| 23 | +The caching module implementations are different and thus have to be configured differently but they support the |
| 24 | +same set of features (except for OLS not supporting Edge Side Includes (ESI)). |
| 25 | + |
| 26 | +So before you start configuring the server, make sure you know which version of LiteSpeed you are using. |
| 27 | + |
| 28 | +.. note:: |
| 29 | + |
| 30 | + Any LiteSpeed setup works in a single node web server environment only. If you are targeting a multi |
| 31 | + node setup you might want to consider switching to :ref:`Varnish <varnish configuration>` which has excellent |
| 32 | + support for this already built-in in this library. |
| 33 | + |
| 34 | + |
| 35 | +Configuring OpenLiteSpeed |
| 36 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 37 | + |
| 38 | +OLS does not support different caching settings depending on ``.htaccess`` settings and different paths. |
| 39 | +If you need that, you have to go with LSWS instead. |
| 40 | +Thus, OLS has to be configured as follows on server or vHost level:: |
| 41 | + |
| 42 | + module cache { |
| 43 | + # This enables the public cache |
| 44 | + enableCache 1 |
| 45 | + |
| 46 | + # This disables the private cache |
| 47 | + enablePrivateCache 0 |
| 48 | + |
| 49 | + # This enables the public cache |
| 50 | + checkPublicCache 1 |
| 51 | + |
| 52 | + # This disables the private cache |
| 53 | + checkPrivateCache 0 |
| 54 | + |
| 55 | + # Also consider the query string in caches |
| 56 | + qsCache 1 |
| 57 | + |
| 58 | + # Enable checking for a cached entry if there's a cookie on the request |
| 59 | + reqCookieCache 1 |
| 60 | + |
| 61 | + # We ignore request Cache-Control headers |
| 62 | + ignoreReqCacheCtrl 1 |
| 63 | + |
| 64 | + # Must be disabled, this tells LS to check the Cache-Control/Expire headers on the response |
| 65 | + ignoreRespCacheCtrl 0 |
| 66 | + |
| 67 | + # We don't cache responses that set a cookie |
| 68 | + respCookieCache 0 |
| 69 | + |
| 70 | + # Configure the maximum stale age to a sensible value for your application |
| 71 | + # The maxStaleAge defines a grace period in which LS can use an out of date (stale) response while checking on a new version |
| 72 | + maxStaleAge 10 |
| 73 | + |
| 74 | + # Make sure we disable expireInSeconds because it would override our Cache-Control header |
| 75 | + expireInSeconds 0 |
| 76 | + |
| 77 | + # Enable the module |
| 78 | + ls_enabled 1 |
| 79 | + } |
| 80 | + |
| 81 | +That's all you need. Of course you might want to adjust certain values to your needs. |
| 82 | +Also refer to the OLS docs if you need more details about the different configuration values. |
| 83 | + |
| 84 | +Configuring LiteSpeed WebServer |
| 85 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 86 | + |
| 87 | +LSWS can also be configured on server level, however, as LSWS supports ``.htaccess`` you may want to configure it |
| 88 | +there to give your application the flexibility of having different configurations for certain paths. |
| 89 | + |
| 90 | +Configure your ``.htaccess`` as follows:: |
| 91 | + |
| 92 | + <IfModule LiteSpeed> |
| 93 | + CacheEnable public / |
| 94 | + # TODO: The rest of the directives |
| 95 | + </IfModule> |
| 96 | + |
| 97 | +Also refer to the LSWS docs if you need more details about the different configuration values. |
| 98 | + |
| 99 | +Configuring FOSHttpCache to work with LiteSpeed |
| 100 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 101 | + |
| 102 | +Because LiteSpeed does not support a multi node setup configuring the proxy client is pretty straight forward if |
| 103 | +you serve your application only on one domain:: |
| 104 | + |
| 105 | + use FOS\HttpCache\ProxyClient\HttpDispatcher; |
| 106 | + use FOS\HttpCache\ProxyClient\LiteSpeed; |
| 107 | + |
| 108 | + $servers = ['127.0.0.1']; |
| 109 | + $baseUri = 'example.com'; |
| 110 | + $httpDispatcher = new HttpDispatcher($servers, $baseUri); |
| 111 | + |
| 112 | + $litespeed = new LiteSpeed($httpDispatcher); |
| 113 | + |
| 114 | +If you need multiple domains, make your ``$baseUri`` an array like so:: |
| 115 | + |
| 116 | + use FOS\HttpCache\ProxyClient\HttpDispatcher; |
| 117 | + use FOS\HttpCache\ProxyClient\LiteSpeed; |
| 118 | + |
| 119 | + $servers = ['127.0.0.1']; |
| 120 | + $baseUris = ['example.com', 'foobar.com']; |
| 121 | + $httpDispatcher = new HttpDispatcher($servers, $baseUris); |
| 122 | + |
| 123 | + $litespeed = new LiteSpeed($httpDispatcher); |
| 124 | + |
| 125 | +Cache Tagging |
| 126 | +~~~~~~~~~~~~~ |
| 127 | + |
| 128 | +If you want to use cache tagging please note that you cannot use the default settings of the ``ResponseTagger`` (which |
| 129 | +by default uses ``X-Cache-Tags``) but instead you have to configure it to ``X-LiteSpeed-Tag`` like so:: |
| 130 | + |
| 131 | + use FOS\HttpCache\ResponseTagger; |
| 132 | + use FOS\HttpCache\TagHeaderFormatter; |
| 133 | + |
| 134 | + $formatter = new CommaSeparatedTagHeaderFormatter('X-LiteSpeed-Tag'); |
| 135 | + $responseTagger = new ResponseTagger(['header_formatter' => $formatter]); |
| 136 | + |
| 137 | + |
0 commit comments