
n8n을 AWS의 무료 인스턴스를 사용해서 설치하는 방법에 대해 알아봅니다.
https://youtu.be/rZnBHanWiZg
순서
- Docker 설치
- n8n 컨테이너 설치
- AWS에 도메인 추가 (agent.codegear.info)
- Nginx 설치 및 도메인 연결
n8n은 n8n 사이트에 가입해서 서비스를 사용할 수도 있고, 직접 셀프 호스팅으로 설치해서 사용할 수도 있습니다.
가격은 Starter가 월24유로(약38,000원), Pro가 월60유로(약96,000원)으로 꽤 비용이 나가는 편입니다.
https://n8n.io/pricing/
n8n Plans and Pricing - n8n.io
Discover n8n's pricing alternatives for cost-effective workflow automation solutions. Find the perfect plan to maximize your workflows.
n8n.io

이전 포스팅에서 AWS에 EC2 인스턴스를 띄우고, Nginx를 설치하고, 도메인 연결하는 것까지 설명을 해놓았으니 참조하시기 바랍니다.
https://codegear.tistory.com/137
6천원 도메인, 무료 AWS로 '나만의 웹사이트' 띄우는 갓성비 끝판왕 가이드!
https://youtu.be/xXxljxkJy7Y 서비스 개발이 완료되면, 이를 서비스 하기 위해서는 서버와 도메인이 필요합니다.도메인을 싸게 구입하는 방법과AWS에서 도메인을 등록하고 서버를 셋팅해서 도메인 서버
codegear.tistory.com
이번 글에서는 앞에서 설정한 EC2 인스턴스에 Docker를 설치하고, n8n을 설치하는 방법을 주로 다룹니다.
Docker 설치
n8n을 쉽게 설치하기 위해서 우선 docker를 설치합니다.
Amazon Linux 2023에 Docker를 설치하는 방법은 AWS 문서에 잘 나와있습니다.
https://docs.aws.amazon.com/ko_kr/AmazonECS/latest/developerguide/create-container-image.html
Amazon ECS에서 사용할 컨테이너 이미지 생성 - Amazon Elastic Container Service
경우에 따라서는 ec2-user가 Docker 대몬에 액세스할 수 있는 권한을 제공하기 위해 인스턴스를 재부팅해야 할 수도 있습니다. 다음 오류가 표시될 경우 인스턴스를 재부팅합니다. Cannot connect to the D
docs.aws.amazon.com
터미널을 열어 EC2 인스턴스에 접속합니다.
ssh -i /path/to/your-key.pem ec2-user@YOUR_EC2_PUBLIC_IP
EC2 인스턴스에서 아래 명령을 수행합니다.
sudo yum update -y
sudo yum install docker
sudo service docker start
sudo usermod -a -G docker ec2-user
터미널 종료 후 다시 접속하면 ec2-user가 docker 권한을 갖게 됩니다.
다음 명령어로 docker의 정상 설치 여부를 확인할 수 있습니다.
docker info
Docker Compose 설치
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Docker Compose 권한 추가
sudo chmod +x /usr/local/bin/docker-compose
n8n 설치
디렉토리 생성
mkdir n8n_data
cd n8n_data
docker-compose.yml 생성
docker에 이미지를 받고 컨테이너를 생성하기 위한 설정 파일을 생성합니다.
vi docker-compose.yml
아래 내용을 입력합니다. (vi에서 내용을 추가하기 위해서는 i 키를 누르셔야 합니다)
services:
n8n:
image: docker.n8n.io/n8nio/n8n # n8n Docker 이미지 사용
restart: always # 컨테이너 종료 시 항상 재시작
ports:
- "5678:5678" # 호스트의 5678 포트를 컨테이너의 5678 포트에 연결 (n8n 기본 포트)
environment:
# n8n 라이선스 키 (선택 사항, 없으면 기본 기능으로 실행)
# - N8N_LICENSE_KEY=YOUR_LICENSE_KEY
# 데이터베이스 설정 (PostgreSQL 사용 권장)
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=n8n_db
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n_database
- DB_POSTGRESDB_USER=n8n_user
- DB_POSTGRESDB_PASSWORD=your_n8n_db_password # 안전한 비밀번호로 변경!
# 웹훅 URL 설정 (선택 사항이지만 외부 접근 시 중요)
- N8N_HOST=your.domain.com # n8n에 접속할 도메인 주소
- N8N_PROTOCOL=https # HTTPS 사용 시
- WEBHOOK_URL=https://your.domain.com/ # 웹훅 URL
volumes:
- ~/.n8n:/home/node/.n8n # n8n 데이터를 호스트에 영구 저장 (볼륨 마운트)
n8n_db: # PostgreSQL 데이터베이스 서비스
image: postgres:13 # PostgreSQL 13 버전 이미지 사용
restart: always
environment:
- POSTGRES_DB=n8n_database
- POSTGRES_USER=n8n_user
- POSTGRES_PASSWORD=your_n8n_db_password # n8n 서비스의 DB_POSTGRESDB_PASSWORD와 동일하게 설정
volumes:
- pg_data:/var/lib/postgresql/data # PostgreSQL 데이터를 호스트에 영구 저장 (볼륨 마운트)
volumes:
pg_data: # PostgreSQL 데이터 볼륨 정의
입력이 완료되면 vi editor에서 esc를 누른 후 다음 명령을 입력하여 저장합니다.
:wq
n8n 컨테이너 실행
docker-compose.yml 파일이 있는 디렉토리에서 다음 명령어를 실행합니다
docker-compose up -d
컨테이너가 잘 실행되었는지는 아래 명령어를 사용합니다.
docker-compose ps
컨테이너 로그도 확인해 줍니다.
docker-compose logs
도메인 설정하기
n8n에서 사용할 도메인은 agent.codegear.info입니다.
이를 위해 AWS Route53에 A 레코드 생성해야 합니다.
생성방법은 다음과 같습니다.
- codegear.info 호스팅 영역 클릭:
- "호스팅 영역" 목록에서 codegear.info를 클릭하여 상세 페이지로 들어갑니다.
- 레코드 생성:
- "레코드 생성(Create record)" 버튼을 클릭합니다.
- 레코드 설정:
- 레코드 이름(Record name):
- agent를 입력합니다. 이렇게 하면 agent.codegear.info가 됩니다. (루트 도메인 codegear.info에 연결하려면 비워둡니다.)
- 레코드 유형(Record type):
- A - IPV4 주소로 트래픽 라우팅을 선택합니다. (도메인을 IP 주소에 연결하는 가장 일반적인 유형입니다.)
- 값(Value):
- Nginx 및 N8N이 설치된 AWS EC2 인스턴스의 퍼블릭 IP 주소를 입력합니다. (가급적 탄력적 IP 주소를 사용하는 것을 권장합니다. 탄력적 IP는 인스턴스 재부팅 시 IP가 변경되지 않습니다.)
- 예: 52.78.XXX.XXX
- TTL(Time to Live):
- 기본값 (300초)을 유지하거나 원하는 값으로 설정합니다. TTL이 짧을수록 DNS 변경 사항이 더 빨리 전파되지만, DNS 서버에 더 많은 부하를 줍니다.
- 라우팅 정책(Routing policy):
- 단순 라우팅(Simple routing)을 유지합니다.
- 레코드 이름(Record name):
- 레코드 생성:
- "레코드 생성" 버튼을 클릭하여 설정을 저장합니다.
DNS 전파 확인
터미널을 열어 다음 명령으로 DNS 전파를 확인할 수 있습니다.
nslookup agent.codegear.info
Nginx 설정
Nginx 설정 파일 구조 이해
Amazon Linux 2023의 Nginx는 일반적으로 /etc/nginx/nginx.conf가 메인 설정 파일이고, 이 파일 안에서 include /etc/nginx/conf.d/*.conf; 지시어를 통해 /etc/nginx/conf.d/ 디렉토리 안의 .conf 파일들을 불러옵니다.
따라서 우리는 주로 /etc/nginx/conf.d/agent.codegear.info.conf와 같은 별도의 파일을 생성하여 도메인별 설정을 관리하는 것이 좋습니다.
- 새로운 Nginx 설정 파일 생성: SSH로 EC2 인스턴스에 접속한 후, 다음 명령어를 사용하여 /etc/nginx/conf.d/ 디렉토리에 agent.codegear.info.conf 파일을 생성하고 편집합니다.
sudo nano /etc/nginx/conf.d/agent.codegear.info.conf
- 파일 내용 붙여넣기: vi 에디터에 다음 내용을 붙여넣으세요. 이 설정은 agent.codegear.info에 대한 HTTP/HTTPS 처리 및 N8N으로의 리버스 프록시를 담당합니다.내용을 붙여넣은 후 ecs를 누르고 :wq! 엔터를 입력하여 저장하고 종료합니다.
server { listen 80; listen [::]:80; server_name agent.codegear.info; # Certbot will use this location to verify domain ownership location /.well-known/acme-challenge { allow all; root /usr/share/nginx/html; # Ensure this directory exists and is readable by Nginx } }
- Certbot 실행 (필수): 위 Nginx 설정 파일은 agent.codegear.info에 대한 SSL 인증서가 /etc/letsencrypt/live/agent.codegear.info/ 경로에 있다고 가정합니다. 이 인증서는 Certbot을 실행해야 발급됩니다.
- Certbot이 agent.codegear.info 도메인을 인식하고, 해당 도메인에 대한 SSL 인증서를 발급받은 후, agent.codegear.info.conf 파일 내의 ssl_certificate와 ssl_certificate_key 경로를 자동으로 채우거나 확인해 줍니다.
- HTTP 트래픽을 HTTPS로 리디렉션할지 물으면 2: Redirect를 선택하는 것이 좋습니다.
sudo certbot --nginx -d agent.codegear.info
- Nginx 설정 테스트 및 재시작: 이제 새로운 설정 파일이 올바른지 확인하고 Nginx를 다시 시작하여 변경 사항을 적용합니다.sudo nginx -t 명령어가 syntax is ok와 test is successful을 반환해야 합니다.
sudo nginx -t # Nginx 설정 파일 문법 검사 sudo systemctl restart nginx # Nginx 서비스 재시작
- Certbot이 설정 파일에 SSL 관련된 셋팅을 자동으로 추가했으므로 이부분에 n8n이 사용하는 5678 포트로 redirect 처리가 필요합니다. 아래 내용을 ssl 아래에 추가하면 됩니다.
# --- Proxy headers for N8N ---
# Ensures N8N gets correct client IP, protocol, and host information.
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
# --- WebSocket support for N8N UI ---
# Crucial for N8N's real-time updates and interactive UI.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# --- Reverse proxy to N8N ---
location / {
proxy_pass http://localhost:5678/; # <-- Updated N8N internal port
proxy_http_version 1.1;
proxy_buffering off;
proxy_read_timeout 300s; # Increased timeout for long-running workflows
proxy_send_timeout 300s;
}
- 전체 설정 파일은 다음과 같습니다.
# --- HTTP Block: Handles HTTP requests and redirects to HTTPS ---
server {
listen 80;
listen [::]:80; # IPv6 listening
server_name agent.codegear.info;
# Certbot's domain validation challenge location.
# This must be present in the HTTP block to allow Certbot to renew certificates.
location ~ /.well-known/acme-challenge {
allow all;
root /usr/share/nginx/html; # Ensure this path is correct and accessible
}
# All other HTTP requests are permanently redirected to HTTPS.
# Certbot usually inserts/modifies this.
return 301 https://$host$request_uri;
}
# --- HTTPS Block: Handles secure (HTTPS) requests and proxies to N8N ---
server {
listen 443 ssl;
listen [::]:443 ssl; # IPv6 listening
http2 on; # Correct way to enable HTTP/2
server_name agent.codegear.info;
# --- Let's Encrypt (Certbot) managed SSL certificate paths ---
# These paths are filled in by Certbot after successful certificate issuance.
ssl_certificate /etc/letsencrypt/live/agent.codegear.info/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/agent.codegear.info/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf; # Certbot's recommended SSL options
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # Diffie-Hellman parameters for stronger security
# --- Proxy headers for N8N ---
# Ensures N8N gets correct client IP, protocol, and host information.
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
# --- WebSocket support for N8N UI ---
# Crucial for N8N's real-time updates and interactive UI.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# --- Reverse proxy to N8N ---
location / {
proxy_pass http://localhost:5678/; # <-- Updated N8N internal port
proxy_http_version 1.1;
proxy_buffering off;
proxy_read_timeout 300s; # Increased timeout for long-running workflows
proxy_send_timeout 300s;
}
# Optional: Error pages
# error_page 404 /404.html;
# location = /404.html { }
# error_page 500 502 503 504 /50x.html;
# location = /50x.html { }
}
최종 확인:
- 웹 브라우저를 열고 https://agent.codegear.info로 접속하여 N8N 웹 UI가 정상적으로 로드되는지 확인합니다.
- http://agent.codegear.info로 접속했을 때 자동으로 https://로 리디렉션되는지도 확인합니다.
이렇게 하면 기존 codegear.info 설정에 영향을 주지 않으면서 agent.codegear.info 서브도메인을 통해 n8n에 안전하게 접근할 수 있습니다.
'AI 워크플로우 자동화-n8n' 카테고리의 다른 글
n8n: 당신의 워크플로우를 자동화하는 오픈소스 엔진! (4) | 2025.06.29 |
---|