为了账号安全,请及时绑定邮箱和手机立即绑定

来吧!教你配置Nginx的HTTPS服务

一、HTTPS服务的作用

HTTPS在传输数据之前需要客户端(浏览器)与服务端(网站)之间进行一次握手,在握手过程中将确立双方加密传输数据的密码信息。对传输信息加密以保证数据的安全性。

二、HTTPS搭建种类

1、全站单向SSL加密

最常见的模式,只对客户端验证服务端可信。

2、部分页面单向ssl

也是单向的,不过只是配置部分url通过https,比如:网站的用户登录、支付等等接口。

3、全站双向SSL加密

利用场景很少见,如银行验证用户的u盾key,上面的两种配置都是去认证被访问的站点域名是否真实可信,并对传输过程加密,但服务器端并没有认证客户端是否可信。

三、NGINX实现HTTPS得系统需求

1、系统所需安装包

openssl openssl-devel

yum install openssl openssl-devel -y

2、nginx编译SSL模块

--with-http_ssl_module

./configure --prefix=/opt/app/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/download/pcre-8.38 --with-http_ssl_module

三、全站单向SSL加密

关于SSL/TLS原理请参考 这里,如果你只是想测试或者自签发ssl证书,参考 这里

1、生成一个RSA密钥

# openssl genrsa -des3 -out imoocc.key 1024  //prase为imoocc (记住)

2、通过上面生成的rsa生成一个不需要密码的秘要

# openssl rsa -in imoocc.key -out imoocc_nopass.key

//这样可以用于nginx reload 免密码
3、生成一个证书请求

# openssl req -new -key imoocc.key -out imoocc.csr

Enter pass phrase for imoocc.key:

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [XX]:BJ

State or Province Name (full name) []:BJ

Locality Name (eg, city) [Default City]:BJ

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

Organizational Unit Name (eg, section) []:

Common Name (eg, your name or your server's hostname) []:

Email Address []:

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []: //不需要输入password

An optional company name []:

//这步骤会提示输入国家、公司、email等信息,大家参考实际情况添加即可。

4、生成一个有效期为10年的自己签发证书

# openssl x509 -req -days 3650 -in imoocc.csr -signkey imoocc.key -out imoocc.crt

5、nginx.conf配置

server

 {

   listen       443;

   server_name  www.imoocc.com;

   ssi on;

   ssl on;

   ssl_certificate /opt/app/nginx/ssl/imoocc.crt;

   #ssl_certificate_key /opt/app/nginx/ssl/imoocc.key;

   ssl_certificate_key /opt/app/nginx/ssl/imoocc_nopass.key;

   index index.html index.jsp;

   location / {

       proxy_pass http://imoocc_7070_tomcat;

       include proxy_params;

   }

   access_log  /opt/logs/nginx/access/myeidser_cn_https.log Jmain;

 }

5、重启nginx

/opt/app/nginx/sbin/nginx -s reload -c /opt/app/nginx/conf/nginx.conf

点击查看更多内容
22人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消