localhost to .com

Intro

How do I deploy an application?

  1. buy a domain
  2. deploy somewhere

That's it

localhost

Your own computer enviornment

services in different port

C1

.com

In cloud (live in terminal)

if services in one domain 

C10K

If C10K

Read Replica

Cache

Hot standBy

Auto scaling

Worker

NoSQL

.com

In cloud (live in terminal)

if services in one domain 

C1K

linux, vim

nginx, VM/Docker

redis

Case

official/erp

front-end/back-end

Wealth

official-front-end

official-back-end

Service

erp-front-end

erp-back-end

usage-listener-server

usage-listener-handler

Port

6060

6069

6080

6089

6068

9092

microservice/gateway

client

service

reverse proxy

service

service

service

service

database

database

Web Server

AP Server

nginx

dockerized application

microservice/api gateway

client

service

reverse proxy

service

service

service

service

database

database

GCP/AWS ...... etc

Hosting

That's it

Back to the script: npm run release

compile your client/server/worker code

Build an image from a Dockerfile

base on host OS

Docker intro

isolated env.

Dockerfile

FROM node:14-slim

ENV DEBUG *
ENV TZ=Asia/Taipei
ENV USAGE_LISTENER_PORT 80

RUN mkdir -p /var/www/wealth
COPY dist/package.json dist/package-lock.json /var/www/wealth/
WORKDIR /var/www/wealth
RUN npm install

COPY dist/ /var/www/wealth

CMD node /var/www/wealth/server/usage-listener/server.js

docker build

docker push

ssh at7211@staging.server

username

remote server

The SSH protocol uses encryption to secure the connection between a client and a server.

ssh into your remote server

cd /etc/nginx

nginx.conf -> main config

conf.d -> project nginx config

cd /etc/nginx/conf.d
vim [:PROJECT].conf
server {
  listen 80;
  server_name wealth.rytass.com;
  client_max_body_size 20m;

  access_log /var/log/wealth.access.log;
  error_log /var/log/wealth.error.log;


  location / {
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:6060;
  }
}

Pull image and restart container

shell script 

EEN='\033[0;32m'
NC='\033[0m'

echo -e "${CYAN}------ Wealth Upgrating ------${NC}\n"
# Pull latest version
N='\033[0;36m'
echo -e "${CYAN}Pull latest image...${NC}"
docker pull asia.gcr.io/develop-server/wealth-official-client

# Stop executing container
echo -e "\n${CYAN}Stop container...${NC}"
docker stop wealth-official-client

# Remove executing container
echo -e "\n${CYAN}Removing container...${NC}"
docker rm wealth-official-client

# Start containers
echo -e "\n${CYAN}Start container...${NC}"
# Set container name and port
docker run -d --name wealth-official-client --network-alias=Official_Client --net=Wealth -p 6060:80 --restart=always asia.gcr.io/develop-server/wealth-official-client
echo -e "\n${GREEN} Wealth Upgrade Task Finished.${NC}":
./[:PROJECT].sh

execute script

That's it

mm......so how does different service work in one domain?

docker ps

docker run -p 6080:80 (published port)

Map TCP port 80 in the container to port 6080 on the Docker host.

list all container status

docker exec -it [:CONTAINER_NAME] /bin/bash

get into the container

http {
  ...
  upstream api_upstream {
    server Official_API_Server;
  }
  ...
  server {
    listen 80 default_server;
    server_name _;
    root /var/www/wealth;
    index index.htm index.html;
    access_log /var/log/wealth.access.log;
    error_log /var/log/wealth.error.log;

    location ~ ^/graphql(.*)$ {
      proxy_http_version 1.1;
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_pass http://api_upstream/graphql$1?$args;
    }
    location ~ ^/uploads(.*)$ {
      proxy_set_header Host $host;
      proxy_pass http://api_upstream/uploads$1?$args;
    }

    location / {
      try_files $uri /$uri /index.html;
    }
  }
}

network alias

location pathname

cat /etc/nginx/nginx.conf

browser

wealth.rytass.com

client service

(nginx)

Web Server

/graphql

6080:80

API service

/upload

upload service

cloudflare 

docker network

auto https

localhost to .com

By Jay Chou

localhost to .com

  • 292