nginx使用openssl安装数字证书

 

http://blog.sina.com.cn/s/blog_6ad624380101ido7.html

 

nginx下载 http://www.nginx.org/en/download.html 

openssl下载: http://www.openssl.org/source/   版本:1.0.1f

 

1.注意:OPENSSL不需要安装,只需要解压出来就行。不然在编译时会提示类似以下的错误:

make[1]: Entering directory `/root/nginx'
cd /server/openssl \
        && make clean \
        && ./config --prefix=/server/openssl/openssl no-shared  no-threads \
        && make \
        && make install
make[2]: Entering directory `/server/openssl'
make[2]: *** No rule to make target `clean'.  Stop.
make[2]: Leaving directory `/server/openssl'
make[1]: *** [/server/openssl/openssl/include/openssl/ssl.h] Error 2
make[1]: Leaving directory `/root/nginx'
make: *** [build] Error 2

 

2.安装Nginx的时候,把openssl路径指定到解压出来的路径:

./configure  --with-http_stub_status_module --with-http_ssl_module --with-openssl=/root/openssl --with-http_gzip_static_module  --with-http_stub_status_module

扫描二维码关注公众号,回复: 305185 查看本文章

之后是一个漫长的等待时间

 

3、生成RSA密钥的方法

openssl genrsa -des3 -out privkey.pem 2048
这个命令会生成一个2048位的密钥,同时有一个des3方法加密的密码,如果你不想要每次都输入密码,可以改成:
openssl genrsa -out privkey.pem 2048
建议用2048位密钥,少于此可能会不安全或很快将不安全。

 

4、生成一个证书请求
openssl req -new -key privkey.pem -out cert.csr
这个命令将会生成一个证书请求,当然,用到了前面生成的密钥privkey.pem文件
这里将生成一个新的文件cert.csr,即一个证书请求文件,你可以拿着这个文件去数字证书颁发机构(即CA)申请一个数字证书。CA会给你一个新的文件cacert.pem,那才是你的数字证书。

如果是自己做测试,那么证书的申请机构和颁发机构都是自己。就可以用下面这个命令来生成证书:
openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
这个命令将用上面生成的密钥privkey.pem生成一个数字证书cacert.pem

 

5.Nginx配置中,需要修改的地方:

server {

listen       443;

server_name  localhost;

ssl                  on;

ssl_certificate /usr/local/nginx/conf/cacert.pem;

ssl_certificate_key /usr/local/nginx/conf/privkey.pem;

server_name 192.168.10.70

ssl_session_timeout  5m;

}

 

6.在iptables中打开ssl使用到的443端口,重启iptables.

 

7.测试。访问时,发现有提示需要证书,应该成功了。

猜你喜欢

转载自hunan.iteye.com/blog/2344995