*1 directory index of "/usr/share/nginx/html/" is forbidden, in mac catalina os

Viewed 8885

I was try to mount a folder into "/usr/share/nginx/html/" and the Docker consoler shows an error of "[error] 28#28: *1 directory index of /usr/share/nginx/html/ is forbidden". I use this command to mounted volume "docker-share dilrukshi$ docker run -d -p 8080:80 --name web -v ~/docker-share/html:/usr/share/nginx/html nginx" and also I used nginx/1.19.3 Official NGINX Docker Image. In a web page show, a "403 Forbidden" error and also "/usr/share" folder doesn't have "/nginx/html". Wha's wrong with? and How can I fix it?

Docker consoler

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
172.17.0.1 - - [20/Oct/2020:07:09:41 +0000] "GET / HTTP/1.1" 403 555 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36" "-"
2020/10/20 07:09:41 [error] 28#28: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:8080"

Browser Error

enter image description here

1 Answers

it looks like a problem with the folder permissions. Try to execute the following:

chmod -R 755 ~/docker-share/html

When you map a host folder into the container, the files' ownership is maintained. e.g.

If you execute the following

docker run -it --rm -v "~/docker-share/html:/usr/share/nginx/html" nginx:alpine

You'll get something like this:

total 12
drwx--x--x    2 1000     1000          4096 Oct 20 07:48 .
drwxr-xr-x    3 root     root          4096 Jan  9  2020 ..
-rwx--x--x    1 1000     1000            83 Oct 20 07:48 index.html

In my case the folder is owned by 1000 (in your case you'll find your uid). The nginx container will use the nginx user (uid: 101) for its workers.

Related