• 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 NINGX CORS for multiple sub.domains

s-light

New Pleskian
Server operating system version
linux (details currently unknown)
Plesk version and microupdate number
18.0.65
Hello community,

iam trying to add CORS related configuration to one subdomain configuration:
i found these two tutorials:



and try to make a multi-subdomain solution to work:

NGINX:
map $http_origin $origin_passed {
    hostnames;

    http:// myFirstDomain.de       1;
    https://myfirstdomain.de       1;
    *.myFirstDomain.de             1;
  
    http://anotherdomain.de               1;
    https://anotherdomain.de              1;
    *.anotherDomain.de                    1;
}

map $origin_passed $allow_origin {
    1  $http_origin;
}

map $origin_passed $allow_methods {
    1  "GET, POST, PUT, DELETE, HEAD, OPTIONS";
}

map "$origin_passed$request_method" $options {
    1OPTIONS  1;
}

        # nginx does not add headers if the content is empty.
        # so if the variables are empty (= $http_origin does not match)
        # these lines get ignored..
        add_header Access-Control-Allow-Origin $allow_origin;
        add_header Access-Control-Allow-Methods $allow_methods;

        # Handling preflight requests
        if ($options) {
            add_header Access-Control-Allow-Origin $allow_origin;
            add_header Access-Control-Allow-Methods $allow_methods;
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header Content-Type text/plain;
            add_header Content-Length 0;
            return 204;
        }

this is based on
- nginx config to enable CORS with origin matching
- How to Set Up Nginx with CORS for Multiple Origins

i removed the server and location block around this - as i think this sub-part will be included somewhere else...

with this i get the error message:

NGINX:
Invalid nginx configuration:
... lots more warnings ....
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in
    /etc/nginx/plesk.conf.d/vhosts/My-Domain-Name.de.conf:96
nginx: [warn] protocol options redefined for [xxxx:xxx:4242:4242::2]:443 in
    /etc/nginx/plesk.conf.d/vhosts/My-Domain-Name.de.conf:96
nginx: [warn] protocol options redefined for 42.42.42.42:443 in
    /etc/nginx/plesk.conf.d/vhosts/auto.another-domain.de.conf:7
nginx: [emerg] "map" directive is not allowed here in
    /var/www/vhosts/system/auto.another-domain.de/conf/vhost_nginx.conf:1
    nginx: configuration file /etc/nginx/nginx.conf test failed


i have no idea what all the warnings are doing there - but the last line - very difficult to spot - tells me i am not allowed to use the map directive...
ok so it seems i have to use another way?! but how and where?

iam open for any tips or ideas!

sunny greetings
stefan
 
Back
Top