X-Headers or authentication checks - for reverse proxy apps

Hello,

I have the nextcloud with ownpad app.

My Etherpad is running on the same server with a reverse proxy in nextcloud apache vhost config. (see below)

I was trying to set the x-forwarded-user header to deny access to the /etherpad path if the apache REMOTE_USER variable is not set, but this variable is never set in apache when nextcloud to the etherpad from within nextcloud with the API.

Is there an option to allow nextcloud to set x-headers for apps with conditions?
Is there a way to add some authentication and redirects for this within nextcloud itself?

Maybe if someone has run into this issue and can provide some there solution.

RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} (^$) [L] <–
RewriteRule ^etherpad$ some_url [R=301]
RewriteRule ^etherpad.+$ / [R=403]

RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
RequestHeader add X-Forwarded-User %{RU}e

ProxyPass /etherpad http://127.0.0.1:9001
ProxyPassReverse /etherpad http://127.0.0.1:9001

example:
somenextcloud_server.com/etherpad would have unauthenticated access if etherpad has

“requireAuthentication” : false,

currently set to
"requireAuthentication" : true,

Would like to have a redirect to the nextcloud login page instead of getting the basic Authentication request from etherpad.

Many thanks,

Jon