大网数据广告活动
服务器运维问答

Limit Authentication to specific username in Nginx

· 52CE 我爱测

Is it possible to limit authentication in Nginx to a specific username? I.e I have multiple subdomains and want to limit that subdomain to ONLY 1 user. All the users are in 1 .htpassword file. In Apache you can do it as follows: …

问题原文

原帖链接 · bhavicp · CC BY-SA 3.0

Is it possible to limit authentication in Nginx to a specific username? I.e I have multiple subdomains and want to limit that subdomain to ONLY 1 user. All the users are in 1 .htpassword file. In Apache you can do it as follows:

AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /usr/local/apache/passwd/passwords
Require user rbowen

However I haven't been able to find a similar way in Nginx.

This is how my current Nginx setup is. I have one of these in each server {} block for each user.

auth_basic "Restricted";
auth_basic_user_file /usr/local/apache/passwd/passwords;

已采纳解答

原帖链接 · Xavier Lucas · CC BY-SA 3.0

If I understand the question well, you have a file containing multiple user names and passwords and you want to limit the authentication to a specific user from that file for each server block and keep the configuration centralized ?

Unfortunately you can't do that with nginx, you will need to split the file into multiple ones containing only one user:password pair.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-11-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。