我已经用next.js创建了一个网站,并将其部署在自己的测试服务器中后,一切都按预期进行。由于存在admin区域,因此我进行了配置以保护/admin
{{1} }使用nginx基本认证。这是我的步骤:
url
上使用apache2-utils
安装了sudo apt-get install apache2-utils
Ubuntu 18.04
创建了凭据。单击htpasswd /etc/nginx/.htpasswd myusername
之后,我提供了enter
password
我在usename:hashedpassword
nginx
这是我对该应用的完整配置。但是我隐藏了其他配置详细信息(TLS,http重定向等):
location /admin {
auth_basic "Zone protege";
auth_basic_user_file /etc/nginx/.htpasswd;
}
当我点击错误的凭据时,无法获得预期的请求页面。
因此,当我点击所需的凭据时,会得到 server {
server_name mydomainename.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /admin {
auth_basic "Zone protege";
auth_basic_user_file /etc/nginx/.htpasswd;
try_files $uri $uri/ =404;
}
}
:
我已经阅读了以下解决方案: NGINX auth_basic is giving me a '404 not found' message ... NGINX htpasswd 404 not found
尝试过的其他解决方案也没有被标记为解决问题。
答案 0 :(得分:1)
尝试这个?
server {
server_name mydomainename.com;
auth_basic "Zone protege";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
auth_basic off;
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /admin {
#auth_basic on;
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}