CentOS 6.5下 Nginx 配置 https 服务

赞赏 2016-07-26

本文介绍在云服务器 ECS CentOS 6.5 服务器上安装配置 nginx 的 https 服务。 https 需要安装 openssl 软件。


本文的实验环境:

 

1. 在配置 nginx 时,可能会依赖于 PCRE 包和 zlib 包,先进行安装:

  1. # yum -y install pcre pcre-devel
  2. # yum install -y zlib-devel

 2. 下载 nginx

  1. # wget http://nginx.org/download/nginx-1.6.2.tar.gz

3. 解压缩

  1. # tar -xvzf nginx-1.6.2.tar.gz

 4. 配置nginx

  1. # ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-openssl=/usr/local/openssl-0.9.8zg

1.JPG

注意: 这里 /usr/local/openssl-0.9.8zg 指的的是 openssl 的源码包,不是编译安装好的 openssl, 否则在执行 make 时会出错。

  1. # make
  2. # make install

 5. 使用 openssl 生成证书

  1. # openssl req -new -x509 -nodes -out server.crt -keyout server.key


生成证书时,请根据自己的需要填写信息:

2.JPG

 

6. 修改 nginx 配置文件:

  1. # vi /usr/local/nginx/conf/nginx.conf

添加如下内容:
  

  1. server {
  2.        listen       443 ssl;
  3.        server_name  localhost;
  4.        ssl_certificate      server.crt;
  5.        ssl_certificate_key  server.key;
  6.        ssl_session_cache    shared:SSL:1m;
  7.        ssl_session_timeout  5m;
  8.        ssl_ciphers  HIGH:!aNULL:!MD5;
  9.        ssl_prefer_server_ciphers  on;
  10.        location / {
  11.            root   html;
  12.            index  index.html index.htm;
  13.        }
  14.    }

 
 4.JPG

 

7. 启动 nginx:

  1. # /usr/local/nginx/sbin/nginx

 8. http方式访问测试示意:
 

6.JPG

9. https 方式访问示意:

 7.JPG

至此nginx配置https就完成了。 

登陆后阅读全文
阅读 1907 赞赏 0 有用 0 没用 0 收藏 0 分享

   



0 条留言

linux分享的头像

linux分享

每个软件都有确定的用途

相关文章

别的域名也能访问我的网站是怎么回事?|Linux下nginx如何禁止空主机头?| 网站IP被恶意解析

Nginx启动报错:Error open() nginx.pid?

阿里云·业务运营团队内部的前端构建和工程化工具 Dawn开源

nginx 报错: emerg bind to 80 failed 98 address already in use

nginx warn upstream response is buffered to a temporary file

如何配置,让Apache、Nginx 支持跨域访问?

Nginx 502 bad gateway如何解决

nginx .htaccess配置rewrite伪静态示例

Nginx 配置文件中 root 与 alias 指令的区别

Nginx 绑定多个域名的方法

有料推荐

这世界欠我一个这样的老公!

高校学生模仿“世界名画”摆拍,可以说是戏精本精了

iPhone X 跌破发行价,苏宁200亿入股恒大 | 财经日日评

果然是高手!这次在日本,特朗普竹杠敲得不是一般狠

资深黄牛现身说法:iPhone X价格秒变不停,就像炒股一样

长一样的双胞胎也能识别?蚂蚁金服发布「眼纹识别」技术

苏联是怎么被阿富汗拖垮的?

美团或入局「分时租赁」共享汽车,王兴要大笔投入「泛出行」领域了? | 36氪独家

你或许被“一盘番茄炒蛋”刷屏了,但有人辛酸,有人质疑

iPhone X发售前夜,黄牛与苹果公司的不安

他的文章

我是如何执行 "rm -rf ~" 的

正态分布为什么常见?(财富的分布却不符合正态分布)

Linux下窗口管理器 xmonad 的使用教程

用披萨做比喻来解释 IaaS,PaaS,SaaS 的区别

如何制作CSR(证书私钥和证书请求文件)文件?

php RedisException with message read error on connection

Windows环境下ping丢包或不通时链路测试工具推荐

Linux下ping丢包或不通时链路测试工具推荐

链路测试结果分析说明及常见链路异常场景和测试报告

SSH 登录时出现如下错误:login: Module is unknown

手机扫一扫
分享文章