Ubuntu Linux에 Apache Free HTTPS 인증서 설치

이 튜토리얼은 Ubuntu Linux에 Apache Free HTTPS 인증서를 설치하는 데 필요한 모든 단계를 보여줍니다.

우분투 리눅스에 아파치 설치하기

적절한 PHP를 지원하는 Apache를 설치해 보겠습니다.

Ubuntu APT 명령을 사용하여 Apache 서버를 설치하십시오.

# apt-get update
# apt-get install apache2 php7.2 php7.2-mysql libapache2-mod-php7.2
# service apache2 restart

선택 과목. 다음 명령을 사용하여 가장 많이 사용되는 Apache PHP 모듈을 설치하십시오.

# apt-get install php7.2-xml php7.2-curl php7.2-gd php7.2-mbstring
# apt-get install php7.2-bz2 php7.2-zip php7.2-json php7.2-readline

Apache mod_ssl을 활성화하십시오.

Apache mod_rewrite를 활성화하십시오.

apache2.conf 파일을 편집하십시오.

# a2enmod ssl
# a2enmod rewrite
# vi /etc/apache2/apache2.conf

apache2.conf 끝에 다음 행을 추가하십시오.

<Directory /var/www/html>
AllowOverride All
</Directory>

Apache 서비스를 다시 시작하십시오.

# service apache2 restart

Ubuntu Linux에서 Apache 웹 서버 설치를 마쳤습니다.

Apache 가상 호스트 구성

가상 호스트는 하나의 Apache 서버가 동일한 IP 주소를 사용하여 여러 웹 사이트를 제공 할 수있게 해주는 기능입니다.

Apache VirtualHosts 기능을 사용하기 위해 필요한 인프라를 생성 할 수 있습니다.

# mkdir /websites/mining-pool
# cd /websites/mining-pool
# mkdir www logs
# chown www-data.www-data /websites -R

저희 웹 사이트의 이름은 mining-pool.ninja입니다.

mining-pool.ninja 웹 사이트 파일은 / websites / mining-pool / www 디렉토리에 있어야합니다.

mining-pool.ninja 로그는 / websites / mining-pool / logs 디렉토리에 저장됩니다.

Alert!

Mining-pool.ninja was used as an example!

You need to change your configuration files to reflect your website name.

웹 사이트에 Apache Virtualhost 구성 파일을 만듭니다.

# vi /etc/apache2/sites-available/mining-pool.conf

여기에 우리의 구성 파일이 있습니다.

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/mining-pool/www
ServerName mining-pool.ninja

<Directory /websites/mining-pool/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/mining-pool/logs/error.log
CustomLog /websites/mining-pool/logs/access.log combined
LogLevel error
</VirtualHost>

웹 사이트 가상 호스트 구성 파일을 활성화하십시오.

Apache 서비스를 다시 시작하십시오.

# a2ensite mining-pool.conf
# service apache2 restart

Apache VirtualHosts 구성을 마쳤습니다.

DNS 도메인 레지스트리 구성

액세스 GODADDY DNS 도메인을 구입할 수 있습니다.

이 예에서는 MINING-POOL.NINJA라는 도메인을 구입합니다.

어떤 웹 사이트라도 DNS 도메인을 구입할 수 있습니다. GoDaddy는 제 개인적인 선택입니다.

Apache를 실행하는 컴퓨터에 웹 사이트를 가리키는 DNS 항목을 만듭니다.

이 예에서는 도메인 MINING-POOL.NINJA를 IP 주소 35.163.100.49로 가리키는 DNS 항목을 만들었습니다.

Godaddy Apache DNS Configuration

NSLOOKUP 명령을 사용하여 DNS 구성을 테스트하십시오.

# apt-get update
# apt-get install dnsutils
# nslookup mining-pool.ninja

Non-authoritative answer:
Name: mining-pool.ninja
Address: 35.163.100.49

DNS 도메인 구성을 마쳤습니다.

브라우저를 열고 웹 사이트의 HTTP 버전에 액세스하십시오.

이 예에서는 브라우저에 다음 URL이 입력되었습니다.

• http://mining-pool.ninja

Apache Virtualhost HTTP

이제 우리의 유일한 관심사는 무료 HTTPS 인증서를 설치하고 웹 사이트의 HTTPS 버전으로 모든 HTTP 트래픽을 자동으로 리디렉션하는 것입니다.

Apache에서 무료 HTTPS 인증서 구성

Ubuntu Linux에 LET 'S ENCRYPT 무료 SSL / TLS 인증서를 사용하기 위해 필요한 패키지를 설치하십시오

# apt-get install software-properties-common
# add-apt-repository universe
# add-apt-repository ppa:certbot/certbot
# apt-get update
# apt-get install python-certbot-apache

Apache 무료 HTTPS 인증서를 요청하고 설치하십시오.

# certbot --apache -d mining-pool.ninja

• (A)를 눌러 서비스 약관에 동의하십시오.
• (Y)를 눌러 전자 메일을 공유하고 뉴스 레터를 수신하십시오.
• (2)를 눌러 HTTP 웹 사이트를 HTTPS 버전으로 자동 리디렉션합니다.

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): techexpert.tips@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 mining-pool.ninja
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/mining-pool-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/mining-pool-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/mining-pool-le-ssl.conf

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
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/mining-pool.conf to ssl vhost in /etc/apache2/sites-available/mining-pool-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://mining-pool.ninja

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

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/mining-pool.ninja/privkey.pem
Your cert will expire on 2019-03-19. 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"
- 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

시스템에서 자동으로 무료 인증서를 요청합니다.

또한 모든 HTTP 액세스를 웹 사이트의 HTTPS 버전으로 리디렉션하도록 Apache 웹 서버를 구성합니다.

이 예에서 시스템은 mining-pool-le-ssl.conf라는 HTTPS 가상 호스트 구성 파일을 만들었습니다

다음은 HTTPS Virtualhost 구성 파일 mining-pool-le-ssl.conf의 내용입니다.

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error

SSLCertificateFile /etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mining-pool.ninja/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

KEY 파일에는 인증서 개인 키가 포함되어 있으며 항상 안전한 장소에 보관해야합니다.

mining-pool.ninja의 핵심 파일은 /etc/letsencrypt/live/mining-pool.ninja/privkey.pem에 저장되었습니다.

시스템은 원래 Apache Virtualhost 구성 파일을 자동으로 수정합니다.

자동으로 모든 HTTP 요청을 웹 사이트의 HTTPS 버전으로 리디렉션합니다.

다음은 업데이트 된 원본 HTTP 가상 호스트 구성 파일 인 mining-pool.conf의 내용입니다.

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error
RewriteEngine on
RewriteCond %{SERVER_NAME} =mining-pool.ninja
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost>

Apache에서 무료 HTTPS 인증서 테스트

필요한 모든 구성이 완료되었습니다.

이제 구성을 테스트 할 차례입니다.

브라우저를 열고 웹 사이트의 HTTP 버전에 액세스하십시오.

이 예에서는 브라우저에 다음 URL이 입력되었습니다.

• http://mining-pool.ninja

Apache는 자동으로 HTTP 요청을 웹 사이트의 HTTPS 버전으로 리디렉션합니다.

Lets Encrypt Apache HTTPS

Apache HTTPS 무료 인증서 구성을 마쳤습니다.

무료 HTTPS 인증서를 갱신하는 방법

LET 'S ENCRYPT 무료 SSL / TLS 인증서는 90 일 동안 만 유효합니다.

시스템은 만료 된 후 30 일 이내에 모든 인증서를 자동으로 갱신하는 스케줄 된 태스크를 작성합니다.

예약 된 작업 이름은 certbot이며 /etc/cron.d 디렉토리에 있습니다.

다음은 /etc/cron.d/certbot 파일의 내용입니다.

# /etc/cron.d/certbot: crontab entries for the certbot package
#
# Upstream recommends attempting renewal twice a day
#
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
#
# Important Note! This cronjob will NOT be executed if you are
# running systemd as your init system. If you are running systemd,
# the cronjob.timer function takes precedence over this cronjob. For
# more details, see the systemd.timer manpage, or use systemctl show
# certbot.timer.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

인증서 갱신 프로세스를 시뮬레이트하려면 다음 명령을 사용하십시오.

# certbot renew --dry-run

다음 메시지가 표시됩니다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/mining-pool.ninja.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator apache, Installer apache
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for mining-pool.ninja
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- 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.