Docker-Nginx角-403禁止错误

时间:2018-09-04 06:48:57

标签: angular docker nginx dockerfile

我正在尝试使用以下Dockerfile在Docker中构建我的angular应用程序:

FROM node:8.11.2-alpine as node

COPY package.json package-lock.json ./

RUN npm i && mkdir /app && cp -R ./node_modules ./app

WORKDIR /usr/src/app

COPY . .

RUN npm install

FROM nginx:1.13.3-alpine

RUN rm -rf /usr/share/nginx/html/*

COPY ./nginx.conf  /etc/nginx/conf.d/default.conf

COPY --from=node . /dist/usr/share/nginx/html

CMD ["nginx", "-g", "daemon off;"]

以及以下nginx.conf文件:

 server {
 listen 80;
 location / {
 root /usr/share/nginx/html/;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
 }
  }

容器的构建很好,但是当我检查该容器的端口时,会收到“ 403 Forbidden”网页,而不是我的Angular应用程序。

检查容器时,发现以下错误消息:     2018/09/03 23:23:09 [错误] 6#6:* 1的目录索引      禁止使用“ / usr / share / nginx / html /”,客户端:172.17.0.1,服务器:,      请求:“ GET / HTTP / 1.1”,主机:“ localhost”

我的index.html文件存在于名为'src'的文件夹中,该文件夹与DockerFile和nginx.conf文件位于同一目录中。

是否会在DockerFile所在的目录中没有Docker-Compose.yml文件?我有什么想念的吗?

到目前为止,当前容器尚无卷。

请帮助我指出正确的方向。

1 个答案:

答案 0 :(得分:0)

问题在于数量;而不是将卷设置为html目录,而是将其设置为nginx目录。 例如: 代替

-v / home / USER / docker-volums / nginx-sample1 / usr / share / nginx / html:/ usr / share / nginx / html

执行以下操作:

-v / home / USER / docker-volums / nginx-sample1 / usr / share / nginx:/ usr / share / nginx

问题会解决!

为解决问题:

remove previous existing container and create container by following command: 

docker run -d --name nginx-sample1 -v / home / USER / docker-volums / nginx-sample1 / usr / share / nginx:/ usr / share / nginx -p 2080:80 nginx:latest

现在在角度项目中,您可以通过观察更改来构建项目。实时更改将自动应用于nginx。通过以下命令运行角度项目:

ng build --outputPath = / home / USER / docker-volums / nginx-sample1 / usr / share / nginx / html / --watch

相关问题