웹사이트 검색

CentOS 8에서 Nginx 및 LE SSL을 사용하여 Flarum Forum을 설치하는 방법


이 페이지에서

  1. 요구 사항\n
  2. 시작하기\n
  3. Nginx, MariaDB 및 PHP 설치
  4. MariaDB 데이터베이스 구성
  5. Nginx용 PHP-FPM 구성
  6. 플라럼 설치\n
  7. Flarum용 Nginx 구성
  8. SELinux 및 방화벽 구성\n
  9. Flarum 웹 UI 액세스
  10. Lets Encrypt SSL로 Flarum 보안 유지

Flarum은 성공적인 온라인 커뮤니티를 쉽게 시작하고 성장시킬 수 있는 무료 오픈 소스 차세대 포럼 소프트웨어입니다. PHP 기반의 간단하고 가볍고 빠르고 모바일 친화적인 소프트웨어입니다. 우아한 UI, 2개 창 인터페이스, 무한 스크롤, 플로팅 컴포저, 완전 반응형 등 다양한 기능이 제공됩니다.

이 튜토리얼에서는 CentOS 8 서버에 Flarum 포럼을 설치하는 방법을 설명합니다.

요구 사항

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

시작하기

시작하기 전에 시스템에 EPEL 및 Remi 저장소를 설치해야 합니다. 먼저 다음 명령을 사용하여 EPEL 저장소를 설치합니다.

dnf install epel-release -y

그런 다음 다음 명령을 사용하여 Remi 리포지토리를 다운로드하고 설치합니다.

wget http://rpms.remirepo.net/enterprise/remi-release-8.rpm
rpm -Uvh remi-release-8.rpm

Nginx, MariaDB 및 PHP 설치

먼저 다음 명령을 사용하여 Nginx 웹 서버 및 MariaDB 서버를 설치합니다.

dnf install nginx mariadb-server -y

두 패키지가 모두 설치되면 php:remi-7.3 모듈을 활성화하여 PHP 7.3을 설치해야 합니다. 다음 명령으로 활성화할 수 있습니다.

dnf module enable php:remi-7.3

다음으로 다음 명령을 사용하여 다른 필수 종속성과 함께 PHP를 설치합니다.

dnf install php php-fpm php-common php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml -y

모든 패키지가 설치되면 Nginx, MariaDB 및 PHP-FPM 서비스를 시작하고 다음 명령을 사용하여 시스템 재부팅 후 시작할 수 있도록 합니다.

systemctl start nginx
systemctl start mariadb
systemctl start php-fpm
systemctl enable nginx
systemctl enable mariadb
systemctl enable php-fpm

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

MariaDB 데이터베이스 구성

기본적으로 MariaDB는 보안되지 않습니다. 다음 스크립트를 사용하여 보안을 유지할 수 있습니다.

mysql_secure_installation

아래와 같이 모든 질문에 답하십시오.

Enter current password for root (enter for none):
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

완료되면 다음 명령을 사용하여 MariaDB 셸에 로그인합니다.

mysql -u root -p

프롬프트가 표시되면 루트 암호를 제공한 후 다음 명령을 사용하여 Flarum에 대한 데이터베이스 및 사용자를 생성합니다.

MariaDB [(none)]> CREATE DATABASE flarumdb;
MariaDB [(none)]> GRANT ALL PRIVILEGES on flarumdb.* to 'flarum'@'localhost' identified by 'password';

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

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

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

Nginx용 PHP-FPM 구성

다음으로 Nginx와 함께 작동하도록 PHP-FPM을 구성해야 합니다. www.conf 파일을 편집하면 됩니다.

nano /etc/php-fpm.d/www.conf

아래와 같이 사용자 및 그룹 이름을 apache에서 nginx로 변경합니다.

user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx

다음으로 다음 행을 찾으십시오.

;listen = /run/php-fpm/www.sock

그리고 다음 줄로 바꿉니다.

listen = 127.0.0.1:9000

완료되면 파일을 저장하고 닫습니다. 그런 다음 PHP-FPM 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart php-fpm

플라럼 설치

Flarum을 설치하기 전에 시스템에 Composer를 설치해야 합니다.

다음 명령으로 설치할 수 있습니다.

curl -sS https://getcomposer.org/installer | php

설치가 완료되면 다음과 같은 결과가 표시됩니다.

All settings correct for using Composer
Downloading...

Composer (version 1.9.2) successfully installed to: /root/composer.phar
Use it: php composer.phar

다음으로 Composer 바이너리 파일을 /usr/local/bin 디렉토리로 이동하고 적절한 권한을 부여합니다.

mv composer.phar /usr/local/bin/composer
chmod 755 /usr/local/bin/composer

다음으로 디렉터리를 Nginx 문서 루트로 변경하고 다음 명령을 사용하여 Flarum 프로젝트를 만듭니다.

cd /var/www/html
composer create-project flarum/flarum . --stability=beta

다음으로 다음 명령을 사용하여 Nginx 웹 루트 디렉터리에 대한 적절한 권한을 부여합니다.

chown -R nginx:nginx /var/www/html
chmod -R 755 /var/www/html
chown -R nginx:nginx /var/lib/php

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

Flarum용 Nginx 구성

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

nano /etc/nginx/conf.d/flarum.conf

다음 줄을 추가합니다.

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

# note that these lines are originally from the "location /" block
root   /var/www/html/public;
index index.php index.html index.htm;

location / { try_files $uri $uri/ /index.php?$query_string; }
location /api { try_files $uri $uri/ /api.php?$query_string; }
location /admin { try_files $uri $uri/ /admin.php?$query_string; }

location /flarum {
    deny all;
    return 404;
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~* \.html$ {
    expires -1;
}

location ~* \.(css|js|gif|jpe?g|png)$ {
    expires 1M;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types application/atom+xml
           application/javascript
           application/json
           application/vnd.ms-fontobject
           application/x-font-ttf
           application/x-web-app-manifest+json
           application/xhtml+xml
           application/xml
           font/opentype
           image/svg+xml
           image/x-icon
           text/css
           #text/html -- text/html is gzipped by default by nginx
           text/plain
           text/xml;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
   }

완료되면 파일을 저장하고 닫습니다. 다음으로 nginx.conf 파일에서 hash_bucket 크기를 늘려야 합니다.

/etc/nginx/nginx.conf 파일을 편집하면 됩니다.

nano /etc/nginx/nginx.conf

마지막 줄 바로 위에 다음 줄을 추가합니다.

server_names_hash_bucket_size 64;

파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 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 및 PHP-FPM 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart php-fpm
systemctl restart nginx

SELinux 및 방화벽 구성

먼저 외부 네트워크에서 HTTP 및 HTTPS 서비스를 허용하도록 방화벽 규칙을 생성해야 합니다. 다음 명령으로 허용할 수 있습니다.

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

기본적으로 SELinux는 CentOS 8에서 활성화되어 있습니다. 따라서 Flarum이 올바르게 작동하려면 SELinux를 구성해야 합니다. 다음 명령을 사용하여 SELinux를 구성할 수 있습니다.

setsebool httpd_can_network_connect on -P

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

Flarum 웹 UI에 액세스

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

포럼 이름, 데이터베이스 세부 정보, 관리자 사용자 이름, 암호를 제공하고 Flarum 설치 버튼을 클릭합니다. 설치가 성공적으로 완료되면 다음 페이지에 Flarum 대시보드가 표시됩니다.

Lets Encrypt SSL로 안전한 Flarum

이제 Flarum이 설치 및 구성되었습니다. 무료 SSL을 Lets Encrypt로 보호할 때입니다.

이렇게 하려면 서버에서 certbot 클라이언트를 다운로드해야 합니다. 다음 명령을 실행하여 올바른 권한을 다운로드하고 설정할 수 있습니다.

wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto

이제 다음 명령을 실행하여 flarum 웹 사이트에 대한 SSL 인증서를 가져와 설치합니다.

certbot-auto --nginx -d flarum.example.com

위의 명령은 먼저 서버에 필요한 모든 종속성을 설치합니다. 설치가 완료되면 아래와 같이 이메일 주소를 제공하고 서비스 약관에 동의하라는 메시지가 표시됩니다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
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 flarum.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/flarum.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/flarum.conf

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/flarum.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/flarum.example.com/privkey.pem
   Your cert will expire on 2020-03-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto renew"
 - 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

그게 다야! 이제 보안 URL https://flarum.example.com을 사용하여 Flarum 웹사이트에 액세스할 수 있습니다.