Getting forbidden error while using nginx inside docker

烈酒焚心 提交于 2019-12-10 14:47:09

问题


My Docker file contents are

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

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"

I'm getting following error when run docker-compose

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

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

I want to sync host directory with docker container.


回答1:


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

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

I was getting this error.

[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.

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" "-"


来源:https://stackoverflow.com/questions/49254476/getting-forbidden-error-while-using-nginx-inside-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!