我似乎无法弄清楚如何从 auth_basic 中排除特定位置。
server {
server_name example.com;
root /var/www/html;
index index.php;
auth_basic "Nein nein nein";
auth_basic_user_file .htpasswd;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
# this script needs free access and takes query string parameters
location /sub/script.php {
auth_basic off;
}
# this works fine
location /sub/a-javascript.js {
auth_basic off;
}
...
位置 /sub/script.php 需要免费访问。如果它只能允许 GET 请求它也很好。我的问题似乎是它之后的查询参数。
总是使用许多查询参数来请求脚本 script.php?param=something&other_param=somethingelse&etc=etc