- Server operating system version
- Ubuntu 22.04
- Plesk version and microupdate number
- 18.0.68
Hello everyone,
I’m encountering a problem with setting up dynamic CORS headers in our Plesk environment for our Capacitor-based React application. While the app works perfectly in a browser, the iOS simulator reports the following error:
I’ve attempted to configure the necessary CORS headers via Plesk’s additional NGINX directives (in the location context) using conditions like:
Additionally, I tried handling OPTIONS requests within the same block. However, I’m running into errors such as:
and duplicate location errors when adjusting the configuration.
It appears that Plesk’s configuration context for additional directives limits where add_header can be applied. In previous versions (around two years ago) our application worked without issue, so it seems something might have changed in the configuration or Plesk version.
Has anyone faced this issue recently? I’m looking for a solution or workaround that allows me to dynamically set the CORS header (specifically to allow requests from the capacitor://app origin) without encountering the “add_header directive is not allowed here” error. I’m open to suggestions on whether it’s possible to modify Plesk templates or if there’s an alternative approach (e.g., handling this within our application’s API code) that would better suit our environment.
Any help or guidance would be greatly appreciated.
Thanks in advance,
I’m encountering a problem with setting up dynamic CORS headers in our Plesk environment for our Capacitor-based React application. While the app works perfectly in a browser, the iOS simulator reports the following error:
Code:
Origin capacitor://app is not allowed by Access-Control-Allow-Origin.
I’ve attempted to configure the necessary CORS headers via Plesk’s additional NGINX directives (in the location context) using conditions like:
Code:
if ($http_origin = "capacitor://app") {
add_header "Access-Control-Allow-Origin" "$http_origin" always;
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, PUT, DELETE" always;
add_header "Access-Control-Allow-Headers" "Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,If-Modified-Since,Accept-Encoding" always;
}
Additionally, I tried handling OPTIONS requests within the same block. However, I’m running into errors such as:
Code:
nginx: [emerg] "add_header" directive is not allowed here
and duplicate location errors when adjusting the configuration.
It appears that Plesk’s configuration context for additional directives limits where add_header can be applied. In previous versions (around two years ago) our application worked without issue, so it seems something might have changed in the configuration or Plesk version.
Has anyone faced this issue recently? I’m looking for a solution or workaround that allows me to dynamically set the CORS header (specifically to allow requests from the capacitor://app origin) without encountering the “add_header directive is not allowed here” error. I’m open to suggestions on whether it’s possible to modify Plesk templates or if there’s an alternative approach (e.g., handling this within our application’s API code) that would better suit our environment.
Any help or guidance would be greatly appreciated.
Thanks in advance,