制作私有ssl证书

1.编译安装nginx

安装前准备:

service iptables stop

setenforce 0

yum -y install pcre-devel zlib-devel

useradd -M -s /sbin/nologin nginx

上传nginx源码包后

tar xf nginx-1.6.2.tar.gz -C /usr/src/

cd /usr/src/nginx-1.6.2/

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module && make && make install   //编译时加入--with-http_ssl_module参数

设置软链接

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

2.生成证书

进入创建证书和私钥的目录

cd /usr/local/nginx/conf/

创建服务器私钥,回车后会让你输入一个口令:

openssl genrsa -des3 -out server.key 1024

创建签名请求的证书(CSR):

openssl req -new -key server.key -out server.csr

回车后出现以下选项:(除了填写域名,其他都可以直接回车跳过)

Country Name (2 letter code) [XX]:    ///国家

State or Province Name (full name) []:   ///省份

Locality Name (eg, city) [Default City]:   ///城市

Organization Name (eg, company) [Default Company Ltd]:   ///部门

Organizational Unit Name (eg, section) []:    ///组织或公司名称

Common Name (eg, your name or your server's hostname) []:www.benet.com    ///域名

Email Address []:   ///邮箱

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:

openssl rsa -in server.key -out server_nopwd.key

最后标记证书使用上述私钥和CSR:

openssl x509 -req -days 3650 -in server.csr -signkey server_nopwd.key -out server.crt

至此证书生成完毕

 

3.配置nging配置文件

vim nginx.conf

修改server段加入以下内容:

server {

        listen       443;

        server_name  localhost;

        ssl on;

        ssl_certificate  /usr/local/nginx/conf/server.crt;

        ssl_certificate_key  /usr/local/nginx/conf/server_nopwd.key;

 

        charset utf-8;

 

        location / {

            root   html;

            index  index.html index.htm;

        }

}

检查nginx.conf语法是否有错误

nginx –t

启动nginx

nginx

如果已经启动,就使用killall nginx 命令先杀死nginx进程,然后再重新启动

4.在客户机上导入证书

首先把生成的证书传到客户机上

sz server.crt 192.168.1.104

在客户机上操作:

控制面板 -> Internet选项 -> 内容 -> 发行者 -> 受信任的根证书颁发机构 -> 导入 -》选择server.crt

然后在浏览器上输入https://www.benet.com能够正常访问

posted @ 2019-05-22 15:27  大川哥  阅读(2241)  评论(0编辑  收藏  举报