[카테고리:] 우분투

  • 우분투24.04 외부메일서버 구축방법

    우분투에서 외부 메일 서버(Postfix + Dovecot + Let’s Encrypt + MySQL)를 구축하는 방법을 단계별로 설명해 드릴게요.


    1. 서버 준비

    필수 사항

    • 도메인 이름(예: mail.example.com)
    • 우분투 서버 (권장: 20.04 이상)
    • 고정 IP 주소
    • 방화벽 설정 가능(iptables 또는 UFW)

    DNS 설정

    DNS 관리 패널에서 다음 레코드를 추가해야 합니다.

    레코드 유형호스트명값 (예제)
    Amail.example.com서버의 공인 IP 주소
    MXexample.commail.example.com (우선순위 10)
    TXTexample.comv=spf1 mx -all
    TXT_dmarc.example.comv=DMARC1; p=none

    2. 패키지 설치

    sudo apt update && sudo apt upgrade -y
    sudo apt install postfix postfix-mysql dovecot-core dovecot-imapd dovecot-mysql mysql-server certbot -y

    3. MySQL 데이터베이스 설정

    sudo mysql -u root -p
    CREATE DATABASE mailserver;
    CREATE USER 'mailuser'@'localhost' IDENTIFIED BY 'yourpassword';
    GRANT ALL PRIVILEGES ON mailserver.* TO 'mailuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;

    4. Postfix 설정

    sudo nano /etc/postfix/main.cf

    다음 설정 추가 또는 수정:

    myhostname = mail.example.com
    mydestination = example.com, localhost
    relayhost =
    inet_interfaces = all
    home_mailbox = Maildir/
    smtpd_tls_cert_file=/etc/letsencrypt/live/mail.example.com/fullchain.pem
    smtpd_tls_key_file=/etc/letsencrypt/live/mail.example.com/privkey.pem
    smtpd_use_tls=yes

    저장 후 Postfix 재시작:

    sudo systemctl restart postfix

    5. Dovecot 설정

    sudo nano /etc/dovecot/dovecot.conf
    protocols = imap lmtp
    ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
    ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem

    Dovecot 재시작:

    sudo systemctl restart dovecot

    6. SSL 인증서 설정 (Let’s Encrypt)

    sudo certbot certonly --standalone -d mail.example.com

    7. 방화벽 설정

    sudo ufw allow 25/tcp
    sudo ufw allow 587/tcp
    sudo ufw allow 993/tcp
    sudo ufw reload

    8. 테스트

    • telnet mail.example.com 25로 SMTP 테스트
    • openssl s_client -connect mail.example.com:993 -quiet로 IMAP SSL 확인
    • mail -s "Test Email" user@example.com으로 메일 발송 테스트

    이제 기본적인 메일 서버가 구축되었습니다. Roundcube 같은 웹메일 클라이언트를 설치하면 웹에서 메일을 확인할 수도 있습니다.

  • Nginx에서 Certbot을 사용하여 Let’s Encrypt SSL 인증서를 설정하는 방법

    1. Certbot 및 플러그인 설치

    먼저, Certbot과 Nginx 플러그인을 설치해야 합니다.

    Ubuntu/Debian

    sudo apt update
    sudo apt install certbot python3-certbot-nginx -y

    CentOS/RHEL

    sudo yum install epel-release -y
    sudo yum install certbot python3-certbot-nginx -y

    2. Nginx 구성 확인

    Let’s Encrypt가 도메인 소유권을 확인하려면, Nginx에서 해당 도메인을 처리할 수 있어야 합니다.

    기본적인 Nginx 설정 예시

    /etc/nginx/sites-enabled/example.conf 또는 /etc/nginx/conf.d/example.com.conf에 아래 설정을 추가:

    server {
    listen 80;
    server_name example.com www.example.com;

    location /.well-known/acme-challenge/ {
    root /var/www/html;
    }

    location / {
    return 301 https://$host$request_uri;
    }
    }

    이후 설정을 적용:

    sudo nginx -t  # 설정 검증
    sudo systemctl reload nginx # Nginx 재시작

    3. Let’s Encrypt SSL 인증서 발급

    Nginx 플러그인을 사용하여 SSL 인증서를 자동으로 발급 및 설정할 수 있습니다.

    sudo certbot --nginx -d example.com -d www.example.com
    • -d example.com -d www.example.com: 인증서를 적용할 도메인 지정
    • 실행 후 이메일 입력 및 이용 약관 동의가 필요함.

    4. 인증서 자동 갱신 설정

    Let’s Encrypt 인증서는 90일마다 갱신해야 하므로 자동 갱신을 설정합니다.

    갱신 테스트:

    sudo certbot renew --dry-run

    자동 갱신을 위해 Cron 작업 추가 (보통 자동 등록됨):

    sudo crontab -e

    아래 줄 추가:

    0 3 * * * certbot renew --quiet && systemctl reload nginx

    이 설정은 매일 오전 3시에 인증서를 갱신하고, Nginx를 재시작합니다.


    5. 발급된 인증서 확인

    sudo certbot certificates

    SSL 인증서가 /etc/letsencrypt/live/example.com/ 경로에 저장됩니다.


    6. SSL 설정 적용

    Nginx 설정을 변경하여 HTTPS를 적용합니다.

    server {
    listen 443 ssl;
    server_name example.com www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    location / {
    root /var/www/html;
    index index.html;
    }
    }

    server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
    }

    Nginx 재시작:

    sudo nginx -t  # 설정 검증
    sudo systemctl restart nginx # 적용
  • 우분투 24.04 nginx에 ssl 연결하는방법

    먼저 기본 NGINX 구성을 제거합니다.

    rm /etc/nginx/sites-enabled/default
    

    이제 아래 파일의 내용을 붙여넣고, <domain>도메인 이름을 파일에서 사용하고,

    nano /etc/nginx/sites-enabled/domain.conf

    server {
        # Replace the example <domain> with your domain name or IP address
        listen 80;
        server_name <domain>;
        return 301 https://$server_name$request_uri;
    }
    
    server {
        # Replace the example <domain> with your domain name or IP address
        listen 443 ssl http2;
        server_name <domain>;
    
        root /var/www/pterodactyl/public;
        index index.php;
    
        access_log /var/log/nginx/<domain>.app-access.log;
        error_log  /var/log/nginx/<domain>.app-error.log error;
    
        # allow larger file uploads and longer script runtimes
        client_max_body_size 100m;
        client_body_timeout 120s;
    
        sendfile off;
    
        # SSL Configuration - Replace the example <domain> with your domain
        ssl_certificate /etc/letsencrypt/live/<domain>/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/<domain>/privkey.pem;
        ssl_session_cache shared:SSL:10m;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384";
        ssl_prefer_server_ciphers on;
    
        # See https://hstspreload.org/ before uncommenting the line below.
        # add_header Strict-Transport-Security "max-age=15768000; preload;";
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/run/php/php8.3-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param HTTP_PROXY "";
            fastcgi_intercept_errors off;
            fastcgi_buffer_size 16k;
            fastcgi_buffers 4 16k;
            fastcgi_connect_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_read_timeout 300;
            include /etc/nginx/fastcgi_params;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    

  • 우분투란 무엇인가

    우분투(Ubuntu)는 **리눅스(Linux) 기반의 운영 체제(OS)**로, 데비안(Debian) 리눅스를 기반으로 개발되었습니다. 주로 개인용 컴퓨터, 서버, 클라우드 환경 등에서 많이 사용되며, 무료로 제공되는 오픈 소스 운영 체제입니다.

    🔹 우분투의 특징

    1. 무료 및 오픈 소스
      • 누구나 자유롭게 다운로드하고 사용할 수 있으며, 소스 코드도 공개되어 있어 개발자들이 직접 수정 및 배포할 수 있습니다.
    2. 사용자 친화적
      • 다른 리눅스 배포판에 비해 설치와 사용이 쉬워, 리눅스를 처음 접하는 사용자에게 적합합니다.
      • 그래픽 인터페이스(GUI)가 깔끔하여 윈도우나 macOS 사용자도 쉽게 적응 가능합니다.
    3. 정기적인 업데이트
      • 일반 버전(Regular Release): 6개월마다 새로운 버전 출시
      • LTS 버전(Long Term Support, 장기 지원 버전): 2년마다 출시되며 5년간 보안 및 기능 업데이트 지원
    4. 강력한 보안성
      • 기본적으로 바이러스가 거의 없으며, 방화벽 및 보안 패치가 꾸준히 제공됨
      • 서버용 운영 체제로도 많이 사용됨 (ex: 웹 서버, 데이터베이스 서버 등)
    5. 패키지 관리 시스템(Apt, Snap 지원)
      • apt 명령어로 손쉽게 소프트웨어를 설치 및 관리할 수 있음
      • snap 패키지를 이용하면 최신 소프트웨어를 빠르게 설치 가능

    🔹 우분투의 주요 용도

    개인용 OS – 일반적인 데스크톱, 노트북용 운영 체제
    서버 운영 – 웹 서버(Nginx, Apache), 데이터베이스 서버(MySQL, PostgreSQL) 등
    클라우드 및 가상화 – AWS, Google Cloud 등 클라우드 환경에서 널리 사용
    개발 환경 – 프로그래머들이 주로 사용하는 OS (특히 Python, Java, C++ 개발에 최적화)
    임베디드 시스템 – IoT 기기, 로봇 등 다양한 하드웨어에서 활용

    🔹 우분투 다운로드 및 설치

    우분투 공식 사이트(🔗 https://ubuntu.com)에서 최신 버전을 다운로드하여 USB 또는 가상 머신(VMware, VirtualBox 등)에 설치할 수 있습니다.

    🔸 우분투를 처음 사용하시나요?
    윈도우와 비교하면 설치 방식과 파일 시스템이 조금 다르지만, 기본적인 사용법을 익히면 서버 관리 및 개발 환경 구축에 매우 유용합니다! 😊