centos使用nginx搭建https服务器
来源:互联网 发布:sql select as语句 编辑:程序博客网 时间:2024/06/06 00:41
最近在研究nginx,整好遇到一个需求就是希望服务器与客户端之间传输内容是加密的,防止中间监听泄露信息,但是去证书服务商那边申请证书又不合算,因为访问服务器的都是内部人士,所以自己给自己颁发证书,忽略掉浏览器的不信任警报即可。下面是颁发证书和配置过程。
首先确保机器上安装了openssl和openssl-devel
#yum install openssl#yum install openssl-devel
然后就是自己颁发证书给自己
#cd /usr/local/nginx/conf#openssl genrsa -des3 -out server.key 1024#openssl req -new -key server.key -out server.csr#openssl rsa -in server.key -out server_nopwd.key#openssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt
至此证书已经生成完毕,下面就是配置nginx
server { listen 443; ssl on; ssl_certificate /usr/local/nginx/conf/server.crt; ssl_certificate_key /usr/local/nginx/conf/server_nopwd.key;}
然后重启nginx即可。
ps: 如果出现“[emerg] 10464#0: unknown directive "ssl" in /usr/local/nginx-0.6.32/conf/nginx.conf:74”则说明没有将ssl模块编译进nginx,在configure的时候加上“--with-http_ssl_module”即可^^
至此已经完成了https服务器搭建,但如何让浏览器信任自己颁发的证书呢?
今天终于研究捣鼓出来了,只要将之前生成的server.crt文件导入到系统的证书管理器就行了,具体方法:
控制面板 -> Internet选项 -> 内容 -> 发行者 -> 受信任的根证书颁发机构 -> 导入 -》选择server.crt
====开始Nginx的SSL模块====================
原因也很简单,nginx缺少http_ssl_module模块,编译安装的时候带上--with-http_ssl_module配置就行了,但是现在的情况是我的nginx已经安装过了,怎么添加模块,其实也很简单,往下看: 做个说明:我的nginx的安装目录是/usr/local/nginx这个目录,我的源码包在/usr/local/src/nginx-1.6.2目录
切换到源码包:
cd /usr/local/src/nginx-1.11.3
查看nginx原有的模块
/usr/local/nginx/sbin/nginx -V
在configure arguments:后面显示的原有的configure参数如下:
--prefix=/usr/local/nginx --with-http_stub_status_module
那么我们的新配置信息就应该这样写:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_modul
运行上面的命令即可,等配置完
配置完成后,运行命令
make
这里不要进行make install,否则就是覆盖安装
然后备份原有已安装好的nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止状态)
cp ./objs/nginx /usr/local/nginx/sbin/
然后启动nginx,仍可以通过命令查看是否已经加入成功
/usr/local/nginx/sbin/nginx -V
Nginx 配置Http和Https共存
把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用server {listen 80
default
backlog=2048;
listen 443 ssl; ssl_certificate /usr/local/nginx/conf/server.crt; ssl_certificate_key /usr/local/nginx/conf/server_nopwd.key;}
Nginx SSL性能调优
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers
on
;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
- centos下使用nginx搭建https服务器
- centos下使用nginx搭建https服务器
- centos使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用 Nginx 搭建 HTTPS 服务器
- 【Nginx】使用nginx搭建https服务器
- Centos Nginx搭建https
- Nginx搭建HTTPS服务器
- nginx搭建https服务器
- Nginx 搭建 HTTPS 服务器
- nginx搭建https服务器
- (SCU
- requestAnimationFrame--用法及轮播动画
- NYOJ-0002-括号匹配
- CodeForces
- [POJ
- centos使用nginx搭建https服务器
- 文件编程----------write和复制操作
- 剑指offer——12.数值的整数次方
- redis集群环境搭建
- 招聘销售经理
- java后台常用正则表达式
- CentOS 下安装和使用 Docker
- ios-多线程基础
- Android如何获取fragment里的webview控件资源