• Dear Pleskians! The Plesk Forum will be undergoing scheduled maintenance on Monday, 7th of July, at 9:00 AM UTC. The expected maintenance window is 2 hours.
    Thank you in advance for your patience and understanding on the matter.

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