Help:Proxying with Script Handlers

From OpenLiteSpeed
Jump to: navigation, search

OpenLiteSpeed can be set up as a reverse proxy to a different server on the backend. This is done by designating that backend server as a web server external application in OpenLiteSpeed's settings. (This is covered in detail in the reverse proxy basics article.) Once that web server external application has been set up, OpenLiteSpeed needs to know which traffic to direct to that external application and thus proxy to the different backend.

Setting up a script handler mapped to your web server external application allows you to easily proxy certain types of requests (determined by the suffix used in the request). This can be a simple way to set up OpenLiteSpeed to handle most content, but send requests for certain special content (Java scripts or scripts that require Apache, to name two examples) to a different backend. In this guide we will demonstrate how to proxy html files to an Apache backend. This guide assumes that you have already set up a web server external application for an Apache backend (as shown in the reverse proxy basics article).

Create a script handler

WebAdmin console => Configuration => Server or Virtual Hosts => Script Handler => Add

A script handler tells OpenLiteSpeed to send requests for files with a specified suffix to a certain external application. If we create a script handler at the server level, it will apply to all vhosts.

In these settings, you need to choose the correct web server external application that you would like to do the proxying. The external application must be set up before the script handler can be created.

In our settings, we have chosen the suffix "html". If we want to proxy for more than one suffix, we can create multiple script handlers for one external application or we can specify multiple suffixes in the Suffix setting. (If you specify multiple suffixes, though, the script handler will only automatically register a MIME type for the first entry in the Suffix setting. You need to make corresponding MIME types in WebAdmin console => Configuration => General => MIME Settings. The format for the MIME types should be application/x-httpd-suffix. For this reason, it may be easier to just make multiple script handlers with one suffix each.)

Proxy-ScriptHandler-Settings.png

Testing

First we try to navigate to the default virtual host's homepage (which is an html file). Success. We get an Apache screen (below).

Proxy-toApache.png

But if we ask for a different kind of content (a PHP file, for example), it's still served by OpenLiteSpeed (below).

Proxy-serveLocal.png