我已经创建了一个next.js网站,并将其部署在我自己的测试服务器中后,一切都按预期进行。由于存在和管理区域,因此我使用nginx基本身份验证进行了配置以保护/admin
url
这是我的步骤:
apache2-utils
上的sudo apt-get install apache2-utils
安装了Ubuntu 18.04
htpasswd /etc/nginx/.htpasswd myusername
创建了我的凭据。单击enter
后,我提供了password
usename:hashedpassword
[我在nginx
中进行了以下配置
location /admin {
auth_basic "Zone protege";
auth_basic_user_file /etc/nginx/.htpasswd;
}
这是我对该应用的完整配置。但是我隐藏了其他配置详细信息(TLS,http重定向等:):
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
也尝试过其他解决方案,即使它们没有被标记为解决问题。
尝试这个?
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;
}
}