Skip to content

Add nginx X-Accel-Redirect support, Redis cache provider, and author access fix#433

Open
Erik-NA wants to merge 6 commits intoGM-Alex:nextfrom
Erik-NA:feature/nginx-xaccel-redis
Open

Add nginx X-Accel-Redirect support, Redis cache provider, and author access fix#433
Erik-NA wants to merge 6 commits intoGM-Alex:nextfrom
Erik-NA:feature/nginx-xaccel-redis

Conversation

@Erik-NA
Copy link
Copy Markdown

@Erik-NA Erik-NA commented Apr 6, 2026

Summary

  • nginx X-Accel-Redirect: FileHandler sends X-Accel-Redirect instead of X-Sendfile on nginx, with a /uam-files/ internal location prefix to avoid redirect loops. SettingsController::isXSendFileAvailable() returns true on nginx and shows the correct server-specific label in the UI (X-Accel-Redirect vs X-Sendfile). Apache gets a runtime fallback via apache_get_modules() if mod_xsendfile is absent.
  • nginx location regex fix: FileProtection::getDirectoryMatch() uses \d{4} instead of [0-9]{4} — nginx cannot parse character classes with quantifiers in location directives.
  • Redis cache provider: New RedisCacheProvider using the WordPress object cache API (wp_cache_*). Registered automatically when wp_using_ext_object_cache() is true. No configuration needed beyond a standard Redis Object Cache plugin.
  • Author access fix: AccessHandler::hasAuthorAccess() now guards against $currentUserId === 0, preventing unauthenticated users from gaining access to posts imported without an author (post_author = 0).

nginx configuration required

location ~ "^/wp-content/uploads/\d{4}/\d{2}" {
    rewrite ^([^?]*)$ /index.php?uamfiletype=attachment&uamgetfile=$1 last;
    rewrite ^(.*)\?(((?!uamfiletype).)*)$ /index.php?uamfiletype=attachment&uamgetfile=$1&$2 last;
    rewrite ^(.*)\?(.*)$ /index.php?uamgetfile=$1&$2 last;
}
location /uam-files/ {
    internal;
    alias /var/www/html/;
}

Replaces #432 (splitting as requested).

GM-Alex and others added 6 commits January 26, 2026 11:20
**nginx file delivery (X-Accel-Redirect)**
- FileHandler: send X-Accel-Redirect header on nginx instead of
  X-Sendfile, which nginx does not support natively
- SettingsController: enable xsendfile option on nginx without
  running the HTTP test (X-Accel-Redirect is always available)
- SettingsController: show lock_file_types setting on nginx (was
  incorrectly hidden)
- NginxFileProtection: add ~ flag and quote regex in location
  directive to produce valid nginx config when pattern contains
  curly braces (e.g. [0-9]{4})

**Redis cache provider**
- Add RedisCacheProvider implementing CacheProviderInterface,
  backed by the WordPress object cache API (wp_cache_*)
- Register provider automatically when wp_using_ext_object_cache()
  is true (i.e. a persistent backend such as Redis is active)
- Add language strings and update .pot file
… prefix

[0-9]{4} in a nginx location directive fails to match even when quoted,
because nginx's PCRE engine does not interpret character classes with
quantifiers correctly in this context. Replace with \d{4}/\d{2} which
works reliably.

Also prefix X-Accel-Redirect URI with /uam-files/ to avoid an internal
redirect loop: without this, nginx redirects back to the UAM location
block, which rewrites to index.php again, causing a rewrite cycle.
When a post has post_author=0 (e.g. imported without an author),
unauthenticated users (also ID=0) were incorrectly treated as the
post author, bypassing all group-based access restrictions.

Guard against userId=0 so that the author-access shortcut never
fires for unauthenticated visitors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lback

The download-type selector always showed "X-Sendfile" regardless of
web server. This was misleading and confusing on nginx.

- On nginx the option is relabelled to "X-Accel-Redirect" and stays
  enabled, because X-Accel-Redirect is always available on nginx
  without any extra module.
- On Apache the existing HTTP round-trip test still runs; if
  mod_xsendfile is absent the option is disabled as before.
- Added runtime fallback in FileHandler: if "xsendfile" is saved in
  the database but Apache's mod_xsendfile is not loaded at request
  time (e.g. after a server migration), delivery silently falls back
  to fopen instead of returning an empty response.
- Added LabelTrait::setLabel() to allow relabelling form values.
- Added TXT_UAM_DOWNLOAD_TYPE_XACCELREDIRECT language string and .pot
  entry.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants