Chinaunix首页 | 论坛 | 博客
  • 博客访问: 111707
  • 博文数量: 28
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 277
  • 用 户 组: 普通用户
  • 注册时间: 2014-10-20 16:21
文章分类
文章存档

2019年(1)

2018年(2)

2017年(22)

2016年(3)

我的朋友

分类: 系统运维

2017-06-20 10:55:10

一、步骤


    a)、安装openssl,生成ssl证书
    b)、nginx添加with-http_ssl_module模块
    c)、配置nginx支持https访问fastdfs


二、安装openssl,生成ssl证书


1、安装openssl

    运行命令:
    1、$ yum install openssl openssl-devel -y
    2、$ openssl version


    注:若出现错误:openssl: errorwhileloading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
    说明库位置不对。

    解决办法:
    在root下运行命令:
    1、$ ln-s/usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
    2、$ ln-s/usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
   
    openssl安装完成。

2、生成ssl证书

    可以通过以下办法生成一个简单的证书:

  a)首先,进入你想创建证书和私钥的目录,例如:

    $ cd /usr/local/nginx/conf/ssl

  b)创建服务器私钥,命令会让你输入一个口令

    $ openssl genrsa -des3 -out server.key 1024

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

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

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

    $ cp server.key server.key.org
    $ openssl rsa -in server.key.org -out server.key

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

    $ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt


三、nginx添加with-http_ssl_module模块运行命令


  1、添加ssl模块

   [root@fuhai-server sbin]#./nginx-V
   nginx version:nginx/1.9.9
   built by gcc 4.4.7 20120313(Red Hat 4.4.7-17)(GCC)
   built with OpenSSL 1.0.1t 3 May 2016
   TLS SNI support enabled
   configure arguments: --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src --with-pcre=/usr/local/pcre-8.39 --with-zlib=/usr/local/zlib-1.2.8 --with-openssl=/usr/local/openssl-1.0.1t --with-http_ssl_module
   如果没有--with-http_ssl_module,则需要重新编译添加ssl模块


 2、重新编译
   
    [root@fuhai-server nginx-1.9.9]#./configure--prefix=/usr/local/nginx--add-module=/usr/local/fastdfs-nginx-module/src--with-pcre=/usr/local/pcre-8.39--with-zlib=/usr/local/zlib-1.2.8--with-openssl=/usr/local/openssl-1.0.1t--with-http_ssl_module

  3、编译完之后make,不要makeinstall。会在当前的objs目录生成nginx可执行文件,备份nginx安装目录的执行文件,将"objs/nginx”文件拷贝到nginx的sbin目录,重载nginx。
       
    [root@fuhai-server sbin]#cp nginx nginx_bak
    [root@fuhai-server nginx-1.9.9]#cp objs/nginx/usr/local/nginx/sbin/

四、配置nginx支持https访问fastdfs


1、修改Nginx配置文件,让其包含新标记的证书和私钥:

    server {
        server_name YOUR_DOMAINNAME_HERE;
        listen 443;
        ssl on;
        ssl_certificate /usr/local/nginx/conf/server.crt;
        ssl_certificate_key /usr/local/nginx/conf/server.key;
    }

2、重载nginx


阅读(2792) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~