AL@のTech Blog

個人用備忘録

【Vuls】Linuxサーバの脆弱性を検知してみた part2 (vulsrepoへのアクセスをSSL化)

前回、Vulsサーバの構築を行い、クライアントからパッケージ情報を送信し、ブラウザ上で脆弱性の検知結果を確認しました。
今回は、vulsrepoへのアクセスをSSL化していこうと思います。

残念なことにvulsrepoは現状SSL化の設定がないようなので、nginxでSSL化させてvulsrepoに接続させていきたいと思います。
 

目次

 1. 前提
 2. nginxインストール&confの設定変更
 3. 接続確認


1. 前提

サーバ名:vuls-server
EC2インスタンスタイプ:t2.medium
EBSボリューム:16GB
OS:Amazon Linux 2

2. nginxインストール&confの設定変更

まずはnginxをインストールします。

amazon-linux-extras install nginx1

 
nginxを起動させます。

systemctl status nginx
systemctl start nginx
systemctl status nginx
systemctl enable nginx

  
鍵の作成とディレクトリ等のパーミッションを変更します。

mkdir /etc/nginx/ssl
openssl req -new -x509 -sha256 -newkey rsa:2048 -days 365 -nodes -out /etc/nginx/ssl/nginx.pem -keyout /etc/nginx/ssl/nginx.key

chown nginx:nginx -R /etc/nginx/ssl/
chmod 600 /etc/nginx/ssl/*
chmod 700 /etc/nginx/ssl

 
nginx.confの設定ファイルを追加します。

vim /etc/nginx/nginx.conf
server {
        listen       443 ssl http2;
        listen       [::]:443 ssl http2;
        server_name  _;
        root         /usr/share/nginx/html;
        ssl_certificate /etc/nginx/ssl/nginx.pem;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;
            location / {
            root   html;
            index  index.html index.htm;
            proxy_pass http://localhost:5111/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            }
        }

 
nginxを再起動させます。

systemctl restart nginx
systemctl status nginx

 
 

3. 接続確認

最後にHTTPSでアクセスしてみます。

ちなみにhttps:[パブリックIP]でアクセスできるようになりましたが、このままだとhttp://[パブリックIP]:5111でもアクセスできてしまいます。
なのでセキュリティグループのport:5111は忘れず削除しておきましょう。