웹사이트 검색

Nginx로 Moodle을 설치하고 Ubuntu 20.04에서 SSL을 암호화하는 방법


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • 우분투 16.04(Xenial Xerus)

이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. LEMP 설치
  4. 데이터베이스 만들기
  5. 무들 설치
  6. Moodle용 Nginx 구성
  7. Moodle 웹 인터페이스 액세스
  8. Lets Encrypt SSL로 안전한 Moodle\n
  9. 결론

Moodle은 PHP로 작성된 무료 오픈 소스 학습 관리 시스템입니다. 튜터와 강사가 학생 또는 학습자를 위한 코스를 만들 수 있는 방법을 제공합니다. Moodle은 강력하고 안전한 통합 시스템을 제공하며 사용자가 현재, 과거 또는 미래 코스에 액세스하고 보류 중인 작업을 검토하는 데 도움이 되는 맞춤형 대시보드와 함께 제공됩니다. 전 세계의 많은 학교, 대학 및 조직에서 사용하며 더 나은 학습 경험을 제공합니다. 위키, 채점, 과제 제출, 온라인 퀴즈, 토론 게시판 등을 포함한 다양한 기능을 제공합니다.

이 튜토리얼에서는 Ubuntu 20.04에서 Nginx 웹 서버와 Lets Encrypt SSL을 사용하여 Moodle을 설치하는 방법을 보여줍니다.

전제 조건

  • Ubuntu 20.04를 실행하는 서버.\n
  • 서버 IP를 가리키는 유효한 도메인 이름입니다.\n
  • 루트 암호는 서버에 구성됩니다.\n

시작하기

시작하기 전에 시스템 패키지를 최신 버전으로 업데이트해야 합니다. 다음 명령을 사용하여 업데이트할 수 있습니다.

apt-get update -y

서버가 업데이트되면 다음 단계로 진행할 수 있습니다.

LEMP 설치

먼저 시스템에 Apache, MariaDB, PHP 및 기타 PHP 라이브러리를 설치해야 합니다. 다음 명령을 사용하여 모두 설치할 수 있습니다.

apt-get install nginx mariadb-server php-fpm php-common php-mysql php-gmp php-curl php-intl php-mbstring php-soap php-xmlrpc php-gd php-xml php-cli php-zip unzip git curl -y

모든 패키지가 설치되면 php.ini 파일을 편집하고 일부 설정을 변경합니다.

nano /etc/php/7.4/fpm/php.ini

다음 줄을 변경합니다.

memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

파일을 저장하고 닫은 다음 PHP-FPM 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart php7.4-fpm

완료되면 다음 단계로 진행할 수 있습니다.

데이터베이스 생성

Moodle은 MySQL 또는 MariaDB를 데이터베이스 백엔드로 사용하므로 Moodle용 데이터베이스 및 사용자를 생성해야 합니다.

먼저 다음 명령을 사용하여 MySQL 셸에 연결합니다.

mysql

로그인 후 다음 명령을 사용하여 데이터베이스와 사용자를 생성합니다.

CREATE DATABASE moodledb;
CREATE USER 'moodle'@'localhost' IDENTIFIED BY 'password';

다음으로 다음 명령을 사용하여 Moodle 데이터베이스에 대한 모든 권한을 부여합니다.

GRANT ALL ON moodledb.* TO 'moodle'@'localhost' WITH GRANT OPTION;

그런 다음 권한을 플러시하고 다음 명령을 사용하여 MySQL을 종료합니다.

FLUSH PRIVILEGES;
EXIT;

다음으로 MariaDB 기본 구성 파일을 편집하고 innodb_file_format을 정의합니다.

nano /etc/mysql/mariadb.conf.d/50-server.cnf

[mysqld] 섹션 안에 다음 줄을 추가합니다.

[mysqld]
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix = ON

파일을 저장한 다음 MariaDB 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart mariadb

무들 설치

먼저 디렉토리를 Apache 루트 디렉토리로 변경하고 다음 명령을 사용하여 최신 버전의 Moodle을 다운로드합니다.

cd /var/www/html
git clone -b MOODLE_38_STABLE git://git.moodle.org/moodle.git moodle

다운로드가 완료되면 Moodle config.php를 편집하고 데이터베이스 유형을 정의합니다.

nano /var/www/html/moodle/config.php

다음 줄을 찾으십시오.

$CFG->dbtype    = 'mysqli';

그리고 다음 줄로 교체했습니다.

$CFG->dbtype    = 'mariadb';

파일을 저장하고 닫은 후 다음 명령을 사용하여 적절한 소유권과 권한을 설정한 Moodle 데이터 디렉토리를 만듭니다.

mkdir -p /var/www/html/moodledata
chown -R www-data:www-data /var/www/html/moodle
chmod -R 755 /var/www/html/*
chown www-data:www-data /var/www/html/moodledata

완료되면 다음 단계로 진행할 수 있습니다.

Moodle용 Nginx 구성

다음으로 Moodle을 호스팅하기 위해 Nginx 가상 호스트 구성 파일을 생성해야 합니다.

nano /etc/nginx/conf.d/moodle.conf

다음 줄을 추가합니다.

server {
    listen 80;
    root /var/www/html/moodle;
    index  index.php index.html index.htm;
    server_name  moodle.example.com;

    client_max_body_size 100M;
    autoindex off;
    location / {
        try_files $uri $uri/ =404;
    }

    location /dataroot/ {
      internal;
      alias /var/www/html/moodledata/;
    }

    location ~ [^/].php(/|$) {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

파일을 저장하고 닫은 후 다음 명령을 사용하여 구문 오류가 있는지 Nginx를 확인합니다.

nginx -t

다음과 같은 결과가 표시되어야 합니다.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

마지막으로 Nginx 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart nginx

이 시점에서 Nginx는 Moodle을 호스팅하도록 구성됩니다. 이제 다음 단계를 진행할 수 있습니다.

Moodle 웹 인터페이스에 액세스

이제 웹 브라우저를 열고 URL http://moodle.example.com을 사용하여 Moodle 웹 인터페이스에 액세스하십시오. Moodle 설치 페이지가 표시됩니다.

언어를 선택하고 다음을 클릭합니다. 다음 페이지가 표시됩니다.

Moodle 웹 주소, 디렉토리 경로, 데이터 디렉토리 경로를 제공하고 다음을 클릭하십시오. 다음 페이지가 표시됩니다.

데이터베이스 드라이버 유형을 선택하고 다음을 클릭합니다. 다음 페이지가 표시됩니다.

데이터베이스 호스트, 데이터베이스 이름, 사용자 이름, 암호를 제공하고 다음을 클릭합니다. 다음 페이지가 표시됩니다.

계속을 클릭하여 모든 조건을 확인합니다. 다음 페이지가 표시됩니다.

필요한 모든 PHP 확장이 설치되었는지 확인한 다음 계속을 클릭하십시오. 다음 페이지가 표시됩니다.

계속을 클릭합니다. 다음 페이지가 표시됩니다.

관리자 사용자 이름, 비밀번호, 이메일, 국가, 시간대를 제공하고 프로필 업데이트를 클릭합니다. 다음 페이지가 표시됩니다.

첫 페이지 설정을 제공하고 변경 사항 저장 버튼을 클릭하여 변경 사항을 저장하십시오.

Lets Encrypt SSL로 안전한 무들

다음으로 Lets Encrypt SSL을 다운로드하고 이 SSL을 사용하도록 Nginx를 구성하려면 Certbot 도구를 설치해야 합니다.

먼저 다음 명령을 사용하여 Certbot을 설치합니다.

apt-get install python3-certbot-nginx -y

설치가 완료되면 다음 명령을 실행하여 모든 SSL을 다운로드하고 이를 사용하도록 Nginx를 구성합니다.

certbot --nginx -d moodle.example.com

유효한 이메일 주소를 제공하고 아래와 같이 서비스 약관에 동의하라는 메시지가 표시됩니다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for moodle.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/moodle.conf

다음으로 아래와 같이 HTTP 트래픽을 HTTPS로 리디렉션할지 여부를 선택합니다.

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

2를 입력하고 Enter를 눌러 계속하십시오. 다음 출력이 표시되어야 합니다.

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/moodle.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://moodle.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=moodle.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/moodle.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/moodle.example.com/privkey.pem
   Your cert will expire on 2021-05-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

이제 URL http://moodle.example.com을 사용하여 Moodle 웹사이트에 액세스할 수 있습니다.

결론

축하합니다! Nginx와 함께 Moodle을 성공적으로 설치했으며 Ubuntu 20.04에서 Lets Encrypt SSL을 사용했습니다. 이제 Moodle을 사용하여 자신만의 학습 관리 시스템을 쉽게 만들 수 있습니다.