• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

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