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

+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 |