前回まででopensslをインストールしたので、今回は自己署名の証明書を作り、nginxのサイトに割当てます。

[root@nginx01 ~]# openssl req -new -x509 -sha256 -newkey rsa:2048 -days 365 -nodes -out /etc/nginx/ssl/nginx.pem -keyout /etc/nginx/ssl/nginx.key
Generating a 2048 bit RSA private key
...+++
......................+++
writing new private key to '/etc/nginx/ssl/nginx.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:


まずは、自己署名の証明書です。
証明書の保管先と、キーの保管先を指定する必要があります。
この保管先を後ほど指定します。

[root@nginx01 ~]# less /etc/nginx/nginx.conf



    server {
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      /etc/nginx/ssl/nginx.pem;
        ssl_certificate_key  /etc/nginx/ssl/nginx.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

        location / {
            root   html;
            index  index.html index.htm;
        }


Nginxの設定です。
SSLの443番ポートで待ち受け、SSLの証明書とキーを指定します。

[root@nginx01 ~]# service nginx restart
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
nginx を停止中:                                            [  OK  ]
nginx を起動中:   
                                         [  OK  ]

設定後、サービスを再起動します。

安全ではない接続

「https://」でアクセスしてみました。
自己署名なので、警告が出力されますが・・・

Welcome to nginx!

しっかりとアクセスすることが出来ました。