Ssl Nginx basic auth在http上工作,但不在https上工作
我在centos 6上运行nginx。域被配置为使用ssl。某些特定文件夹需要密码保护。如果我用http输入url,浏览器会要求输入user并传递。如果我使用https键入相同的url,那么将显示特定文件夹的索引文件,而不要求用户通过 我在特定于域的nginx.conf文件中有:Ssl Nginx basic auth在http上工作,但不在https上工作,ssl,nginx,https,nginx-location,Ssl,Nginx,Https,Nginx Location,我在centos 6上运行nginx。域被配置为使用ssl。某些特定文件夹需要密码保护。如果我用http输入url,浏览器会要求输入user并传递。如果我使用https键入相同的url,那么将显示特定文件夹的索引文件,而不要求用户通过 我在特定于域的nginx.conf文件中有: location /protected_folder { auth_basic "Restricted"; auth_basic_user_file /etc/nginx/.htpasswd
location /protected_folder {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
如何确保使用http和https的URL都受密码保护?我看到nginx在同一个目录中有两个配置文件:nxingx.conf和snginx.conf。我只需使用相同的身份验证规则更新snginx.conf,就可以了。我看到nginx在同一个目录中有两个配置文件:nxingx.conf和snginx.conf。我只需使用相同的身份验证规则更新snginx.conf,就可以了。您需要将受限配置放在80和443端口中: /etc/nginx/可用站点/MY_VHOST
server
{
listen 80;
server_name YOUR.FQDN;
.....other config of vhost.....
location /protected_folder {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
server
{
listen 443;
server_name YOUR.FQDN;
.....other config of vhost.....
location /protected_folder {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
或者,您可以将http请求重定向到https:
server
{
listen 80;
server_name YOUR.FQDN;
return 301 https://YOUR.FQDN$request_uri;
}
server
{
listen 443;
server_name YOUR.FQDN;
.....other config of vhost.....
location /protected_folder {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
您需要将受限配置放在80和443端口中: /etc/nginx/可用站点/MY_VHOST
server
{
listen 80;
server_name YOUR.FQDN;
.....other config of vhost.....
location /protected_folder {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
server
{
listen 443;
server_name YOUR.FQDN;
.....other config of vhost.....
location /protected_folder {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
或者,您可以将http请求重定向到https:
server
{
listen 80;
server_name YOUR.FQDN;
return 301 https://YOUR.FQDN$request_uri;
}
server
{
listen 443;
server_name YOUR.FQDN;
.....other config of vhost.....
location /protected_folder {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}