【发布时间】: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;
# }
#}
}
有人能在某个方向指出我这里出了什么问题吗?
我的 conf 文件也被复制到那里,我也匹配了内容
【问题讨论】:
-
(比较错误信息、你的 Dockerfile 和 Nginx
root指令。) -
非常感谢。我似乎将构建文件复制到错误的目录中。它现在正在工作。错误消息甚至说明了一切。感谢您为我指明正确的方向