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
| Type | Purpose | Example Use |
|---|---|---|
| Static | Serve files from a specific directory | Serve /assets/ from a CDN origin path |
| CGI | Execute CGI scripts | Legacy Perl or Python scripts |
| Servlet | Java servlet mapping | Java/Tomcat applications |
| Proxy | Forward requests to an upstream | Proxy /api/ to a Node.js backend |
| Redirect | Redirect a path to another URL | Send /old-page to /new-page |
| App Server | LiteSpeed SAPI or LSAPI | Custom PHP app handler |
Common Use Cases
Serve Static Assets from a Separate Directory
Map /images/ to a dedicated storage path:
| Setting | Value |
|---|---|
| URI | /images/ |
| Type | Static |
| Location | /var/www/shared-images/ |
Proxy a Backend Application
Route /api/ to a Node.js backend:
| Setting | Value |
|---|---|
| URI | /api/ |
| Type | Proxy |
| Web Server | http://127.0.0.1:3000 |
Restrict Access to Admin Paths
Block public access to /wp-admin/ by IP:
| Setting | Value |
|---|---|
| URI | /wp-admin/ |
| Access Control | Allow your-ip, Deny all |
Creating a Context in WebAdmin
- Navigate to Virtual Hosts → select your vhost
- Click Context → Add
- Choose the context type (Static, Proxy, Redirect, etc.)
- Set the URI (the URL path to match)
- Configure the type-specific settings
- 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
- Return to the Server Configuration module for the complete overview.