Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1354176
  • 博文数量: 145
  • 博客积分: 1440
  • 博客等级: 少尉
  • 技术积分: 2986
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-24 23:47
个人简介

我一直在走,至少还有条路,也好于无路可走…

文章分类

全部博文(145)

文章存档

2023年(1)

2017年(2)

2016年(5)

2015年(13)

2014年(13)

2013年(70)

2012年(41)

分类: LINUX

2014-06-10 07:54:41

                 Nginx  SSL 证书使用

生成SSL证书文件:

 openssl genrsa -des3 -out nginx.key 2048 
 openssl req -new -key nginx.key -out nginx.csr 
 cp nginx.key nginx.key.org 
 openssl rsa -in nginx.key.org -out nginx.key 
 openssl x509 -req -days 365 -in nginx.csr -signkey nginx.key -out nginx.crt 

生成的文件拷贝到/usr/local/nginx/conf 里面

2.SSL 证书配置

上传完配置文件后,如果发现出现类似提示,请检查一下是否有编译SSL选项 
# /usr/local/nginx/sbin/nginx -t 
nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf:110
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed 
 # /usr/local/nginx/sbin/nginx -V  看下是否有  --with-http_ssl_module --with-openssl

没有代表没有这个模板,需要添加

3.如果你有多个不同域名的证书,则需要重新编译openssl,以获得TLS SNI支持 
 
# wget    
# tar zxvf ./openssl-0.9.8l.tar.gz 
# cd ./openssl-0.9.8l 
# ./config enable-tl***t 
# make && make install  

4.重新编译Nginx

5. ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx  --with-http_stub_status_module --with-http_gzip_static_module  --with-http_realip_module --with-http_sub_module   --with-pcre=/lnmp-2.4/Packages/pcre-8.33  --with-http_ssl_module --with-openssl=/openssl-0.9.8l/

6.
Nginx 配置文件添加一个server

7. server {

8.          listen 443;

9.          server_name localhost;

10.          ssl on;

11.          ssl_certificate server.crt;

12.          ssl_certificate_key server.key;

13.          ssl_session_timeout 5m;

14.          ssl_protocols SSLv2 SSLv3 TLSv1;

15.          ssl_ciphers HIGH:!aNULL:!MD5;

16.          ssl_prefer_server_ciphers on;

17.         location / {

18.           root html;

19.            index index.html index.htm;

20.             }

防火墙开启443端口:

 iptables -A INPUT -i eth0 -p tcp --dport  443 -m state --state NEW,ESTABLISHED -j ACCEPT

 iptables -A OUTPUT -o eth0 -p tcp --sport  443  -m state --state ESTABLISHED -j ACCEPT

重启nginx 在浏览器中输入https://域名

由于我们是自签发的证书,浏览器不信任,CA中心没有此证书,测试而已,如果需要ssl证书需要购买的,我们点击几下浏览此网站,就能打开我们的首页了



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