Skip to content

LiteSpeed support #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d065005
Added LiteSpeed support
Toflar Oct 31, 2018
b9d4bef
Updated docs
Toflar Nov 21, 2018
8e627ab
Generate reasonalby random filename
Toflar Nov 21, 2018
888f2ed
Do not trust input
Toflar Nov 21, 2018
5c547fa
Implemented support for absolute purge urls and split up target_dir i…
Toflar Dec 8, 2018
864bf88
Adressed several review comments
Toflar Jan 22, 2019
190d39a
Fixed mandatory argument
Toflar Jan 22, 2019
53b77a4
Preparing functional tests for litespeed integration
Toflar Jan 22, 2019
ea3a3dc
Added vhost config for lsws tests
Toflar Jan 28, 2019
6d466f1
Needs more permissions
Toflar Jan 28, 2019
5060661
Added mkdir
Toflar Jan 28, 2019
515a3f6
Trying to fix permission issues
Toflar Jan 28, 2019
9d19daf
Next try
Toflar Jan 31, 2019
8954738
More debug information
Toflar Jan 31, 2019
bdb151f
Test
Toflar Jan 31, 2019
ae148ae
Test
Toflar Jan 31, 2019
55dbb32
Let's see again
Toflar Jan 31, 2019
773f9e1
Create log dir
Toflar Jan 31, 2019
13ac037
Test
Toflar Jan 31, 2019
b154a88
Only stop when ls is running
Toflar Jan 31, 2019
d072524
Install using apt
Toflar Feb 1, 2019
0ffc8f6
Let's build ourselves so we can configure using the travis user
Toflar Feb 1, 2019
9e9e8b1
Start litespeed with root (sudo) permssion in tests
Mar 13, 2019
58fffce
Merge pull request #1 from dol/litespeed
Toflar Mar 14, 2019
c9a7908
Switched to correctly use array command lines and introduced allowing…
Toflar Mar 14, 2019
8972446
CS
Toflar Mar 14, 2019
3e88831
Use port 8080
Toflar Mar 14, 2019
1fa197c
Litespeed only adds the header if it was a cache hit
Toflar Mar 14, 2019
6d85708
Fixed docroot
Toflar Mar 14, 2019
e6f1f56
Fixed hostname
Toflar Mar 14, 2019
1c66c58
Fixed port
Toflar Mar 14, 2019
5faba60
Also show ls error and access logs on travis failure
Toflar Mar 14, 2019
9aea459
Fixed logs location
Toflar Mar 14, 2019
d6c23be
Testing for travis
Toflar Mar 14, 2019
3ca287b
Properly configured LSWS
Toflar Mar 14, 2019
0c977c4
Make sure cache constraint is case insensitive
Toflar Mar 19, 2019
8061f40
Revamped the docs
Toflar Mar 19, 2019
595bc28
Removed the whole file generation complexity in preparation of new LS…
Toflar Mar 19, 2019
292e1f6
Simplified vhost config
Toflar Mar 19, 2019
b14416b
Finally got LS running on Travis!
Toflar Mar 19, 2019
8b6b30a
Added support for more than one baseUri in HttpDispatcher
Toflar Mar 20, 2019
3e934af
Prepared the rest of the functional tests for LS
Toflar Mar 20, 2019
c6def7b
CS
Toflar Mar 20, 2019
5f160db
Be more explicit about the configured baseUri
Toflar Mar 20, 2019
9cd041e
Use preuse OLS
Toflar Mar 21, 2019
1965229
Testing purge endpoint
Toflar Mar 21, 2019
3446a94
OLS purge endpoint is now not protected by basic auth only
Toflar Mar 25, 2019
9f7da19
Test
Toflar Apr 1, 2019
4a463d7
Adjusted to latest OLS changes in preuse and made purgeuri configurable
Toflar Apr 1, 2019
08a2e61
Disabled checking the cache for requests with cookies by default
Toflar Apr 1, 2019
1ddf540
Test
Toflar Apr 1, 2019
5f27838
Updated to latest pre-use with new features
Toflar Apr 12, 2019
00f0d34
CS
Toflar Apr 12, 2019
7377f78
Adjusted configuration to latest preuse binary again
Toflar Apr 25, 2019
ea56c81
Only use one LS worker
Toflar Apr 25, 2019
46e3742
Fixed missing serverName
Toflar May 2, 2019
238377e
Make sure fixtures send correct Content-Length header
Toflar May 3, 2019
2c8d102
Test
Toflar May 3, 2019
df5a9d8
Isolate tests
Toflar May 3, 2019
45962f6
Reenable tests
Toflar May 3, 2019
b92e8f0
CS
Toflar May 3, 2019
8def743
Docs
Toflar May 14, 2019
9faed6a
Merge branch 'master' into litespeed
Toflar Nov 29, 2019
8566017
Added a hint about LSWS not supporting cache tag invalidation atm
Toflar Nov 29, 2019
c010741
Update OLS to latest stable
Toflar Nov 29, 2019
48ed17d
Remove leftover
Toflar Nov 29, 2019
0ff8676
Let's try to wait longer
Toflar Nov 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ install:
before_script:
# Install Varnish
- |
set -e
curl -L https://packagecloud.io/varnishcache/varnish${VARNISH_VERSION//./}/gpgkey | sudo apt-key add -
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
cat /etc/apt/sources.list
Expand All @@ -71,6 +70,8 @@ before_script:
- if [ "$VARNISH_MODULES_VERSION" != "" ]; then sh ./tests/install-varnish-modules.sh; fi
# Install NGINX
- sh ./tests/install-nginx.sh
# Install OpenLiteSpeed
- sh ./tests/install-openlitespeed.sh

script:
- composer validate --strict --no-check-lock
Expand All @@ -87,3 +88,5 @@ after_failure:
- sudo cat /var/log/apache2/error.log
- sudo cat /var/log/apache2/access.log
- sudo cat /var/log/apache2/other_vhosts_access.log
- for errorlog in '/usr/local/lsws/logs/error.log*'; do sudo cat $errorlog; done
- sudo cat /usr/local/lsws/logs/access.log
2 changes: 2 additions & 0 deletions doc/cache-invalidator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Create the cache invalidator by passing a proxy client as
// or
$client = new ProxyClient\Nginx(...);
// or
$client = new ProxyClient\LiteSpeed(...);
// or
$client = new ProxyClient\Symfony(...);
// or, for local development
$client = new ProxyClient\Noop();
Expand Down
153 changes: 153 additions & 0 deletions doc/litespeed-configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
.. _litespeed configuration:

LiteSpeed Configuration
-----------------------

Below you will find detailed LiteSpeed configuration recommendations for the
features provided by this library.

Preamble
~~~~~~~~

First of all, let's get one thing straight here: You'll find a lot of documentation
and noise around LiteSpeed cache on the Internet, mostly involving plugins, specifically the
Wordpress one. You **don't** need any plugin to benefit from LiteSpeed cache!
As long as you follow the HTTP specification regarding the caching headers, you can use it as
a general reverse proxy just like NGINX or Varnish.

LiteSpeed comes in two different variants:

* OpenLiteSpeed (OLS) - the open source product with less features
* LiteSpeed Web Server (LSWS) - the enterprise version with more features and professional support

The caching module implementations are different and thus have to be configured differently.
Currently, OLS does support cache tagging and cache tag invalidation and LSWS does not. However, LSWS supports ESI
whereas OLS does not.

So before you start configuring the server, make sure you know which version of LiteSpeed you are using.

.. note::

Any LiteSpeed setup works in a single node web server environment only. If you are targeting a multi
node setup you might want to consider switching to :ref:`Varnish <varnish configuration>` which has excellent
support for this already built-in in this library.


Configuring OpenLiteSpeed
~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::

You need at least OpenLiteSpeed version 1.4.47

OLS does not support different caching settings depending on ``.htaccess`` settings and different paths.
If you need that, you have to go with LSWS instead.
Thus, OLS has to be configured as follows on server or vHost level::

module cache {
# This enables the public cache
enableCache 1

# This disables the private cache
enablePrivateCache 0

# This enables the public cache
checkPublicCache 1

# This disables the private cache
checkPrivateCache 0

# Also consider the query string in caches
qsCache 1

# Disable checking for a cached entry if there's a cookie on the request
reqCookieCache 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't support user context caching with litespeed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. User context caching requires some kind of preflight request to the app to find out the context which requires implementation in the proxy.


# We ignore request Cache-Control headers
ignoreReqCacheCtrl 1

# Must be disabled, this tells LS to check the Cache-Control/Expire headers on the response
ignoreRespCacheCtrl 0

# We don't cache responses that set a cookie
respCookieCache 0

# Configure the maximum stale age to a sensible value for your application
# The maxStaleAge defines a grace period in which LS can use an out of date (stale) response while checking on a new version
maxStaleAge 10

# Make sure we disable expireInSeconds because it would override our Cache-Control header
expireInSeconds 0

# If you want to use cache invalidation by cache tags, configure the general PURGE endpoint here.
# By default, this library is configured to use "/_fos_litespeed_purge_endpoint". If you'd like to
# have a different one, configure it here accordingly and make sure you configure the same URI
# in the library itself (see further down this page). Also make sure you don't overlook trailing slashes here!
purgeuri /_fos_litespeed_purge_endpoint

# Enable the module
ls_enabled 1
}

That's all you need. Of course you might want to adjust certain values to your needs.
Also refer to the OLS docs if you need more details about the different configuration values.

Configuring LiteSpeed WebServer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. warning::

Unfortunately LSWS does currently not support invalidating cache tags.

Configuring FOSHttpCache to work with LiteSpeed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Because LiteSpeed does not support a multi node setup configuring the proxy client is pretty straight forward if
you serve your application only on one domain::

use FOS\HttpCache\ProxyClient\HttpDispatcher;
use FOS\HttpCache\ProxyClient\LiteSpeed;

$servers = ['127.0.0.1'];
$baseUri = 'example.com';
$httpDispatcher = new HttpDispatcher($servers, $baseUri);

$litespeed = new LiteSpeed($httpDispatcher);

If you need multiple domains, make your ``$baseUri`` an array like so::

use FOS\HttpCache\ProxyClient\HttpDispatcher;
use FOS\HttpCache\ProxyClient\LiteSpeed;

$servers = ['127.0.0.1'];
$baseUris = ['example.com', 'foobar.com'];
$httpDispatcher = new HttpDispatcher($servers, $baseUris);

$litespeed = new LiteSpeed($httpDispatcher);


If you configured your LiteSpeed instance to use a different ``purgeuri`` than ``/_fos_litespeed_purge_endpoint`` also
make sure to pass the configured URI like so::

use FOS\HttpCache\ProxyClient\HttpDispatcher;
use FOS\HttpCache\ProxyClient\LiteSpeed;

$servers = ['127.0.0.1'];
$baseUris = ['example.com', 'foobar.com'];
$httpDispatcher = new HttpDispatcher($servers, $baseUris);

$litespeed = new LiteSpeed($httpDispatcher, ['purge_endpoint' => '/your-uri');

Cache Tagging
~~~~~~~~~~~~~

If you want to use cache tagging please note that you cannot use the default settings of the ``ResponseTagger`` (which
by default uses ``X-Cache-Tags``) but instead you have to configure it to ``X-LiteSpeed-Tag`` like so::

use FOS\HttpCache\ResponseTagger;
use FOS\HttpCache\TagHeaderFormatter;

$formatter = new CommaSeparatedTagHeaderFormatter('X-LiteSpeed-Tag');
$responseTagger = new ResponseTagger(['header_formatter' => $formatter]);


16 changes: 16 additions & 0 deletions doc/proxy-clients.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Client Purge Refresh Ban Tagging Clear
============= ======= ======= ======= ======= =======
Varnish ✓ ✓ ✓ ✓
NGINX ✓ ✓
LiteSpeed ✓ ✓ ✓ ✓
Symfony Cache ✓ ✓ ✓ (1) ✓ (1)
Noop ✓ ✓ ✓ ✓
Multiplexer ✓ ✓ ✓ ✓
Expand Down Expand Up @@ -181,6 +182,21 @@ call `setPurgeLocation()`::
To use the client, you need to :doc:`configure NGINX <nginx-configuration>`
accordingly.

LiteSpeed Client
~~~~~~~~~~~~~~~~~

The LiteSpeed client sends HTTP requests with the ``HttpDispatcher``. Create the
dispatcher as explained above and pass it to the LiteSpeed client::

use FOS\HttpCache\ProxyClient\LiteSpeed;

$litespeed = new LiteSpeed($httpDispatcher);

.. note::

To use the client, you need to :doc:`configure LiteSpeed <litespeed-configuration>`
accordingly.

Symfony Client
~~~~~~~~~~~~~~

Expand Down
3 changes: 2 additions & 1 deletion doc/proxy-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Proxy Server Configuration
==========================

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

varnish-configuration
nginx-configuration
litespeed-configuration
symfony-cache-configuration
Loading