v0.42.2_fix2

This commit is contained in:
Mateusz Gruszczyński committed 2026-11-26 13:06:54 +01:00
1 parent 25148f26eb
commit a75893d428
16 files changed
+301 -66

No files matched your search

+2
View File
@@ -75,6 +75,8 @@ Example — beta testers by header, office network with a staff cookie for the w
- **Local response:** return a chosen `200–599` status, content type and body without connecting to an origin. `HEAD`, `204` and `304` do not return a body.
- **Redirect:** issue `301`, `302`, `303`, `307` or `308` to a valid absolute HTTP(S) target. Query preservation is configurable. Redirect rewrite expressions may reference regex captures.
**Web Service Vhosts do not need a Reverse Proxy backend** just to use a Redirect or Local response location. Only the main Reverse Proxy source or an enabled Proxy location requires a backend pool. To redirect only `/` to an application prefix, choose **Exact** match for `/` (not Prefix `/`, which also matches application subpaths), **Redirect**, and a code such as **302** with an absolute destination URL.
### Path rewriting
`preserve` forwards the original path, `strip_prefix` removes the matched prefix, `replace_prefix` substitutes a new normalized prefix and `regex` rewrites using captures such as `$1` or `${name}`. Queries remain intact unless a redirect explicitly changes handling. Public cache keys are based on the client-facing URL, not an internal rewritten backend path.
+44
View File
@@ -68,6 +68,50 @@ The exact and regex rules use Rust's `regex` syntax, not PCRE look-arounds. `str
**Protect access:** Enable **Vhost Basic Auth** if the application needs it, using the existing RustProxy credential settings (or another supported authentication provider; only verified Vhost Basic Auth currently maps to `REMOTE_USER`). Avoid publishing admin/CGI directories as static paths. `deny all` for hidden files can be implemented with Vhost ACL/location rules and optional `.htaccess` security rules. Server-level HTTPS, certificate renewal, IPv6 listeners and access/error logging are configured through RustProxy listeners/Vhosts/logs, not inside FastCGI settings.
## Nagios Core: PHP pages and CGI checks under `/nagios/`
The following is a **site-specific example** of the generic three-service arrangement above. It replaces common Angie/Nginx rules for a Nagios Core UI; the FastCGI engine does not contain any Nagios-specific code. Adjust paths and socket names to your installation.
**Prerequisites:** Nagios static/PHP files are under `/usr/local/nagios/share/`, executable CGI files under `/usr/local/nagios/sbin/`, PHP-FPM is listening on `unix:/run/php/php8.3-fpm.sock` and fcgiwrap on `unix:/run/fcgiwrap.socket`. Verify that the RustProxy operating-system account can read the site, traverse both document roots and connect to both Unix sockets. Do not change socket permissions to world-writable as a workaround. CGI programs may require Nagios-specific OS users/groups to read status data.
1. Under **Web Server → FastCGI profiles**, create `nagios-php` with **handler `php_fpm`**, enabled, endpoint `unix:/run/php/php8.3-fpm.sock`, executable extensions `php` and public `SCRIPT_NAME` prefix `/nagios`. Leave `PHP_VALUE` / `PHP_ADMIN_VALUE` at defaults unless the PHP-FPM pool genuinely needs overrides.
2. Create `nagios-cgi` with **handler `fcgiwrap`**, enabled, endpoint `unix:/run/fcgiwrap.socket`, executable extensions `cgi`, public `SCRIPT_NAME` prefix `/nagios/cgi-bin`, and `PATH_INFO` disabled unless a specific script uses it. This handler does **not** use `PHP_VALUE` or `PHP_ADMIN_VALUE`.
3. Create these **Web Services** (the profile and service are separate objects):
| Web Service ID | Document root | Shared profile | Index files | `try_files` |
|---|---|---|---|---|
| `nagios-web` | `/usr/local/nagios/share` | `nagios-php` | `index.php`, `index.html`, `index.htm` | `$uri`, `$uri/`, `=404` |
| `nagios-cgi-scripts` | `/usr/local/nagios/sbin` | `nagios-cgi` | none | `$uri`, `=404` |
| `nagios-empty` | An existing, empty directory such as `/srv/rustproxy/empty` | disabled | none | `=404` |
Keep `symlink_policy=deny` for executable Web Services. The empty default service avoids accidentally exposing the same files outside `/nagios/`.
4. Create a **Vhost** for `n.linuxiarz.pl` on HTTP and HTTPS listeners. Use `nagios-empty` as the default Web Server source; configure a TLS certificate (RustProxy ACME or imported), HTTPS redirection and HTTP/2 as required. Configure Vhost **Basic Auth** with users managed by RustProxy. The Angie `auth_basic_user_file` directive is **not** read automatically; verified Vhost Basic Auth is what supplies `REMOTE_USER` / `AUTH_USER` to CGI. Only enable `pass_authorization` when a script requires `HTTP_AUTHORIZATION`.
5. In **Vhost → Custom locations**, add these entries in the order shown. Choose action **Web Server** for the two service routes, **Redirect** for the first two, and **Local response** for the hidden-file deny. Enter full HTTPS URLs for redirect targets (the Custom location redirect editor requires an absolute URL).
| Match | Pattern | Action / target | Path rewrite |
|---|---|---|---|
| `exact` | `/` | `302` to `https://n.linuxiarz.pl/nagios/` | — |
| `exact` | `/nagios` | `301` to `https://n.linuxiarz.pl/nagios/` | — |
| `regex` | `^/nagios/(?:[^/]+/)*\.[^/]+(?:/|$)` | Local response `403`, no content | — |
| `regex` | `^/nagios/cgi-bin/(.*\.cgi)$` | Web Service `nagios-cgi-scripts` | `regex` → `/$1` |
| `prefix` | `/nagios/` | Web Service `nagios-web` | `strip_prefix` |
The hidden-file rule must be tested before the CGI regex so a dot-prefixed executable cannot bypass it. An additional PHP-specific regex is **unnecessary** here: `nagios-web` serves static files and dispatches `.php` to its PHP-FPM profile. If you need different PHP socket/root rules, use an additional PHP-specific Web Service and a regex Custom location instead.
**Expected mapping:** `GET /nagios/` finds `/usr/local/nagios/share/index.php` (or the configured existing index), `GET /nagios/stylesheets/style.css` stays static, and `GET /nagios/cgi-bin/status.cgi?host=all` selects the CGI Web Service. The latter sends `SCRIPT_FILENAME=/usr/local/nagios/sbin/status.cgi`, `SCRIPT_NAME=/nagios/cgi-bin/status.cgi`, original `REQUEST_URI`, `QUERY_STRING=host=all` and `REMOTE_USER` when RustProxy Basic Auth has successfully authenticated the user. Do **not** add `$1` expressions into Custom FastCGI parameters: core script and identity fields are calculated safely by RustProxy.
Verify after applying the configuration:
```bash
curl -I http://n.linuxiarz.pl/
curl -Ik https://n.linuxiarz.pl/nagios
curl -ik -u operator https://n.linuxiarz.pl/nagios/
curl -ik -u operator 'https://n.linuxiarz.pl/nagios/cgi-bin/status.cgi?host=all'
curl -Ik https://n.linuxiarz.pl/nagios/.htaccess
```
Expect redirects for `/` and `/nagios`, a Basic Auth challenge without credentials, a PHP/static page for `/nagios/`, FastCGI output (not CGI source code) for the CGI URL, and `403` for dotfiles (a Basic Auth challenge may happen first). A `502` suggests a missing backend/socket or bad socket permissions; a `403` can also mean the script is inaccessible/non-executable, and `404` can mean a wrong rewrite or document root. The exact Nagios page may require additional stylesheets/aliases or Nagios-specific CGI environment and permissions. Test these against a real installed Nagios, not only a mock FastCGI server.
## Migrating from Nginx / Angie
| Original directive | RustProxy equivalent |
+1 -1
View File
@@ -63,7 +63,7 @@ Under **Vhosts → Edit → Security → Country access**, choose `Off`, `Block`
- **Reverse Proxy:** one Vhost has a backend pool. Each member has a configured URL, ID, enabled flag, weight, optional backup/drain state, health settings and capacity limits.
- **Web Server:** Vhost references a Web Service by ID. Its document root, directory handling, PHP options and static-file headers remain configured under **Web Server**.
- **Custom locations:** can override selected URL paths and use the default pool, a backend group with its own balancing, a pinned backend, a different Web Service, a redirect or a local response. Unmatched paths still use the main source. Locations and whole-host rules can also require conditions on headers, cookies, query parameters, method, client IP, host or country — see [Request conditions](CUSTOM_LOCATIONS.md#request-conditions-routing-by-header-cookie-ip).
- **Custom locations:** can override selected URL paths and use the default pool, a backend group with its own balancing, a pinned backend, a different Web Service, a redirect or a local response. Unmatched paths still use the main source. Locations and whole-host rules can also require conditions on headers, cookies, query parameters, method, client IP, host or country — see [Request conditions](CUSTOM_LOCATIONS.md#request-conditions-routing-by-header-cookie-ip). A Web Server Vhost needs **no proxy backend** when its custom locations are solely local redirects, responses or other Web Services; an enabled Reverse Proxy location still needs a backend.
Sample documents in `examples/vhosts-private.json` and `examples/vhosts-balanced.json` illustrate JSON formats, but their IP addresses, certificates and health endpoints are examples only.