m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

nginxでベーシック認証

ちょっとしたセキュリティチェックを設定したい場合

外部のサーバに公開するけど基本参照されたくないから自分のみ用みたいな場合対策

手順

htpasswdを使用してファイルを作成
[root@localhost redmine]# cd /etc/nginx
[root@localhost nginx]# htpasswd -c htpasswd ユーザーID
New password:
Re-type new password:
Adding password for user ユーザーID
[root@localhost nginx]#

※nginxでもあると思われる

confファイルを編集して認証を追加
    location / {
        auth_basic "Restricted";
        auth_basic_user_file htpasswd;
        proxy_pass http://127.0.0.1:3000;
    }
リロードして確認して完了
[root@localhost nginx]# service nginx reload
[root@localhost nginx]#