• Hi, Pleskians! We are running a UX testing of our upcoming product intended for server management and monitoring.
    We would like to invite you to have a call with us and have some fun checking our prototype. The agenda is pretty simple - we bring new design and some scenarios that you need to walk through and succeed. We will be watching and taking insights for further development of the design.
    If you would like to participate, please use this link to book a meeting. We will sent the link to the clickable prototype at the meeting.
  • (Plesk for Windows):
    MySQL Connector/ODBC 3.51, 5.1, and 5.3 are no longer shipped with Plesk because they have reached end of life. MariaDB Connector/ODBC 64-bit 3.2.4 is now used instead.
  • Our UX team believes in the in the power of direct feedback and would like to invite you to participate in interviews, tests, and surveys.
    To stay in the loop and never miss an opportunity to share your thoughts, please subscribe to our UX research program. If you were previously part of the Plesk UX research program, please re-subscribe to continue receiving our invitations.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.

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