When there are multiple "location" directives with regular expressions in them, nginx will stop looking after it finds the first match. This probably means that your PHP-specific "location" directive is never being evaluated in the first place. You can use PHP with arbitrary subdomains: see here. But I don't think it will work with your tilde-is-userdir scheme.