LoginSignup
62
65

More than 5 years have passed since last update.

nginxでSSLを立てるまで

Posted at

とある事情でSSL通信をさせて内部的にリダイレクトさせないとならなかったのでその手順をまとめる。

サーバ証明書を生成

今回はデバッグ目的のみなのでちゃんとした証明書ではなくとりあえず動くものを生成する。

#opensslのインストール
$ brew install openssl

#続いてopensslから証明書の生成
$ openssl req -new -days 365 -x509 -nodes -keyout cert.key -out cert.crt

nginxの設定

続いてnginxの設定。
設定ファイルは/etc/nginx/conf.d/ssl.confに保存。
(ここは*.confが普通は全部読み込まれるので同じディレクトリならOK)

ssl.conf
#エイリアス?の設定。なんか動かなかったのでコメントアウト。
#upstream server_clusters {
#    server http://localhost:80
#}

server {
    listen       443;

    ssl                  on;
    ssl_certificate      /etc/nginx/cert.crt;
    ssl_certificate_key  /etc/nginx/cert.key;

    ssl_session_timeout  5m;

    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

    location / {
        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-User $remote_user;
        proxy_pass http://localhost:8080;
    }
}

nginxを再起動

nginxを再起動。configのチェックをして問題なければrestart。

#configファイルのテスト
sudo /etc/init.d/nginx configtest

#OKだったらrestart
sudo /etc/init.d/nginx restart
62
65
0

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
62
65