当前位置:网站首页 / Linux / 正文

申请SSL证书并配置LNMP使用https访问网站

时间:2016年08月07日 | 作者 : liuhui | 分类 : Linux | 浏览: 6880次 | 评论 1

阿里云限量代金券 | 此广告位出租25元/月

越来越多的网站开始用https了,使用https加密技术可以提高站点的安全性,下面是我配置自己的https的过程记录:

申请SSL证书

1、注册账号免费申请SSL:https://login.wosign.com/reg.html

2、登录后打开免费SSL证书申请页面:https://buy.wosign.com/QuickToApplyFreeSSL.html

1.jpg

2.jpg

3.jpg

点击下载

4.jpg

下载证书并解压nginx版本的证书(解压密码就是刚才输入的证书保护密码)

5.jpg

6.jpg

拿到证书后将其上传到nginx的ssl目录(也可以自定义目录)

确认nginx安装时已编译http_ssl模块,也就是执行如下命令查看是否存在--with-http_ssl_module参数:

linux-test:~ # /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.6.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/src/openssl-1.0.1/

如果没有这个参数,说明没有编译SSL模块,那么请参照其他文章自行解决,此处就不再赘述了。


修改配置

 server{

      listen 80;

       #listen [::]:80;

      server_name diannaobos.com www.diannaobos.com;

      index index.html index.htm index.php default.html default.htm default.php;

      root  /home/wwwroot/diannaobos.com;

      location / {

          rewrite (.*) https://www.diannaobos.com$1 permanent;

      }

   }


server

    {

        listen 443; 

        server_name diannaobos.com www.diannaobos.com;

        ssl on;

        ssl_certificate /usr/local/nginx/ssl/diannaobos.crt; #证书公钥文件路径

         ssl_certificate_key  /usr/local/nginx/ssl/diannaobos.key;   #证书私钥文件路径

         ssl_session_timeout  5m;

         ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;

         ssl_ciphers  HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM;

        index index.html index.htm index.php default.html default.htm default.php;

        root  /home/wwwroot/diannaobos.com;


        include zb.conf;

        #error_page   404   /404.html;

        include enable-php.conf;


        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

        {

            expires      30d;

        }


        location ~ .*\.(js|css)?$

        {

            expires      12h;

        }


        location ~ /\.

        {

            deny all;

        }


        access_log  /home/wwwlogs/diannaobos.com.log;

    }


保存配置后先执行如下命令,测试配置是否正确

/usr/local/nginx/sbin/nginx -t

如果正确无误会显示如下

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

确认无误后重载nginx,让配置生效

lnmp reload

如果没有错误,刷新一下页面就能看到https绿色的小锁了!


本文参考链接:http://zhangge.net/4890.html

                        http://zhangge.net/4861.html


推荐您阅读更多有关于“”的文章

猜你喜欢

网站分类
关注电脑博士
友情链接

分享:

支付宝

微信