• Halloween is coming! To celebrate the occasion, we dusted off a couple of old skins, and even created a brand new one (Pixel).
    To get into the festive spirit, install the Skins extension.
  • The new Python extension is now available. It allows customers to deploy and manage WSGI-based Python applications on their websites directly from Plesk.
  • The Plesk Mobile apps for iOS and Android and the Plesk Mobile Center extension have been deprecated, and are no longer available for new installations. In Plesk Obsidian 18.0.84, the Plesk Mobile Center extension will be removed from servers during the upgrade, and the Plesk Mobile apps will lose their server management features.
  • The Social Login extension has been deprecated and will be removed in Plesk Obsidian 18.0.84. After that, it will no longer be possible to log in to Plesk with a Google, Facebook, GitHub account, or with a passkey. Plesk usernames and passwords, as well as logging in with a WebPros Account, are not affected.

Question Issue Implementing Dynamic CORS Headers in Plesk’s Additional NGINX Directives

yfain

New Pleskian
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:

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,
 
Back
Top