LoginSignup
3
2

More than 5 years have passed since last update.

Let’s encryptを利用して、https通信を構築する

Last updated at Posted at 2018-07-21

前回、Ubuntu18.04にLaravelの環境を構築しました。今回は、この環境にドメインを設定し、https通信ができるようにしたいと思います。

ドメインの取得

こちらのサイトを参考に無料のドメインを登録しました。
使いやすい以下の2点にしぼりました。

*no-ip
https://www.noip.com/remote-access

*freenom
https://my.freenom.com/clientarea.php

最終的に、freenomを利用し、.mlを取得してドメインを登録しました。

UbuntuにLet’s encryptを利用して、サーバ証明書の取得

ubuntuにLet’s encryptをインストール。

sudo apt-get install letsencrypt

nginxを一旦止めて、証明書を取得する。

sudo systemctl stop nginx
sudo letsencrypt certonly --standalone -d example.ml

ngnixに証明書を設定する

前回の設定にhttpsの設定を追記しました。

server {
        listen 443 default_server;
        listen [::]:443 default_server ipv6only=on;

        server_name sample-test.ml;

        root /var/www/laravel/public;
        index index.php index.html index.htm;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/example.ml/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.ml/privkey.pem;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

設定が終了したので、nginxを起動します。

sudo systemctl start nginx

暫くすると、https://example.mlでアクセスできるはずです。

最後に

AWS上に、これまで、Laravelの開発環境を構築しました。
次は、ローカル環境上にhttpsでの開発環境を構築したいと思います。

参考元
https://qiita.com/k-yamada-github/items/7314003de7bdcbb2d39b

3
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2