PHP, MariaDB로 Lighttpd를 설치하고 데비안 10에서 SSL을 암호화하는 방법
이 페이지에서
- 요구 사항\n
- 시작하기\n
- Lighttpd 설치
- MariaDB 서버 설치
- PHP 및 PHP-FPM 설치
- Lighttpd 가상 호스트 만들기\n
- Lets Encrypt 무료 SSL로 Lighttpd 보안
- Lighttpd 웹 인터페이스 액세스
- 결론
Lighttpd는 속도가 중요한 환경을 위해 특별히 설계된 무료 오픈 소스 고속 웹 서버입니다. Apache 및 Nginx와 같은 다른 웹 서버에 비해 메모리 사용량이 적고 AJAX 애플리케이션을 실행하는 데 특히 빠릅니다. Lighttpd를 사용하면 FastCGI, SCGI 및 CGI 인터페이스를 사용하여 다른 프로그래밍 언어로 작성된 웹 응용 프로그램을 호스팅할 수도 있습니다. 서버에 로드 문제가 있는 경우 Lighttpd가 최선의 선택입니다.
이 튜토리얼에서는 PHP-FPM 및 MariaDB 지원으로 Debian 10에 Lighttpd를 설치하는 방법을 배우고 Lets Encrypt SSL 인증서로 웹 서버를 보호합니다.
요구 사항
- Debian 10을 실행하는 서버.\n
- 루트 비밀번호가 서버에 설정됩니다.\n
이 자습서에서는 도메인 이름 example.com을 사용합니다. 모든 파일 이름 및 구성 설정에서 example.com을 아래의 고유한 도메인 이름으로 바꾸십시오.
시작하기
시작하기 전에 시스템을 최신 버전으로 업데이트해야 합니다. 다음 명령을 실행하여 이를 수행할 수 있습니다.
apt-get update -y
apt-get upgrade -y
서버가 업데이트되면 서버를 다시 시작하여 변경 사항을 적용하십시오.
Lighttpd 설치
기본적으로 Lighttpd는 Debian 10 기본 리포지토리에서 사용할 수 있습니다. 다음 명령을 실행하여 설치할 수 있습니다.
apt-get install lighttpd -y
설치가 완료되면 Lighttpd 서비스를 시작하고 다음 명령을 사용하여 시스템 재부팅 후 시작하도록 활성화합니다.
systemctl start lighttpd
systemctl enable lighttpd
다음 명령을 사용하여 Lighttpd의 상태를 확인할 수도 있습니다.
systemctl status lighttpd
다음 출력이 표시되어야 합니다.
? lighttpd.service - Lighttpd Daemon Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-09-06 02:09:35 EDT; 29s ago Main PID: 4445 (lighttpd) Tasks: 1 (limit: 1138) Memory: 1.4M CGroup: /system.slice/lighttpd.service ??4445 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf Sep 06 02:09:35 debian systemd[1]: Starting Lighttpd Daemon... Sep 06 02:09:35 debian systemd[1]: Started Lighttpd Daemon. Sep 06 02:09:36 debian systemd[1]: /lib/systemd/system/lighttpd.service:6: PIDFile= references path below legacy directory /var/run/, updating lines 1-12/12 (END)
완료되면 다음 단계로 진행할 수 있습니다.
MariaDB 서버 설치
다음 명령을 실행하여 MariaDB 서버를 설치할 수 있습니다.
apt-get install mariadb-server mariadb-client -y
일단 설치되면 MariaDB 설치를 보호해야 합니다. 다음 스크립트를 실행하여 보안을 설정할 수 있습니다.
mysql_secure_installation
Answer all the questions as shown below: Change the root password? [Y/n] n 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
완료되면 다음 단계로 진행할 수 있습니다.
PHP 및 PHP-FPM 설치
다음으로 시스템에 PHP, PHP-FPM 및 FastCGI를 설치해야 합니다. 기본적으로 Debian 10은 PHP 버전 7.3과 함께 제공됩니다. 다음 명령을 실행하여 설치할 수 있습니다.
apt-get install php php-cgi php-fpm php-mysql -y
모든 패키지가 설치되면 php.ini 파일을 편집하고 cgi.fix_pathinfo를 1로 설정해야 합니다. 다음 명령을 사용하여 이를 수행할 수 있습니다.
nano /etc/php/7.3/fpm/php.ini
다음 줄을 변경합니다.
cgi.fix_pathinfo=1
완료되면 파일을 저장하고 닫습니다.
기본적으로 PHP는 UNIX 소켓 /var/run/php/php7.3-fpm.sock을 가리킵니다. 따라서 PHP가 TCP 소켓을 수신하도록 설정하려면 PHP-FPM 풀을 구성해야 합니다.
/etc/php/7.3/fpm/pool.d/www.conf 파일을 편집하여 이를 수행할 수 있습니다.
nano /etc/php/7.3/fpm/pool.d/www.conf
다음 줄을 찾으십시오.
listen = /run/php/php7.3-fpm.sock
그리고 다음 줄로 바꿉니다.
listen = 127.0.0.1:9000
완료되면 파일을 저장하고 닫습니다. 그런 다음 PHP-FPM 서비스를 다시 시작하여 구성 변경 사항을 적용합니다.
systemctl restart php7.3-fpm
다음으로 15-fastcgi-php.conf 파일을 수정해야 합니다.
nano /etc/lighttpd/conf-available/15-fastcgi-php.conf
다음 줄을 찾으십시오.
"bin-path" => "/usr/bin/php-cgi", "socket" => "/var/run/lighttpd/php.socket",
그리고 다음과 같이 교체하십시오.
"host" => "127.0.0.1", "port" => "9000",
완료되면 파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 FastCGI 및 FastCHI-PHP 모듈을 모두 활성화합니다.
lighty-enable-mod fastcgi
lighty-enable-mod fastcgi-php
마지막으로 Lighttpd 서비스를 다시 시작하여 변경 사항을 적용합니다.
systemctl restart lighttpd
Lighttpd 가상 호스트 생성
다음으로 Lighttpd로 PHP를 테스트하기 위해 새로운 가상 호스트 파일을 생성해야 합니다. 다음 명령으로 만들 수 있습니다.
nano /etc/lighttpd/conf-available/example.com.conf
다음 줄을 추가합니다.
$HTTP["host"] == "www.example.com" { server.document-root = "/var/www/html/" server.errorlog = "/var/log/lighttpd/example.com-error.log" }
완료되면 파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 가상 호스트를 활성화합니다.
ln -s /etc/lighttpd/conf-available/example.com.conf /etc/lighttpd/conf-enabled/
다음으로 다음 명령을 사용하여 Lighttpd 문서 루트 디렉터리에 샘플 index.php 파일을 생성합니다.
nano /var/www/html/index.php
다음 줄을 추가합니다.
<?php phpinfo(); ?>
파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 Lighttpd 문서 루트 디렉터리의 소유권을 www-data로 변경합니다.
chown -R www-data:www-data /var/www/html/
마지막으로 Lighttpd 서비스를 다시 시작하여 모든 구성 변경 사항을 적용합니다.
systemctl restart lighttpd
Lets Encrypt 무료 SSL로 Lighttpd 보호
먼저 Let’s Encrypt로 웹 서버를 보호하려면 Certbot 도구를 설치해야 합니다. 기본적으로 최신 버전의 Certbot은 Debian 10 기본 리포지토리에서 사용할 수 없습니다.
다음 명령을 사용하여 Certbot 리포지토리를 추가할 수 있습니다.
apt-get install software-properties-common
add-apt-repository ppa:certbot/certbot
다음으로 다음 명령을 사용하여 리포지토리를 업데이트하고 Certbot을 설치합니다.
apt-get update -y
apt-get install certbot -y
다음으로 다음 명령을 사용하여 Let’s Encrypt 인증서를 생성합니다.
certbot certonly --webroot -w /var/www/html/ -d www.example.com
아래와 같이 이메일 주소를 제공하고 라이선스 조건에 동의하라는 메시지가 표시됩니다.
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator webroot, Installer None 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
인증서가 성공적으로 다운로드되면 다음 출력이 표시됩니다.
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2019-12-06. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot 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
다음으로 인증서와 개인 키를 하나의 파일에 결합해야 합니다. 다음 명령으로 수행할 수 있습니다.
cat /etc/letsencrypt/live/example.com/cert.pem /etc/letsencrypt/live/example.com/privkey.pem > /etc/letsencrypt/live/example.com/web.pem
다음으로 Lighttpd 가상 호스트 파일을 편집하고 Lets Encrypt SSL 인증서 경로를 정의해야 합니다.
다음 명령으로 수행할 수 있습니다.
nano /etc/lighttpd/conf-enabled/example.com.conf
아래와 같이 파일을 변경합니다.
$HTTP["host"] == "www.example.com" { server.document-root = "/var/www/html/" } $SERVER["socket"] == ":443" { ssl.engine = "enable" ssl.pemfile = "/etc/letsencrypt/live/example.com/web.pem" # Combined Certificate ssl.ca-file = "/etc/letsencrypt/live/example.com/chain.pem" # Root CA server.name = "www.example.com" # Domain Name OR Virtual Host Name server.document-root = "/var/www/html/" # Document Root server.errorlog = "/var/log/lighttpd/example.com_error.log" accesslog.filename = "/var/log/lighttpd/example.com_access.log" } $HTTP["scheme"] == "http" { $HTTP["host"] == "www.example.com" { # HTTP URL url.redirect = ("/.*" => "https://www.example.com$0") # Redirection HTTPS URL } }
파일을 저장하고 닫습니다. 그런 다음 Lighttpd 서비스를 다시 시작하여 구성 변경 사항을 적용합니다.
systemctl restart lighttpd
Lighttpd 웹 인터페이스에 액세스
Lighttpd는 PHP 및 PHP-FPM 지원으로 설치 및 구성됩니다. 이제 테스트할 시간입니다.
웹 브라우저를 열고 URL https://www.example.com을 입력합니다. 다음 페이지로 리디렉션됩니다.
위의 페이지는 PHP가 FastCGI와 잘 작동함을 나타냅니다.
결론
축하합니다! Debian 10에서 PHP-FPM 및 FastCGI 지원으로 Lighttpd 웹 서버를 성공적으로 설치하고 구성했습니다. 이제 자신의 웹 서버를 쉽게 호스팅할 수 있습니다. 자세한 내용은 Lighttpd Doc의 Lighttpd 공식 문서 페이지를 참조하세요.