我需要配置我的Nginx站點配置以僅在我的開發服務器中顯示密碼。事實上,我正在使用CI/CDwhich 部署Docker在生產中使用的應用程式,但我不需要在生產中顯示密碼。
開發服務器通常以特定域結尾,例如:appname.example.com.
有沒有辦法只在開發中顯示身份驗證?
這是我的配置:
server {
root /var/www/html/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
auth_basic "Restricted Content";
auth_basic_user_file /var/www/html/public/.htpasswd;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(. ?\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass php-upstream;
fastcgi_index index.php;
}
}
提前致謝。
uj5u.com熱心網友回復:
您可以使用mapblockauth_basic從$host變數值中獲取指令引數:
map $host $realm {
appname.example.com "Resticted content";
default off;
}
server {
root /var/www/html/public;
index index.php;
auth_basic $realm;
auth_basic_user_file /var/www/html/public/.htpasswd;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ [^/]\.php(/|$) {
...
}
}
例如,您可以在map指令 using~修飾符中使用正則運算式
map $host $realm {
~appname\.example\.com$ "Resticted content";
default off;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/319070.html
標籤:nginx
