【问题标题】:Docker - Angular app image is not working ("/etc/nginx/html/index.html" is not found)Docker - Angular 应用映像不工作(“/etc/nginx/html/index.html”未找到)
【发布时间】:2022-01-04 13:56:15
【问题描述】:

所以我有一个角度应用程序,我已经为它创建了一个 Dockerfile 。试图从中创建构建,并在解决一些构建问题后成功。容器正在运行,但应用程序没有运行,这是我在 NgInx 日志中看到的

2021/11/26 13:13:03 [error] 8#8: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:82"
172.17.0.1 - - [26/Nov/2021:13:13:03 +0000] "GET / HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36 Edg/94.0.992.50"

这是我的 docker 文件

FROM node:12 as build-stage
RUN mkdir -p /app
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . /app
RUN npm run build

FROM nginx:1.17.1-alpine as production-stage
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build-stage /app/dist/java-poc /usr/share/nginx/html

这是我在 package.json 文件中的构建脚本

"scripts": {  
    "build": "node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --prod",
 },

这是我试图在 NGINX 映像中覆盖的 NgInx 配置文件。

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
    listen       82;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

   location /api/auth-ms {
        proxy_pass http://localhost:9092/auth-ms;
        proxy_set_header Host $host;
        proxy_pass_request_headers on;
    }


    location /api/test-engine  {
                    proxy_pass http://localhost:9092/test-engine;
                    proxy_set_header Host   $host;
                    proxy_pass_request_headers on;
            }
    
    

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

有人能在某个方向指出我这里出了什么问题吗?

编辑:刚刚检查 index.html 是否存在。这也检查了

我的 conf 文件也被复制到那里,我也匹配了内容

【问题讨论】:

  • (比较错误信息、你的 Dockerfile 和 Nginx root 指令。)
  • 非常感谢。我似乎将构建文件复制到错误的目录中。它现在正在工作。错误消息甚至说明了一切。感谢您为我指明正确的方向

标签: angular docker nginx


【解决方案1】:

似乎我将构建文件复制到错误的目录中。现在解决了。只需要更改dockerfile这一行

COPY --from=build-stage /app/dist/java-poc /etc/nginx/html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-16
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 2021-06-08
    • 1970-01-01
    相关资源
    最近更新 更多