Skip to main content

Contexts

Learning Focus

By the end of this lesson you will understand what contexts are, the different context types available, and how to use them for fine-grained request handling.

What Contexts Are

Contexts are path-based rules inside a virtual host. They let you change behavior for a specific URL path without redefining the entire site. Think of them as "this path gets special treatment."

Context Types

TypePurposeExample Use
StaticServe files from a specific directoryServe /assets/ from a CDN origin path
CGIExecute CGI scriptsLegacy Perl or Python scripts
ServletJava servlet mappingJava/Tomcat applications
ProxyForward requests to an upstreamProxy /api/ to a Node.js backend
RedirectRedirect a path to another URLSend /old-page to /new-page
App ServerLiteSpeed SAPI or LSAPICustom PHP app handler

Common Use Cases

Serve Static Assets from a Separate Directory

Map /images/ to a dedicated storage path:

SettingValue
URI/images/
TypeStatic
Location/var/www/shared-images/

Proxy a Backend Application

Route /api/ to a Node.js backend:

SettingValue
URI/api/
TypeProxy
Web Serverhttp://127.0.0.1:3000

Restrict Access to Admin Paths

Block public access to /wp-admin/ by IP:

SettingValue
URI/wp-admin/
Access ControlAllow your-ip, Deny all

Creating a Context in WebAdmin

  1. Navigate to Virtual Hosts → select your vhost
  2. Click ContextAdd
  3. Choose the context type (Static, Proxy, Redirect, etc.)
  4. Set the URI (the URL path to match)
  5. Configure the type-specific settings
  6. Save and Graceful Restart

Key Takeaways

  • Contexts are one of the most useful tools for fine-grained request handling.
  • Use them for static file mapping, proxying backends, redirecting paths, and access control.
  • Each context type has specific settings — match the type to your use case.

What's Next