angular - Angular routing in docker and nginx
问题描述
I have the following Dockerfile
FROM node:14.15.5 as build-stage
WORKDIR /webapp
COPY package*.json /webapp/
RUN npm ci
COPY ./ /webapp/
RUN npm run build:prod
# copy SPA and serve by nginx
FROM nginx:1.15
COPY --from=build-stage /webapp/dist/kubernetes-webapp/ /usr/share/nginx/html
EXPOSE 80
I have enabled routing in angular application, and when accessing it on localhost:4200/myroute
it's working.
But when I run the application in a docker container and acess localhost:4200/myroute
it returns
404 Not Found nginx/1.15.12
The nginx configuration is the default one coming from the nginx/1.15.12 image
How am I able to solve the problem and allow angular routing in the docker container with nginx.
解决方案
据我所知,上述 docker 文件将在 ngnix 中创建一个构建和复制文件以运行您的应用程序(您构建 angular 并通过 nginx 服务器公开构建文件夹/静态文件)
- 您正在 ngnix 和端口 80 上运行应用程序。
- 尝试打开 url
localhost:80
或只是 localhost 因为默认端口是 80
*当您运行 Angular 进行开发时,您使用命令 ng serve 并在端口 4200 上打开,并且在幕后的服务命令会为您提供一个服务器来运行/开发您的项目。
但是在您的这种情况下,您已经进行了构建,并且您选择了在端口 80 上运行的服务器。
推荐阅读
- c# - .Net 4.7.2 Sql 在长文件夹路径中导出 bak 文件
- sql - 字符串正在保存特殊字符
- java - 如何将 jar 文件安装程序转换为 Linux、Windows、MacOS 支持的文件?
- python - 类型错误:comment_detail() 缺少 2 个必需的位置参数:'request' 和 'slug'
- swift - 修改路径 SPM 中的文件
- python - 在python数据框中找到对两个条件进行分层的第一行
- filter - 来自度量的 DAX 过滤器函数参数
- python - 使用 Gocoder python 跟踪我的位置时出现问题
- python - 在 shell 脚本中设置烧瓶环境变量
- c# - Python C# 互操作