• 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 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 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