Docker Nginx 目录索引在 Kubernetes 中禁止"/src/"



在Kubernetes中设置Docker Nginx配置时,我得到了一个directory index of "/src/" is forbidden错误。下面是Kubernetes日志中的错误:

/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: /etc/nginx/conf.d/default.conf is not a file or does not exist
/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/11 02:23:24 [error] 23#23: *1 directory index of "/src/" is forbidden, client: 10.136.144.155, server: 0.0.0.0, request: "GET / HTTP/1.1", host: "10.42.3.4:80"
10.136.144.155 - - [11/Mar/2021:02:23:24 +0000] "GET / HTTP/1.1" 403 125 "-" "kube-probe/1.15"

为Angular应用程序提供nginx服务的dockerfile很简单:

FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx/conf.d /etc/nginx/
COPY dist /src
RUN ls /src

我的nginx.conf文件包含:

worker_processes  1;
events {
worker_connections  1024;
}
http {
include       mime.types;
default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;
server {
listen       80;
server_name 0.0.0.0;
root   /src;
charset utf-8;
include h5bp/basic.conf; # eg https://github.com/h5bp/server-configs-nginx
include modules/gzip.conf;
location =/index.html {
include modules/cors.conf;
}
location / {
try_files $uri$args $uri$args/ /index.html;
}
}
}

Kubernetes部署使用Quay镜像。你认为我的错误可能是在dockerfile, nginx.conf文件,或两者?

在Dockerfile复制行中,您正在复制conf.d到nginx文件夹,尝试更改

FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx/conf.d /etc/nginx/conf.d
COPY dist /src
RUN ls /src

我通过将我的AngularbuildoutputPath更改为"dist"而不是默认的"dist/my-project"来解决我的错误。

"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist", // was previously "dist/my-project"

最新更新