title: Nginx sucessfully password protects PHP files, but then prompts you to download them
body: <p>In a <a href="https://stackoverflow.com/questions/37902392/password-protecting-files-in-a-folder-in-nginx-using-htpasswd/37902448">previous question,</a> I was trying to password protect my /admin/ and sub-folders directory using Nginx with .htpasswd and regex.</p>
  
  <p>That was done successfully, but now, after password authentication was completed, Nginx prompts to "download" php files, rather than simply loading them.</p>
  
  <p>This doesn't happen when the new location "authentication" block is commented out. For instance, in this code sample, PHP pages load without any issue:</p>
  
  <pre><code>    location / {
              try_files $uri $uri/ =404;
      }
  
      #location "~^/admin/.*$" {
      #       try_files $uri $uri/ =404;
      #       auth_basic "Restricted";
      #       auth_basic_user_file /etc/nginx/.htpasswd;
      #}
  
      location ~ \.php$ {
              try_files $uri =404;
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
      }
  </code></pre>
  
  <p>How can I resolve these (apparently conflicting) location blocks, so the /admin/ section is password protected yet php files still load?</p>