Closed sugizakikun closed 1 month ago
ということで以下の記事を参考にEC2の分身を作る (勉強も兼ねて)
作成手順
44.195.xxx.xxx
と紐づいているEC2サーバーAのAMIを作成35.153.xxx.xxx
)を紐付ける35.153.xxx.xxx
)を貼り付けるnslookup sakopi.site
で検証用に作成したEC2のElastic IP(35.153.xxx.xxx
)にドメインが紐づいていることを確認するCertbotをEC2サーバー(Amazon Linux 2)にインストールする方法
urllib3
のバージョンをダウングレードして、OpenSSL 1.0.2k と互換性があるバージョンに戻す。
sudo pip3 install 'urllib3<2'
certbotをインストール
sudo pip3 install certbot
certbot の動作確認
[ec2-user@ip-10-0-1-41 ~]$ certbot --version
certbot 2.7.4
certbot certonly \
--webroot \
-w /srv/certbot \
-d sakopi.site \
-m [ワイのメールアドレス] \
--agree-tos
を打つと[Errno 13] Permission denied: '/var/log/letsencrypt/letsencrypt.log' Either run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths
と怒られまくるので、sudoをつけてcertbotへのパスを明記した上で再度実行してみる
ちなみにcertbotへのパスの調べ方はこれ↓
which certbot
大成功👏👏👏👏
[ec2-user@ip-10-0-1-41 ~]$ sudo /usr/local/bin/certbot certonly \
> --webroot \
> -w /srv/certbot \
> -d sakopi.site\
> -m sugizakikun@gmail.com \
> --agree-tos
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Python 3.7 support will be dropped in the next planned release of Certbot - please upgrade your Python version.
Requesting a certificate for sakopi.site
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/sakopi.site/fullchain.pem
Key is saved at: /etc/letsencrypt/live/sakopi.site/privkey.pem
This certificate expires on 2024-11-22.
These files will be updated when the certificate renews.
NEXT STEPS:
- The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/etc/nginx/conf.d/docker-laravel.conf
にlisten 443の設定を追記
server {
listen 80;
server_name sakopi.site;
root /var/www/docker-laravel/src/public; # `public` ディレクトリをルートに設定
index index.php index.html;
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
client_max_body_size 15m;
location ^~ /.well-known/acme-challenge/ {
root /srv/certbot;
default_type "text/plain";
}
location / {
try_files $uri $uri/ /index.php?$query_string; # `index.php` にフォールバック
}
location ~ \.php$ {
try_files $uri =404; # `index.php` をここでフォールバックするのではなく、リク>エストされた PHP ファイルのみ処理
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 180;
}
}
以下を/etc/nginx/conf.d/docker-laravel.conf
に追記する
server {
listen 443 ssl;
server_name sakopi.site;
ssl_certificate /etc/letsencrypt/live/sakopi.site/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sakopi.site/privkey.pem;
root /var/www/docker-laravel/src/public;
index index.php index.html;
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
client_max_body_size 15m;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 180;
}
}
以下のコマンドで変更を反映する
sudo systemctl restart nginx
おし!いけたべさ!!!!
以上の手順で同様に44.195.xxx.xxxにも適用をしてみる (非効率と思われそうだけど何回もやった方が定着する)
目的
https://~
で始まることを義務付けられているから参考にする記事
手順