Help:Proxying with Contexts

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.

Using a proxy context to designate which traffic to proxy has the advantage of allowing you to easily set aside a location on your site to be proxied. More than that, though, it allows you to add the other functionality of a context — adding headers, requiring authorization, only authorizing certain users, etc. — on top of the proxying. This quick guide will take you through how to set up and test a proxy context (assuming you have already set up your web server external application).

Create a proxy context

Contexts only exist within virtual hosts, so you will need to have a vhost for the content you are proxying. For this guide we will be using the default virtual host, "Example".

WebAdmin console => Configuration => Virtual Hosts => your vhost => Context => Add => Type => Web Server

In the screenshot below, we have set the URI to /. We will be proxying all the locations on this site. We have set up our Web Server as the web server application we set up in the reverse proxy basics article, "apache".

Proxy-Context-Settings.png

Testing

Now that we have set up the context, we try a request to our site. A request to the main page (below) shows the default Apache page. Our backend Apache server is serving content for this site.

Proxy-toApache.png

But we haven't really set up this Apache installation. If we request the phpinfo.php page (below), we get a 404 not found. This page exists on our OpenLiteSpeed setup, but not on our Apache setup.

Proxy-toApache-404.png

Time to set up our content!