location /admin/ { auth_basic "Secure area"; auth_basic_user_file .htpasswd; error_page 404 = @admin; } location @admin { rewrite ^(.*)$ /admin/index.php last; }
给目录添加认证
auth_basic
但有伪静态显示404,解决方法:
https://serverfault.com/questions/808320/nginx-auth-basic-not-working-with-rewrite