Skip to content

Commit ea7680b

Browse files
authored
Merge ac693eb into 48e35c1
2 parents 48e35c1 + ac693eb commit ea7680b

23 files changed

+1129
-92
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ install:
5656
before_script:
5757
# Install Varnish
5858
- |
59-
set -e
6059
curl -L https://packagecloud.io/varnishcache/varnish${VARNISH_VERSION//./}/gpgkey | sudo apt-key add -
6160
curl -L "https://packagecloud.io/install/repositories/varnishcache/varnish${VARNISH_VERSION//./}/config_file.list?os=ubuntu&dist=trusty&source=script" | sudo tee -a /etc/apt/sources.list
6261
cat /etc/apt/sources.list
@@ -67,6 +66,8 @@ before_script:
6766
- if [ "$VARNISH_MODULES_VERSION" != "" ]; then sh ./tests/install-varnish-modules.sh; fi
6867
# Install NGINX
6968
- sh ./tests/install-nginx.sh
69+
# Install OpenLiteSpeed
70+
- sh ./tests/install-openlitespeed.sh
7071

7172
script:
7273
- composer validate --strict --no-check-lock
@@ -83,3 +84,6 @@ after_failure:
8384
- sudo cat /var/log/apache2/error.log
8485
- sudo cat /var/log/apache2/access.log
8586
- sudo cat /var/log/apache2/other_vhosts_access.log
87+
- sudo cat /usr/local/lsws/logs/error.log
88+
- sudo cat /usr/local/lsws/logs/access.log
89+
- sudo ls -la /usr/local/lsws/logs

doc/cache-invalidator.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Create the cache invalidator by passing a proxy client as
1818
// or
1919
$client = new ProxyClient\Nginx(...);
2020
// or
21+
$client = new ProxyClient\LiteSpeed(...);
22+
// or
2123
$client = new ProxyClient\Symfony(...);
2224
// or, for local development
2325
$client = new ProxyClient\Noop();

doc/litespeed-configuration.rst

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+

doc/proxy-clients.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Client Purge Refresh Ban Tagging Clear
2424
============= ======= ======= ======= ======= =======
2525
Varnish ✓ ✓ ✓ ✓
2626
NGINX ✓ ✓
27+
LiteSpeed ✓ ✓ ✓ ✓
2728
Symfony Cache ✓ ✓ ✓ (1) ✓ (1)
2829
Noop ✓ ✓ ✓ ✓
2930
Multiplexer ✓ ✓ ✓ ✓
@@ -181,6 +182,21 @@ call `setPurgeLocation()`::
181182
To use the client, you need to :doc:`configure NGINX <nginx-configuration>`
182183
accordingly.
183184

185+
LiteSpeed Client
186+
~~~~~~~~~~~~~~~~~
187+
188+
The LiteSpeed client sends HTTP requests with the ``HttpDispatcher``. Create the
189+
dispatcher as explained above and pass it to the LiteSpeed client::
190+
191+
use FOS\HttpCache\ProxyClient\LiteSpeed;
192+
193+
$litespeed = new LiteSpeed($httpDispatcher);
194+
195+
.. note::
196+
197+
To use the client, you need to :doc:`configure LiteSpeed <litespeed-configuration>`
198+
accordingly.
199+
184200
Symfony Client
185201
~~~~~~~~~~~~~~
186202

doc/proxy-configuration.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Proxy Server Configuration
44
==========================
55

6-
You need to configure the proxy server of your choice (Varnish, NGINX or Symfony
6+
You need to configure the proxy server of your choice (Varnish, NGINX, LiteSpeed or Symfony
77
HttpCache) to work with FOSHttpCache. These guides help you
88
for the configuration for the features of this library. You will still need to
99
know about the other features of the proxy server to get everything right.
@@ -12,4 +12,5 @@ know about the other features of the proxy server to get everything right.
1212

1313
varnish-configuration
1414
nginx-configuration
15+
litespeed-configuration
1516
symfony-cache-configuration

0 commit comments

Comments
 (0)