웹사이트 검색

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


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

  • 우분투 20.04(Focal Fossa)
  • 우분투 16.04(Xenial Xerus)

이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. Nginx, MariaDB 및 PHP 설치
  4. MariaDB 데이터베이스 생성
  5. 미디어위키 다운로드
  6. MediaWiki용 Nginx 구성
  7. MediaWiki 웹 UI에 액세스
  8. Lets Encrypt SSL로 MediaWiki 보안 유지
  9. 결론

MediaWiki는 PHP로 작성된 오픈 소스 위키 소프트웨어입니다. 서버에서 자체 호스팅 위키 웹사이트를 만들 수 있습니다. 단순성과 사용자 정의 가능성으로 인해 가장 인기 있는 위키 플랫폼 중 하나입니다. 현재 많은 회사에서 위키 페이지를 관리하는 데 사용하고 있습니다. 인터넷에 콘텐츠를 게시하기 위한 다목적 무료 도구를 제공합니다.

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

전제 조건

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

시작하기

먼저 다음 명령을 실행하여 시스템 패키지를 업데이트된 버전으로 업데이트합니다.

apt-get update -y

모든 패키지가 업데이트되면 다음 단계로 진행할 수 있습니다.

Nginx, MariaDB 및 PHP 설치

MediaWiki에는 Nginx 웹 서버, MariaDB 데이터베이스 서버, PHP 및 기타 확장이 필요합니다. 다음 명령으로 모두 설치할 수 있습니다.

apt-get install nginx mariadb-server php php-fpm php-mbstring php-xml php-json php-mysql php-curl php-intl php-gd php-mbstring texlive imagemagick unzip -y

모든 패키지가 설치되면 다음 명령을 사용하여 Composer를 설치합니다.

apt-get install composer -y

다음으로 php.ini 파일을 편집하고 기본 설정을 변경합니다.

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

다음 줄을 변경합니다.

memory_limit = 512M
post_max_size =32M
upload_max_filesize = 32M
date.timezone = Asia/Kolkata

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

systemctl restart php7.4-fpm

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

MariaDB 데이터베이스 생성

MediaWiki는 MariaDB를 데이터베이스 백엔드로 사용하므로 MediaWiki용 데이터베이스와 사용자를 생성해야 합니다.

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

mysql

연결되면 다음 명령을 사용하여 데이터베이스와 사용자를 만듭니다.

MariaDB [(none)]> CREATE DATABASE mediadb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON mediadb.* TO 'mediauser'@'localhost' IDENTIFIED BY 'password';

다음으로 다음 명령을 사용하여 권한을 플러시하고 MariaDB를 종료합니다.

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

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

미디어위키 다운로드

첫 번째. MediaWiki 웹사이트로 이동하여 최신 버전의 MediaWiki를 선택하십시오. 그런 다음 다음 명령을 실행하여 서버에 다운로드합니다.

wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.zip

다운로드가 완료되면 다음 명령을 사용하여 다운로드한 파일의 압축을 풉니다.

unzip mediawiki-1.35.2.zip

다음으로 다음 명령을 사용하여 추출된 디렉터리를 Nginx 웹 루트 디렉터리로 이동합니다.

mv mediawiki-1.35.2 /var/www/html/mediawiki

다음으로 디렉토리를 MediaWiki로 변경하고 다음 명령을 사용하여 모든 PHP 종속성을 설치합니다.

cd /var/www/html/mediawiki
composer install --no-dev

모든 종속 항목이 설치되면 다음 명령을 사용하여 적절한 권한과 소유권을 설정합니다.

chown -R www-data:www-data /var/www/html/mediawiki
chmod -R 755 /var/www/html/mediawiki

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

MediaWiki용 Nginx 구성

다음으로 MediaWiki용 Nginx 가상 호스트 구성 파일을 생성해야 합니다. 다음 명령으로 만들 수 있습니다.

nano /etc/nginx/conf.d/wiki.conf

다음 줄을 추가합니다.

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

        root /var/www/html/mediawiki;
        index index.php;
   
        error_log /var/log/nginx/mediawiki.error;
        access_log /var/log/nginx/mediawiki.access;

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


        location ~ /\.ht {
          deny all;
         }

        location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            include snippets/fastcgi-php.conf;
        }
}

파일을 저장하고 닫은 후 다음 명령을 사용하여 구문 오류가 있는지 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의 상태를 확인할 수도 있습니다.

systemctl status nginx

다음 출력이 표시되어야 합니다.

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-06-02 05:06:48 UTC; 3s ago
       Docs: man:nginx(8)
    Process: 24594 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 24605 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 24606 (nginx)
      Tasks: 2 (limit: 2353)
     Memory: 2.8M
     CGroup: /system.slice/nginx.service
             ??24606 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??24607 nginx: worker process

Jun 02 05:06:48 ubunt4 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 02 05:06:48 ubunt4 systemd[1]: Started A high performance web server and a reverse proxy server.

MediaWiki 웹 UI에 액세스

이제 웹 브라우저를 열고 URL http://wiki.example.com을 입력하십시오. 다음 페이지로 리디렉션됩니다.

이제 위키 설정 버튼을 클릭합니다. 다음 페이지가 표시됩니다.

여기에서 위키 언어를 선택하고 계속 버튼을 클릭합니다. 다음 페이지가 표시됩니다.

이제 계속 버튼을 클릭하십시오. 다음 페이지가 표시됩니다.

이제 데이터베이스 세부 정보를 제공하고 계속 버튼을 클릭하십시오. 다음 페이지가 표시됩니다.

설치와 동일한 계정 사용을 선택하고 계속 버튼을 클릭합니다. 다음 페이지가 표시됩니다.

이제 위키 사이트 이름, 사용자 이름 및 비밀번호를 제공하십시오. 그런 다음 계속 버튼을 클릭합니다. 다음 페이지가 표시됩니다.

계속 버튼을 클릭하여 설치를 시작합니다. 다음 페이지가 표시됩니다.

계속 버튼을 클릭합니다. 설치가 완료되면 다음 페이지가 표시됩니다.

이제 다운로드 버튼을 클릭하여 LocalSettings.php 파일을 시스템에 다운로드합니다. 그런 다음, 이 파일을 MediaWiki 루트 디렉토리 내의 서버에 복사하고 다음 명령으로 적절한 권한을 설정하십시오:

chown www-data:www-data /var/www/html/mediawiki/LocalSettings.php

그런 다음 웹 브라우저로 돌아가서 위키 입력을 클릭하십시오. 다음 페이지에 MediaWiki 대시보드가 표시되어야 합니다.

Lets Encrypt SSL로 MediaWiki 보호

다음으로 Lets Encrypt SSL 관리를 설치하려면 Certbot 클라이언트 패키지를 설치해야 합니다.

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

apt-get install python3-certbot-nginx -y

설치가 완료되면 다음 명령을 실행하여 웹사이트에 Lets Encrypt SSL을 설치합니다.

certbot --nginx -d wiki.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 wiki.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/wiki.conf

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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/wiki.conf

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/wiki.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/wiki.example.com/privkey.pem
   Your cert will expire on 2021-12-30. 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.

이제 웹사이트는 Lets Encrypt SSL로 보호됩니다. URL https://wiki.example.com을 사용하여 안전하게 액세스할 수 있습니다.

결론

축하합니다! Nginx와 함께 MediaWiki를 성공적으로 설치했으며 Ubuntu 20.04에서 SSL을 암호화합니다. 이제 MediaWiki로 자신만의 위키 사이트를 쉽게 호스팅할 수 있습니다.