Can Nginx force multiple location? matches

such as

    location /api {
      add_header "Access-Control-Allow-Origin" "*";
    }
    location ~ [^/]\.php(/|$) {
      fastcgi_pass unix:/dev/shm/php-cgi.sock;
      fastcgi_index index.php;
      include fastcgi.conf;
    }

at this point, if you visit .php under api, there will be no add_header, and you can only rewrite a regular match, which is very disgraceful. Is there a good solution?

Nov.19,2021

  1. add an extra sentence to the regular rule add_header
  2. use include to reference from the same file
  3. (you can write this, but it is not officially recommended) nest the second location block inside the first block, but do more tests to ensure that parsed bug
  4. is not introduced.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c275-2b839.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c275-2b839.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?