docker - * 1在Mac Catalina os中,禁止 “/usr/share/nginx/html/”的目录索引

标签 docker nginx macos-catalina

我试图将文件夹安装到“/usr/share/nginx/html/”中,而Docker控制台显示错误“[error] 28#28: *1 directory index of /usr/share/nginx/html/ is forbidden”。我使用此命令挂载了卷“docker-share dilrukshi$ docker run -d -p 8080:80 --name web -v ~/docker-share/html:/usr/share/nginx/html nginx”,并且我还使用了Nginx / 1.19.3 NGINX官方Docker镜像。在显示的网页中,“403 Forbidden”错误以及“/ usr / share”文件夹中没有“/ nginx / html”。谁错了?以及如何解决?
Docker控制台

/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"
浏览器错误
enter image description here

最佳答案

文件夹权限似乎有问题。尝试执行以下操作:

chmod -R 755 ~/docker-share/html
将主机文件夹映射到容器时,将保留文件的所有权。例如
如果执行以下
docker run -it --rm -v "~/docker-share/html:/usr/share/nginx/html" nginx:alpine
您将获得如下内容:
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
在我的情况下,该文件夹归1000所有(在您的情况下,您将找到自己的uid)。 Nginx容器将使用nginx用户(uid:101)为其工作人员。

关于docker - * 1在Mac Catalina os中,禁止 “/usr/share/nginx/html/”的目录索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64440577/

相关文章:

nginx - 如何让 nginx 重定向到 url 编码的查询参数

java - 无法从 java maven 项目的 docker run 命令访问 jarfile

docker - 运行docker容器报错: Could not find base path/models/model for servable model

ubuntu - 如何在主机文件上使用 docker 镜像中的 shell?

docker - 无法启动和连接3个docker服务-Redis,Python 3.7 Slim(Running DRF)和Celery

macos - 在Mac上为基于Electron的App提供不同的Dock和Tray图标吗?

nginx - gzip_types image/jpeg 如何工作

url - nginx/redis 和处理 url 中的跟踪参数

swift - 新项目使用 SwiftUI、XCode 12 和 Catalina 失败

ios - 无法识别的选择器作为按钮发送到 Collection View 单元格的实例,该按钮将数据从按钮发送到另一个 View Controller