我想在 Shopware 的 DEV 安裝上設定 BasicAuth,以防止 Google/訪問者訪問該站點。我想保留沒有 BasicAuth 的管理區域,因為 SPA 后端不斷要求登錄許多 ajax 請求。簡而言之,BasicAuth 用于除“/admin”和“/api”之外的所有請求。
我已經嘗試使用以下配置。但即使是對“/admin”的請求,我也會收到密碼提示。
為什么一個位置的“auth_basic”會影響另一個位置?
server {
listen [--IP--]:80;
listen [--IP--]:443 ssl http2;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_certificate /var/www/clients/client1/web7/ssl/[--DOMAIN--].crt;
ssl_certificate_key /var/www/clients/client1/web7/ssl/[--DOMAIN--].key;
server_name [--DOMAIN--] ;
root /var/www/[--DOMAIN--]/web;
.
.
.
add_header X-Robots-Tag "noindex, nofollow" always;
location @rewriteapp {
root /var/www/[--DOMAIN--]/web/public/;
client_max_body_size 100M;
rewrite ^/(.*)$ /index.php last;
}
location /admin {
alias /var/www/[--DOMAIN--]/web/public/;
client_max_body_size 100M;
index index.php;
http2_push_preload on;
rewrite ^/(. )\.php/(.*)$ /$1.php last;
try_files $uri @rewriteapp;
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
.
.
.
http2_push_preload on;
}
}
location / {
alias /var/www/[--DOMAIN--]/web/public/;
client_max_body_size 100M;
index index.php;
http2_push_preload on;
rewrite ^/(. )\.php/(.*)$ /$1.php last;
try_files $uri @rewriteapp;
.
.
.
auth_basic "DEV";
auth_basic_user_file /var/www/clients/client1/web6/web/public/.htpasswd;
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
.
.
.
http2_push_preload on;
}
}
}
auth_basic off我也在“/admin”位置嘗試過。
auth_basic off;
allow all;
uj5u.com熱心網友回復:
嘗試這個:
server {
location ~ .php$ {
set $auth "Restricted";
if ($request_uri ~ /api/.*){
set $auth "off";
}
if ($request_uri ~ /admin.*){
set $auth "off";
}
auth_basic $auth;
auth_basic_user_file /www/htdocs/shopware/.htpasswd;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/537052.html
上一篇:如何在Kong的自定義日志格式化程式中記錄“x-kong-proxy-latency”
下一篇:node.jscrypto.createDecipheriv(AES-CTR演算法)的WebCrypto.subtle.decrypt模擬是什么?
