참고 사이트

 https://certbot.eff.org/instructions

 

Installing snap on Ubuntu

snapd 설치

$ sudo apt update
$ sudo apt install snapd

 

snapd 설치 후 확인

$ sudo snap install hello-world
hello-world 6.4 from Canonical✓ installed
$ hello-world
Hello World!

 

cerbot 이 설치되어 있다면 아래 명령어 중 하나를 이용하여 삭제

$ sudo apt-get remove certbot
$ sudo dnf remove certbot
$ sudo yum remove certbot

 

cerbot 설치

$ sudo snap install --classic certbot

 

cerbot 커맨드 설정

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

 

cerbot 이용해서  certification을 얻고 설치하기

sudo certbot --nginx -d 도메인주소

 

renewal 확인

$ sudo certbot renew --dry-run

참고 사이트

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-22-04#step-5-%E2%80%93-setting-up-server-blocks-

Installing nginx on Ubuntu 22.04

nginx 설치

$ sudo apt update
$ sudo apt install nginx

 

nginx 설치가 잘되었는지 확인

$ sudo service nignx status

 

방화벽(firewall) 설정 

$ sudo ufw app list

Available applications:
  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  OpenSSH
  • 위에 출력된 모든 옵션이 설치 되어 있어야 한다.
    • Nginx HTTP:  80번 포트 만 허용 (normal, unencrypted web traffic)
    • Nginx HTTPS:  443번 포트만 허용 (TLS/SSL encrypted traffic)
    • Nginx Full:  80번 과 443번 포트 둘다 허용
  • 80번 포트 허용 방법
$ sudo ufw allow 'Nginx HTTP'
  • 현재 상태 확인 ( 허용한 application 이 나열된다)
$ sudo ufw status

Status: active

To                         Action      From
--                         ------      ----
Nginx HTTP                 ALLOW       Anywhere
OpenSSH                    ALLOW       Anywhere
Nginx HTTPS                ALLOW       Anywhere
Nginx HTTP (v6)            ALLOW       Anywhere (v6)
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx HTTPS (v6)           ALLOW       Anywhere (v6)

 

  •  응답이 inactive 이면 아래 명령어로 활성화 시키기
$ sudo ufw enable

 

서버가 작동하고 있는 가 확인

$ systemctl status nginx

 

할당 받은 공인 아이피(public ip) 를 확인 

$ curl -4 icanhazip.com
$ curl ifconfig.me

- 둘 중 하나를 입력하면 할당받은 ip 가 출력된다.

- 출력된 ip를 크롬이나 다른 인터넷 브라우져에 입력하면 아래와 같은 문구가 나오면 설치완료

         "Welcome to nginx!"

 

EC2 에서 서버를 3000번 포트를 이용해서 배포를 했을때 방화벽때문에 접속이 안될 수도 있다.

이럴때는 3000번 포트도 허용해주기

$ sudo ufw allow 3000

 

서버블록 설정

도메인을 위한 폴더 생성

$ sudo mkdir -p /var/www/your_domain/html

 

해당 폴더의 소유자 설정

$ sudo chown -R $USER:$USER /var/www/your_domain/html

 

권한설정

$ sudo chmod -R 755 /var/www/your_domain

 

index.html 생성

$ sudo vi /var/www/도메인 이름/html/index.html

 

- 아래 내용 입력 후  esc -> :wq  로 저장후 닫기

<html>
    <head>
        <title>Welcome to your_domain!</title>
    </head>
    <body>
        <h1>Success!  The your_domain server block is working!</h1>
    </body>
</html>

 

서버블록 생성

$ sudo vi /etc/nginx/sites-available/your_domain

 

-  아래 내용을 입력

server {
        listen 80;
        listen [::]:80;

        root /var/www/your_domain/html;
        index index.html index.htm index.nginx-debian.html;

        server_name your_domain www.your_domain;

        location / {
                try_files $uri $uri/ =404;
        }
}

 

링크 생성

$ sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

 

nginx.conf 설정 

- 서버 이름을 추가할 때 발생할 수 있는 해시 버킷 메모리 문제 (hash bucket memory problem) 를 방지하기 위함

sudo nano /etc/nginx/nginx.conf
  •  #server_names_hash_bucket_size 64; 을 찾아서 앞에 있는 # 을 삭제한 후 저장

설정한 내용에 문제 없는지 확인

$ sudo nginx -t

 

문제가 없으면 nginx 재시작

$ sudo systemctl restart nginx

 

이제 부여 받은 도메인을 인터넷 창에 입력하면 index.html 에 입력한 문구가 출력된다. 

ngnix 명령어

  • ngnix 중지
$ sudo systemctl stop nginx
  • nginx 시작
$ sudo systemctl start nginx
  • nginx 재시작
$ sudo systemctl restart nginx

 

 

 

프론트 엔드에서 다른 요청은 다 작동하였는데 딱 한 가지


에러 메세지
"PATCH
http://localhost:63342/localhost:3000/stations/17
404 (Not Found)"

에러 발생 코드
`http:/${IP_ADDRESS}:3000/stations/${id}`

 

이 부분만 오류가 발생... 

 

포스트맨 이용해서 테스트한 결과 백엔드는 문제 없음을 확인

한참을  조사하다가 ... 

작동이되는 코드를 복사/붙여넣기하다가 찾은 에러

http:/ 에 "/" 이 빠졌다...

 

에러 메세지에서 주소를 못 찾는다는 말이 나왔을때 주소와 관련 된 부분을 집중적으로 먼저 확인하자!!

 

비슷 한 로직의 다른 코드들은 정상적으로 작동하는데 하나만 에러가 발생 할 때는

1. 에러 메세지를 확인 후 잘 못된 내용을 가정 먼저 확인

2. 에러 메세지에서 가리키는 부분에서 관련 로직 확인

3. 정상적으로 작동하는 코드와 비교

 

이 순서로 에러를 확인해보자..

 

배포 (Deployment)

  • 다른 사람들이 인터넷을 이용할 수 있도록 하는 것

EC2 ( Elastic Computer Cloud)

  • 컴퓨터를 빌려서 원격으로 접속해 사용하는 서비스
  • 하나의 컴퓨터
  • 백엔드 서버를 배포할 때 주로 사용
    • 이유
      • 인터넷을 통해 내 컴퓨터에 접근할 수 있게 만들다보니 보안적인 위험을 피하기 위함
      • 로깅, 오토스케일링, 로드밸런싱 등 많은 부가기능을 보유

리전( Region)

  • 컴퓨터(EC2)를 어느 지역에서 빌릴 것인지를 정하는 것
  • 애플리케이션의 주된 사용자들의 위치와 지리적으로 가까운 리전(Region)을 선택하는 것이 유리

인스턴스

  • AWS EC2에서 빌리는 컴퓨터 1대

인스턴스 유형

  • AWS EC2에서 빌리는 컴퓨터 1대의 사양

키 페어(Key pair)

  • EC2 컴퓨터에 접근할 때 사용하는 비밀번호

보안 그룹

  • AWS 클라우드에서의 네트워크 보안
  • 집 바깥 쪽에 쳐져있는 울타리와 대문 같은 것
    • 접근해도 되는 트래픽인지 확인
      • www(외부) → EC2 Instance(내부) 접근 : Inbound traffic
      • EC2 Instance → www 접근 : outbound traffic
  • Ip 와 포트를 설정 가능

IP 와 Port

  • IP : 특정 컴퓨터를 가르키는 주소
    • 13.250.15.132
  • Port : 한 컴퓨터 안에서 실행되고 있는 특정 프로그램의 주소
    • :3000
  • 쉽게 비교
    • 우편 주소 : 아파트 주소 (IP) + 동 호수(Port)

Keyof : 인터페이스의 키를 반환하여 준다. 

interface User{
   id: number
   name: string;
   age: number;
   gender: "m" | "f";
}

// interface 의 키 부분만 반환
type UserKey = keyof User; // id | name | age | gender

const uk:UserKey = "id"
const uk2:UserKey = "" // 에러

 

Partial<T> : 모든 프로퍼티를 선택사항으로 바꾸어준다.

interface User{
   id: number
   name: string;
   age: number;
   gender: "m" | "f";
}

let admin: Partial<User> = {
   id: 1,
   name: "Bob"
}

/*
위의 admin 은 아래와 같다.
interface User{
   id?: number
   name?: string;
   age?: number;
   gender?: "m" | "f";
}
*/

 

Required<T> : 모든 프로퍼티를 필수 사항으로 바꾸어준다.

ReadOnly<T> : 모든 프로퍼티를 읽기 전용으로 변경해 준다.

 

Record<K, T> : 모든 프로퍼티를 필수 사항으로 바꾸어준다.

const score: Record<"1" | "2" | "3" | "4", "A" | "B" | "C" | "D" | "F"> = {
   1: "A",
   2: "B",
   3: "C",
   4: "D",
}

type Grade = "1" | "2" | "3" | "4";
type Score = "A" | "B" | "C" | "D" | "F";

const score2: Record<Grade, Score> = {
   1: "A",
   2: "B",
   3: "C",
   4: "D",
}

 

interface User{
   id: number
   name: string;
   age: number;
}

function isValid(user:User){
   const result : Record<keyof User, boolean> ={
      id : user.id > 0,
      name : user.name !== "",
      age : user.age > 0 
   }
   return result;
}

 

 

Pick<T, K>: 인터페이스에서 원하는 프로퍼티를 선택

Omit<Type, K>

 

Exclude<T1, T2> T1에서 T2를 제외

 

NonNullable<Type>

type T1 = string | null | undefined | void;
type T2 = NoNullable<T1> // string | void

 

'프로그래밍 > TypeScript' 카테고리의 다른 글

[ TS ] 상속 : extends, super(),  (0) 2024.05.05
[ TS ] interface : 필터링하기  (0) 2024.04.01
[TS] 제네릭 ( Generics )  (0) 2024.03.08
[ TS ] 추상 class  (0) 2024.03.08
[TS] Class : Constructor(생성자) & Access Modifiers  (0) 2024.03.08

+ Recent posts