在Docker中使用Nginx时出现禁止错误 [英] Getting forbidden error while using nginx inside docker

查看:309
本文介绍了在Docker中使用Nginx时出现禁止错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Docker文件内容为

My Docker file contents are

FROM nginx
COPY /src /usr/share/nginx/html

我的docker撰写文件的内容是

My docker compose file contents are

version: '2'
services:
  app:
    build: .
    image: app:1.0.0
    volumes:
    - ./src:/usr/share/nginx/html
    ports:
    - "8080:80"

运行docker-compose时出现以下错误

I'm getting following error when run docker-compose

*1 directory index of "/usr/share/nginx/html/" is forbidden

我尝试授予目录权限->/usr/share/nginx/html 它没有用.

I tried giving permission to directory -> /usr/share/nginx/html it didn't work.

我想将主机目录与docker容器同步.

I want to sync host directory with docker container.

推荐答案

我遇到了同样的问题,因此发布答案可能会帮助其他人或寻找同一问题的其他人

I was facing the same issue so the posting answer might help some else or some else looking for the same problem

我正在运行nginx官方映像.

I am running nginx official image.

docker run --rm --name some-nginx -p 8080:80 -v /test/html5-youtube.js/examples/:/usr/share/nginx/html -it nginx

我遇到此错误.

[error] 8#8: *3 directory index of "/usr/share/nginx/html/" is *forbidden*, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:8080"

因此,当我检查目录权限时,这是错误的.

So when I check the directory permission it was wrong.

在我的情况下,请检查nginx.conf中的用户是否为nginx,因此请更改文件权限.

Check the user in nginx.conf in my case it is nginx so change file permission.

cd /usr/share/nginx/html
chown nginx:nginx ./*

然后我能够从服务器获得响应.

and then I was able to get a response from the server.

172.17.0.1 - - [30/Oct/2018:09:04:52 +0000] "GET /html5-youtube.js HTTP/1.1" 404 571 "http://localhost:8080/player.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36" "-"

这篇关于在Docker中使用Nginx时出现禁止错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆