フロントエンドアプリケーションHTTPS(feat.certbot,nginx)の導入


Environment

  • GCP, Intel Broadwell
  • debian-10-buster-v20220310
  • デフォルトではroot権限(sudo su)が使用されます.

    1.nginx&certbotのインストール

  • apt-get update
  • apt-get install nginx
  • apt-get install software-properties-common
  • add-apt-repository ppa:certbot/certbot
  • apt-get update
  • 2.Pythonのインストール


    この段階では、Pythonがインストールされている可能性があります.
  • python --version
  • Pythonがインストールされていない場合は、インストールしてください.
  • apt-get install python
  • バージョンの検証後、Python 2がインストールされている場合は上のコマンドを使用し、3がインストールされている場合は下のコマンドを使用します.
  • apt-get install python-certbot-nginx
  • apt-get install python-certbot3-nginx
  • 3.構築反応


    gitをインストールし、コードを取得します.もうあるならスキップして
  • apt-get install git
  • git config --global user.name i4song
  • git config --global user.email [email protected]
  • git clone https://github.com/i4song/i4song-blog.git
  • node.jsをインストールします.もうあるならスキップして
  • apt-get install -y build-essential
  • apt-get install curl
  • curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash --
  • apt-get install -y node.js
  • npmをインストールします.もうあるならスキップして
  • apt-get install npm
  • 糸を取り付ける.(npmで作成したプロジェクトの場合はスキップします.)
  • npm install -g yarn
  • プロジェクトが存在するフォルダに移動して構築します.
  • cd i4song-blog
  • yarn or npm install
  • yarn run build or npm run build
  • 4.nginx(for react)の設定


    ドメイン名を使用してconfigファイルを作成し、シンボルリンクを作成します.
  • vi /etc/nginx/sites-available/i4song.com
    server {
    	server_name i4song.com;
        
        location / {
          root /home/i4song/i4song-blog/build/; //리액트 프로젝트의 build 폴더 위치
          index index.html;
          try_files $uri $uri/ /index.html;
        }
    }
  • sudo ln -s /etc/nginx/sites-available/i4song.com /etc/nginx/sites-enabled/i4song.com
  • 4.certbotを使用して証明書を発行する

  • certbot --nginx -d i4song.com
  • 1と入力した場合、http接続はhttpにリダイレクトされません.
  • 2と入力した場合、https接続はhttpsにリダイレクトされます.
  • 5.証明書自動更新の設定(crontab)


    設定:証明書を毎月更新します.
  • crontab -e
  • 1 1 1 * * certbot renew --renew-hook "sudo service nginx restart"