title: auth_basic off for a single controller in cakephp served by nginx (location and rewrite)
body: <p>I want to have unrestricted access to one of my controller in CakePHP.
  Below is the config I'm using, unfortunately, when trying myhost.com/my_controller/my_action it still requires credentials. Shouldn't /my_controller/my_action match <strong>location ^~ /my_controller/my_action</strong> instead of <strong>location ~ .php$</strong>?</p>
  
  <p>From what I understand from <a href="https://stackoverflow.com/questions/1011101/nginx-location-directive-doesnt-seem-to-be-working-am-i-missing-something">here</a> it should.</p>
  
  <p>I tried to incorporate above trick with <strong>if ($request_uri ~* /phpmyadmin)</strong>, but auth_basic is not allowed in IFs, I guess (Restarting nginx: [emerg]: "auth_basic" directive is not allowed here).</p>
  
  <p>I also tried to match rewritten location, i.e. <strong>location /index.php?q=/my_controller/my_action {</strong> but without a success.</p>
  
  <p>Exact operator "=" doesn't work as well, due to rewriting, I guess. The same with "~".</p>
  
  <p>Ideally, the solution should be generic enough to use with other controllers, too.</p>
  
  <pre><code>server {
      root
      index
  
      rewrite ^(.+)$ /index.php?q=$1 last;
  
      location ^~ /my_controller/my_action {
          auth_basic off;
          fastcgi_pass
          fastcgi_index
          fastcgi_param
          include
      }
  
      location ~ \.php$ {
          auth_basic "Restricted";
          auth_basic_user_file
  
          fastcgi_pass
          fastcgi_index
          fastcgi_param
          include
      }
  }
  </code></pre>