title: nginx ignores location definitions using regular expressions
body: <p>I got the following domain configuration on my nginx server (nginx 1.2.1):</p>
  
  <pre><code>server {
  
      listen 80 default_server;
  
      server_name example.com;
  
      root /var/www/example.com;
  
      access_log /var/log/nginx/example.com.access.log;
      error_log /var/log/nginx/example.com.error.log;
  
      location ~ /content/(.*)\.(txt|md) {
          return 301 /error;
      }
  
      location ~ /tpl/(.*) {
          return 301 /error;
      }
  
      location ~ /sys/(.*) {
          return 301 /error;
      }
  
      location / {
          index index.php
          try_files $uri $uri/ /index.php;
      }
  
  }
  </code></pre>
  
  <p>As you can see, I want to disallow access to all <code>.txt</code>/<code>.md</code> files in my <code>content</code> directory as well as every access to my <code>/tpl</code> and <code>/sys</code> directories. But, nginx seems to ignore each one of these rules.</p>
  
  <p>So I tried something different, i.e.:</p>
  
  <pre><code>location ^~ /templates {
      return 404;
  }
  </code></pre>
  
  <p>As this works, I guess there's a precedence-problem. Does anybody know how the apply all 3 rules?</p>
  
  <p>Thanks!</p>
  
  <p>— Max</p>