我正在尝试运行Docker compose a angular应用程序。这是我的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.confdocker-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抛出异常时,localhost页面已经拒绝了该连接。
我是Nginx的新手,我不知道该怎么做
发布于 2020-11-02 23:49:52
在您的nginx配置中,localhost匹配容器,而不是主机(nginx将只接受来自容器本身的连接)。删除server_name行应该可以使其正常工作。
https://stackoverflow.com/questions/64647425
复制相似问题