Reputation: 448
Trying to get basic_auth work for nginx in DDEV.
I added a .ddev/nginx_full/auth.conf
with the following content
server {
listen 80;
listen 443;
server_name dev.example.com;
location ^~ / {
root /var/www/html/public;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
and the basic auth prompt appears but after typing in the credentials I get a 404... I have no clue. What am I doing wrong here?
Upvotes: 0
Views: 40
Reputation: 448
To get basic_auth work properly there are just a few things to do:
.ddev/nginx_full/auth.conf
file containing the following:auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
This needs to restrict all requests and leads to a basic auth prompt as expected.
.ddev/nginx_full/.htpasswd
file containing your username:password credentialsCreate the file by using the htpasswd
CLI tool or use an online generator tool. It doesn't matter, just make sure the file's content is valid.
.ddev/docker-compose.mounts.yaml
file containing the following:services:
web:
volumes:
- ./nginx_full/.htpasswd:/etc/nginx/.htpasswd
DDEV automatically detects that file and will mount the .htpasswd
into the web container on restart.
Don't forget executing ddev restart
;-)
Upvotes: 1