Nginxでオレオレ証明書
秘密鍵の作成
# openssl genrsa -out server.key -aes128 1024 Generating RSA private key, 1024 bit long modulus ..............++++++ ...........................................................................++++++ e is 65537 (0x10001) Enter pass phrase for server.key: Verifying - Enter pass phrase for server.key:
証明書署名要求ファイルの作成
# openssl req -new -key server.key -out my_domain.csr Enter pass phrase for server.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]:Tokyo Locality Name (eg, city) :Shibuya Organization Name (eg, company) [Internet Widgits Pty Ltd]:my_domain Organizational Unit Name (eg, section) : Common Name (e.g. server FQDN or YOUR name) :my_domain Email Address :info@my_domain Please enter the following 'extra' attributes to be sent with your certificate request A challenge password : An optional company name :
証明書署名要求ファイルからサーバ証明書を作成
# openssl x509 -req -in my_domain.csr -signkey server.key -out my_domain.crt Signature ok subject=/C=JP/ST=Tokyo/L=Shibuya-ku/O=my_domain/CN=my_domain Getting Private key Enter pass phrase for server.key:
パスフレーズの入力回避
# cp -ip server.key server.key.bak # openssl rsa -in server.key.bak -out server.key Enter pass phrase for server.key.bak: writing RSA key
Nginx設定
server { listen 443 ssl; server_name my_domain; access_log /var/log/ssl.access.log main; ssl_certificate /etc/nginx/my_domain.crt; ssl_certificate_key /etc/nginx/server.key; ・・・
Nginx再起動、パスフレーズを求められなければよい。
# /etc/init.d/nginx restart
権限はrootのみにする。
# chmod 600 server.key