繁体   English   中英

nginx角5反向代理mongo图像

[英]nginx angular 5 reverse-proxy mongo image

我可以为我的angular 5项目获得反向代理服务。 带有以下文件。 我是Angular和Nginx的新手。 在我对客户端和nginx等进行docker化之前,我只是将所有内容都安装在一个路径下。 因此,我只运行了一个npm安装程序,并使用了npm start,ng build --prod和ng serve。

我对Angular 2版本5感到有些困惑,我以为我正在尝试将客户端与服务器分离。 知道Angular 2可以在客户端运行大多数操作。 但是现在看来,我的app.js仍在同一“客户端”容器内被调用。 我应该分开快递服务器并将其容器化吗,这样做有什么好处?

我还将从容器中运行mongo图像。 我是否正确将Client容器链接到mongo?

nginx default.conf

   server {
location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://client:4200/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
   }
}

泊坞窗,compose.yml

   version: '2'

services:
  # Build the container using the client Dockerfile
   client:
   build: ./
  # This line maps the contents of the client folder into the container.
   volumes:
    - ./:/usr/src/app
    links:
     - mongo
    depends_on:
    - mongo
  mongo:      
    image: mongo
    container_name: "mongodb"
    environment:           
    - MONGO_DATA_DIR=/data/db
    - MONGO_LOG_DIR=/dev/null
   volumes:
    - ./data/db:/data/db
   ports:
    - 27017:27017
   command: mongod --smallfiles --logpath=/dev/null # --quiet
  # Build the container using the nginx Dockerfile
 nginx:
  build: ./nginx
   # Map Nginx port 80 to the local machine's port 80
  ports:
    - "80:80"
   # Link the client container so that Nginx will have access to it
  links:
    - client

Dockerfile

  #  Create a new image from the base nodejs 7 image.
 FROM node:8.1.4-alpine as builder
 # Create the target directory in the imahge
 RUN mkdir -p /usr/src/app
 # Set the created directory as the working directory
 WORKDIR /usr/src/app
# Copy the package.json inside the working directory
 COPY package.json /usr/src/app
 # Install required dependencies
 RUN npm install 
 # Copy the client application source files. You can use .dockerignore
 to     exlcude files. Works just as .gitignore does.
 COPY . /usr/src/app
 # Open port 4200. This is the port that our development server uses
 EXPOSE 3000
 # Start the application. This is the same as running ng serve.
 CMD ["npm", "start"]

即使您在同一容器中运行客户端(角度)和服务器(节点),它们仍然是“分离的”。 它们物理上位于同一服务器上并在同一服务器上提供服务,但分别运行。 您的api层在node上运行,而angular应用程序在客户端上运行。

您所拥有的是有效的。 我有几乎相同的设置。 我有2个容器。 运行express的节点容器可为我的api层我的angular应用程序服务。 然后,我将mongo容器作为数据库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM