songining

docker-compose.yml

version: '3'

services:

  backend:
    build:
      context: .
      dockerfile: ./backend/Dockerfile
    expose:
      - 5000
    ports:
      - "5000:5000"
    links:  
      - mongo_db:mongo_db
    depends_on:
      - mongo_db
    #restart: always  
    volumes:
      - ./backend/flask_app:/usr/src/app
    command: gunicorn -w 1 -b 0.0.0.0:5000 wsgi:app

  frontend:
    build:
      context: .
      dockerfile: ./frontend/Dockerfile
    expose:
      - 3000
    ports:
      - "3000:3000"
    volumes:
      - ./frontend:/app
      - /app/node_modules
    stdin_open: true
    tty: true
    #restart: always
  
  mongo_db:
    image: mongo:latest
    restart: unless-stopped
    environment:    # ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: vitaminc
    volumes:
       - ./mongo/db:/data/db
    ports:
      - "27017:27017"

  nginx:
    image: nginx:latest
    ports:
      - "8080:8080"
      - "8081:8081"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - frontend
      - backend
    restart: "on-failure"

 

nginx/nginx.conf

nginx์˜ reverse proxy -> 8080 (ํ”„๋ก ํŠธ), 8081(๋ฐฑ) 

user nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" "$request_uri" "$uri"'
                      '"$http_user_agent" "$http_x_forwarded_for"';    
    access_log  /var/log/nginx/access.log  main;
    sendfile on;
    keepalive_timeout 65;


    upstream docker-front{
	server frontend:3000;
    }
    upstream docker-back {
        server backend:5000;
    }

    server {
        listen 8080;
        server_name localhost;

            location / {
			proxy_pass         http://docker-front;
			proxy_redirect     off;
            		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-Host $server_name;
            		proxy_set_header   X-Forwarded-Proto $scheme;
            }
    }

    server {
        listen 8081;
        server_name localhost;
     
        location / {
            		proxy_pass         http://docker-back;  
	    		proxy_redirect     off;
            		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-Host $server_name;
            		proxy_set_header   X-Forwarded-Proto $scheme;
        	}
    	}
}

 

aws ec2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ด์šฉํ•ด ์„œ๋ฒ„๋ฅผ ๊ตฌ์ถ•ํ•˜์˜€๋‹ค. 

pem ๋ณด์•ˆ ํŒŒ์ผ์— ๋Œ€ํ•œ ์ €์žฅ์ด ํ•„์ˆ˜์ด๋‹ค. pemํŒŒ์ผ์„ ์ด์šฉํ•ด ์šฐ๋ถ„ํˆฌ ssh ์„œ๋ฒ„๋ฅผ ๊ตฌ์ถ•ํ–ˆ๋‹ค.

'2021 silicon valley online internship' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Nginx Reverse Proxy  (0) 2022.03.17
์ธํ„ด์‹ญ ์ˆ˜๋ฃŒ์ฆ ๐Ÿ˜Ž  (0) 2022.03.15
AWS EC2 ์›น์„œ๋ฒ„ ๊ตฌ์ถ•ํ•˜๊ธฐ  (0) 2021.07.02