Docker Community Forums

Share and learn in the Docker community.

NGINX MAC OS Big Sur - 403 Forbidden Error

Hey hi everyone,

I was following the tutorial on youtube about docker from free code camp where the instructor will run a basic. HTML file in NGINX container it will run perfectly for him but I am getting the 403 forbidden error when accessing the localhost

My OS: Mac OS Big Sur

The command used by me in the terminal :

  1. docker run --name website -v $PWD:/usr/share/nginx/html:ro -d -p 8080:80 nginx - 403 Forbidden

  2. docker run --name website -v $(pwd):/usr/share/nginx/html:ro -d -p 8080:80 nginx - 403 Forbidden

Pasting the log file below

/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: info: Getting the checksum of /etc/nginx/conf.d/default.conf

10-listen-on-ipv6-by-default.sh: info: 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: Launching /docker-entrypoint.d/30-tune-worker-processes.sh

/docker-entrypoint.sh: Configuration complete; ready for start up

2021/03/09 18:29:11 [error] 32#32: *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"

172.17.0.1 - - [09/Mar/2021:18:29:11 +0000] "GET / HTTP/1.1" 403 153 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:86.0) Gecko/20100101 Firefox/86.0" "-"

172.17.0.1 - - [09/Mar/2021:18:29:11 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:86.0) Gecko/20100101 Firefox/86.0" "-"

2021/03/09 18:29:11 [error] 32#32: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/"

Fixing the issue involves creating a file /etc/apache2/users/yourusername.conf (yourusername being the account short name, e.g. danielbeck – it’s usually the name of your home folder in /Users) with the following contents:

<Directory “/Users/yourusername/Sites/”>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all

Afterwards, run sudo chown root:wheel /etc/apache2/users/yourusername.conf and restart Apache.