CentOS6.5 下在Nginx中添加SSL证书以支持HTTPS协议访问

参考文献:

1. NginxV1.8.0安装与配置

2. CentOS下在Nginx中添加SSL证书以支持HTTPS协议访问

3. nginx配置ssl证书的方法

4、nginx强制使用https访问(http跳转到https)

 5、nginx ssl 107 (net::ERR_SSL_PROTOCOL_ERROR) 无法与服务器建立安全连接 解决方法

 

配置过程如下:

我的nginx是 yum 安装 具体安装过程参考:[转]CENTOS 6.5 配置YUM安装NGINX+服务器负载均衡

一、安装相关支持库: (参考  NginxV1.8.0安装与配置
yum -y install gcc gcc-c++ autoconf 
yum -y install openssl openssl-devel

更新到最新的支持库

 

二、编辑配置文件

  # vim /etc/nginx/conf.d/default 或 vim /etc/nginx/conf.d/example_ssl.conf

我的是  vim /etc/nginx/conf.d/example_ssl.conf

配置示例

# HTTPS server
#
server {
    listen       443 ;
    server_name  localhost;
    ssl  on;
    ssl_certificate      /etc/nginx/ssl/xx.com.crt;
    ssl_certificate_key  /etc/nginx/ssl/xx.com.key;

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

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

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}

三、重启Nginx,完成

  sudo service nginx restart

重启过程中一般会询问PEM pass phrase,这是因为RSA私钥文件有密语保护。CA在颁发证书的时候设定了一个密语保护,在知道密语的情况下,可以用OpenSSL去除保护,重启Nginx的时候就不会提示输入密语。

可能碰到的问题:

 

四、nginx强制使用https访问(http跳转到https)

配置

server {  
    listen  80;  
    server_name test.com;  
     ........

    rewrite ^(.*)$  https://$host$1 permanent;  #添加这行强制跳转
......
}

 

posted @ 2015-12-11 18:44  wuling129  阅读(8915)  评论(0编辑  收藏  举报