如何解决与Nginx和docker-compose形成角度
我正在尝试与Docker一起编写一个有角度的应用程序。这是我的Angular容器Dockerfile
# Stage 0,for downloading project’s npm dependencies,building and compiling the app.
FROM node:14.13 as node
# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
# add .bin to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install package.json (o sea las dependencies)
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @angular/cli@10.0.3
# add app
COPY . /usr/src/app
# start app
CMD npm build-prod
# Stage 1,for copying the compiled app from the previous step and making it ready for production with Nginx
FROM nginx:alpine
COPY --from=node /usr/src/app/dist/bloomingfrontend /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/conf.d/default.conf
docker-compose文件:
version: '3.3'
services:
web:
build: './blooming_frontend'
ports:
- 80:80
depends_on:
- spring
spring:
build: ./blooming_backend
ports:
- 8080:8080
还有nginx.conf
server {
server_name localhost;
listen 80;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
}
在某些教程中看来,可以正常工作,但是在访问localhost时抛出异常 本地主机页面已拒绝连接。
我是Nginx的新手,我不知道该怎么做
解决方法
在您的nginx配置中,localhost
与容器而不是主机匹配(nginx仅接受来自容器本身的连接)。
删除server_name
行应使其起作用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。