gpt4 book ai didi

angular - 如何在docker容器内路由angular?

转载 作者:行者123 更新时间:2023-12-02 19:49:15 25 4
gpt4 key购买 nike

我想将我的 Angular 应用程序部署在Docker容器中,但无法在容器中路由我的应用程序。我试图遵循official angular doc准则。您可以看一下我在这里所做的事情:

Dockerfile:

FROM node:latest as build
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build --prod


# Stage 1: serve app with nginx server
FROM nginx:latest
COPY --from=build /app/dist/pointeuse /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

Nginx配置文件
server {
listen [::]:80;
sendfile on;
default_type application/octet-stream;

gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 256;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_comp_level 9;

root /usr/share/nginx/html;

location / {
try_files $uri $uri/ /index.html =404;
}
}

Pointeuse文件夹(我的应用程序)
3rdpartylicenses.txt                 polyfills-es2015.690002c25ea8557bb4b0.js
assets polyfills-es5.9e286f6d9247438cbb02.js
favicon.ico runtime-es2015.1eba213af0b233498d9d.js
index.html runtime-es5.1eba213af0b233498d9d.js
main-es2015.df94aaa439cec2ec9350.js styles.4333e01ba2bdd733ca4e.css
main-es5.df94aaa439cec2ec9350.js

最佳答案

我需要添加

listen 80
在Nginx配置文件中。
因为默认情况下docker中未启用IPv6。

关于angular - 如何在docker容器内路由angular?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61932945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com