Files
RustProxy/docs/WEB_SERVER.md
T
2026-11-26 12:31:28 +01:00

109 lines
15 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Web Server — static sites, downloads and routing
The built-in Web Server serves local files and can forward executable scripts to **external PHP-FPM, fcgiwrap or generic FastCGI responders**. A reusable **Web Service** is referenced by a Vhost or by a Custom location. Its files and PHP settings are not duplicated in the Vhost.
## Create a Web Service
1. Open **Web Server → New Web Service**. Choose an ID/name and an absolute document root readable by the RustProxy service account.
2. Set index files (static default `index.html`, `index.htm`; when PHP-FPM for `.php` is enabled with that unchanged default, `index.php` is also tried last), whether directory listing is allowed (off by default), MIME handling and download extensions.
3. Add `try_files`, rewrites and response headers only if your application requires them. VCL-style cache rules (including `pass` / `cookie_pass`) are **not** evaluated for Web Server sources; the static-extension Cookie option and the regular cache policy still apply to local files.
4. Enable FastCGI only if you have a reachable, protected external PHP-FPM pool, CGI runner or compatible FastCGI responder; otherwise static files do not need an executable runtime.
5. Save, create or edit a **Vhost**, select **Web Server** as source and choose the service ID.
6. Test index files, static assets, missing files, direct directory access, downloads and headers.
A Web Service can be shared across several Vhosts. A Vhost may also use ordinary Reverse Proxy as its default and a Web Service for `/assets` or another custom location. Web Server and HTTP reverse proxy use the normal frontend TLS, access, logging and eligible cache pipeline.
**Linux DEB/RPM paths:** With the updated package unit, `/home/user/public_html`,
`/var/www/site` and `/srv/site` are readable using an appropriately scoped
service-user group or POSIX ACL; no `systemctl edit` or
`ReadOnlyPaths=` exception is needed. The filesystem remains read-only to the
service outside its private state/log/config paths. Grant execute/traversal
on each parent directory and read permission on served files; see
[Installation: external paths](INSTALL.md#linux-debrpm-read-only-access-to-external-paths).
### Generated filesystem permission commands
As you enter an absolute **Document root**, the editor generates permission commands immediately below the path. They refresh when opening or clearing a service, applying a preset or changing the root, so the displayed commands refer to the current field. The path must not contain `.`/`..` components or control characters and must resolve to an existing directory when the commands run; `/` is not accepted. Install the Linux `acl` tools if needed, review the commands and run them as an administrator on the web server. Saving a Web Service does not execute shell commands or grant filesystem permissions.
The helper grants the `rustproxy` service account traversal (`--x`) of parent directories, read/traversal (`r-x`) on the website's directories and read (`r--`) on regular files. Symlinked document roots are resolved when the commands run, so both the configured path and the target's ancestors can be traversed. Symlinks within the served tree are not followed by the permission walk. Read-only ACLs do not grant writes or relax the Web Service's own symlink policy. Keep private content outside the document root.
Default read/traverse ACLs are added to the existing website directories for newly created content. Default ACL inheritance takes precedence over the creator's `umask`; missing defaults are seeded from the directory's existing permissions. Explicit restrictive creation modes can still mask RustProxy's read access. Files moved into the tree or installed with preserved permissions may need the commands reapplied. Repeat the commands after a deployment changes the document-root symlink target. For a custom service account, change **Service user** under **Options and help** before copying; this changes only the instructions, not the process identity or saved configuration.
For PHP applications, the separate **PHP-FPM pool user** needs its own access to scripts and any writable application directories. The generated RustProxy ACLs do not configure that user. Files must also be visible within the service's container/systemd namespace and permitted by SELinux/AppArmor if used; filesystem ACLs cannot override those policies.
## File serving options
| Feature | Behavior / caution |
|---|---|
| **Document root** | Files are served only through the configured root; keep private keys, source secrets and writable control files outside it. |
| **Indexes / listing** | Configurable index priority; directory listing is disabled by default. |
| **`try_files`** | Try requested paths, then a fallback such as `/index.html` or the PHP front controller. Useful for SPAs and frameworks. |
| **Rewrites** | Bounded regex internal rewrites or supported redirect statuses; evaluated in the Web Service routing pipeline. |
| **MIME / downloads** | Built-in type mapping with extensions and explicit attachment options. |
| **Headers / cache** | Service-level headers and optional static cache-control rules; later Vhost/location response rules may override. |
| **Compression** | Dynamic gzip/Brotli/Zstandard/deflate policy and eligible precompressed `.br`/`.gz` sidecars. |
| **File validators / ranges** | Conditional `ETag`/date checks, HEAD and supported byte ranges for eligible files. |
| **Symlinks** | `deny` by default; `inside_root` is an explicit less restrictive policy. |
| **Hardening** | Optional checks for common sensitive/attack paths and removal of selected server-identifying headers; not a full WAF. |
### Static delivery (`sendfile`)
In **Web Server → Edit service → Delivery**, `sendfile` supports `off` (default) and `auto`. On **Linux**, eligible full static **GET** responses of at least **64 KiB** over **unencrypted HTTP/1.1** may use a kernel file-transfer path. TLS, HTTP/2, HTTP/3, ranged or transformed content, compressed responses and active object-cache responses keep the normal streaming path. This transport choice should not invalidate otherwise compatible cached objects. Measure on your own hardware before enabling it; see [Performance](PERFORMANCE.md).
## Rewrites and application presets
The editor supports common website presets to fill suggested fields; review their document root, `try_files`, MIME and PHP values before saving. The two independent hardening checkboxes (block common attack probes and remove fingerprinting headers) are directly below the preset selection and Apply action; the chosen values remain editable. Presets do not install WordPress, Roundcube or other applications. For a single-page app, a fallback similar to `$uri`, `$uri/`, `/index.html` serves the SPA entry for routes without an existing file. For PHP frameworks, use the appropriate front controller; see [PHP-FPM](PHP_FPM.md).
## `.htaccess` compatibility
An optional bounded Apache-style `.htaccess` compatibility layer supports a **subset** of rules useful for migrations, not arbitrary Apache modules or dynamic directive execution. It can scan configured paths and enforce stricter handling of unsupported expressions. Prefer explicit `try_files`/rewrite/header controls when possible and test migrated sites. A real Apache configuration cannot be pasted unchanged into RustProxy.
With **Strict unsupported-directive mode disabled**, unimplemented directives (such as unsupported `Options` tokens) are skipped and logged as warnings during Web Service validation/apply; inspect the server logs or expand **.htaccess compatibility warnings** on the Web Service card for file/line locations. They do **not** become active Apache functionality. Unsupported security/handler syntax is still rejected to avoid unintentionally exposing protected content.
`RedirectMatch 404 /\.` is accepted as a **status-only rule**: a matching request returns HTTP 404 without a `Location` header. `Redirect gone /old` and `RedirectMatch 410 <regex>` similarly return HTTP 410, while ordinary `Redirect 301 /old /new` and `RedirectMatch 302 <regex> /replacement` retain redirect behavior. This works without `RewriteEngine`. Safety filters for protected paths still run before rewrites and can return 403 for a hidden or otherwise forbidden file.
**PHP routing using `.htaccess`:** `RewriteEngine`, `RewriteBase` (absolute safe URL prefix), `RewriteCond` and `RewriteRule` are active. `AcceptPathInfo On` enables script suffix routing such as `index.php/devices/42/` even if the Web Service FastCGI **PATH_INFO** toggle is off. `AcceptPathInfo Off` disables it, even if that toggle is on; `Default` restores the Web Service toggle. These settings apply to eligible FastCGI script files, not arbitrary static files. RustProxy preserves the rewritten suffix, including the trailing `/`, in the FastCGI `PATH_INFO`; `SCRIPT_FILENAME` still refers only to the existing executable file under the document root. PHP-FPM must be enabled with the correct socket and `.php` extension. If an `.htaccess` rule rewrites to `.php` but that handler is missing, Web Service validation now produces an explicit warning rather than silently accepting a non-functional front controller. The stock Web Service index list additionally tries `index.php` *last* when PHP-FPM for `.php` is enabled, while explicit index lists are unchanged. An `.htaccess` edit requires re-applying the service.
`ErrorDocument 404 /error.php?404` and other **local** `ErrorDocument` targets (HTTP 400–599) are supported for GET/HEAD. RustProxy performs one internal Web Service request for the error document and preserves the original error status when the document succeeds. The same filesystem and security controls apply to that document; recursive error handling is prohibited. External URL targets and custom literal error messages are not supported. Errors from other methods keep their built-in error response. `Options FollowSymlinks` and `Options MultiViews` are **not** equivalent to RustProxy's symlink policy and Apache content negotiation: they are still warned/skipped with Strict off. `Options -MultiViews` is accepted because MultiViews is not enabled. Do not assume these options are active.
**Example of a front controller with `PATH_INFO`:**
```apache
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/ [L]
AcceptPathInfo On
ErrorDocument 404 /error.php?404
```
For application-specific route exclusions, remember that `%{REQUEST_URI}` begins with `/`; use `!^/api/` rather than `!^api/` when excluding `/api/` URLs. A rule containing `RewriteCond %{REQUEST_URI} !\.php` prevents repeatedly rewriting `/index.php/...` on subsequent passes. See [FastCGI](FASTCGI.md).
For common Apache 2.2 migrations, `Order deny,allow`, `Order allow,deny`, `Order mutual-failure`, `Allow from all` / `Deny from all`, and `Allow from` / `Deny from` explicit IP addresses or CIDR networks (IPv4/IPv6) are supported and **enforced** using the actual client IP. For instance, `Deny from all` blocks the affected directory, returning HTTP 403; it is not silently ignored. `Order allow,deny` denies unmatched clients by default, while `Order deny,allow` allows them by default. Hostname-based ACLs and other unsupported access/authentication constructs fail validation even with Strict disabled. Test allow/deny cases after migrating; legacy access rules are not a general Apache authorization emulator.
## Admin editor layout
In **Web Server → Edit → Delivery**, static file delivery, dynamic compression and precompressed assets have separate sections. In **PHP-FPM**, profile/endpoint, request options, resource limits and FastCGI/php.ini overrides are grouped. Disabled local controls indicate that PHP is off or a shared profile owns those settings; selection and saved values behave as before.
## FastCGI and error responses
A Web Service may use external PHP-FPM, fcgiwrap or another FastCGI responder via its local settings or an existing shared profile. RustProxy does not execute scripts itself. Combine multiple Web Services (distinct document roots, extensions and endpoints) using Vhost Custom locations; see the generic [FastCGI guide](FASTCGI.md). Existing PHP-FPM pool isolation rules continue to apply; see [PHP-FPM](PHP_FPM.md).
Missing static files return **HTTP 404 Not Found**, unreadable/blocked paths **403 Forbidden**, unsupported static methods **405 Method Not Allowed** (with `Allow: GET, HEAD`), and internal failures **500 Internal Server Error**. The built-in Web Server now uses the existing **application-style HTML error pages** for statuses with a bundled template (including 400, 403, 404, 500 and PHP-FPM gateway errors). Other generated error statuses, such as 405, use the shared styled HTML fallback. The regular built-in 502 is styled with RustProxy branding; auth-specific Tinyauth failure pages have their own wording and are served before any origin application is accessed. Neither internal filesystem paths nor `RustProxy: Web Server ...` diagnostics are included in the public body. Details for 5xx filesystem failures remain in server logs.
These generated HTML responses retain the actual HTTP status, `Content-Type: text/html; charset=utf-8`, `X-Content-Type-Options: nosniff` and `Cache-Control: no-store`; `HEAD` preserves the matching `Content-Length` but sends no body. Explicit application/origin responses are still passed through without forced replacement, subject to the Vhost error interception options below.
Vhosts can intercept selected application error bodies in **Pages** and return a configured HTML error page while preserving the status. Internal location `error_fallback` is different: it routes the error to a named internal handler. Error-page replacements are marked uncacheable. Origin-supplied and explicitly configured custom error bodies are preserved unless interception is enabled.
## Monitoring and issues
A Web Service's dashboard shows request rate, status/error counts, response-header timing, delivered bytes and PHP permit usage (when PHP is configured). These are application observations, not proof of external PHP worker count or final compressed network bytes.
- **403 / unexpected block:** inspect document-root permissions (including parent traversal), symlink policy, hardening, inherited ACLs and any SELinux/AppArmor denial; verify the active systemd unit is the updated one.
- **404 / unwanted SPA rewrite:** check actual files, index list, `try_files`, location matching and rewrite order.
- **Wrong Content-Type/download:** check MIME override and attachment extensions.
- **PHP script downloaded instead of executed:** check PHP enablement, script extension and FPM endpoint.
- **Cache not filling:** inspect both global and Vhost cache, static response headers and cookies.
Keep all document roots and external application processes separately patched and secured.