手把手教你编译带ssl(https) 模块的nginx服务-基于新购腾讯云服务器CentOS 7.6 64位

手把手教你编译带ssl(https) 模块的nginx服务

安装gcc-c++编译软件包

新购买的腾讯云服务器未安装c++编译软件包,通过执行如下命令安装。
yum install gcc-c++

下载最新版本软件包(2019年11月16日版本)

配置带ssl模块的nginx服务需要下载pcre、zlib、openssl、nginx四个软件包,我们将下载的四个软件包存储在/usr/local/src目录,执行如下命令即可:
cd /usr/local/src/
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.zip
wget http://www.zlib.net/zlib-1.2.11.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
wget http://nginx.org/download/nginx-1.16.1.tar.gz

编译pcre

unzip pcre-8.43.zip
pcre-8.43/
./configure --prefix=/usr/local/pcre-8.43
make
make install

编译zlib

tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure --prefix=/usr/local/zlib-1.2.11
make
make install

编译openssl

tar -zxvf openssl-1.1.1d.tar.gz
cd openssl-1.1.1d/
./config --prefix=/usr/local/openssl-1.1.1d --shared -fPIC
make depend
make
make install

编译nginx

tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1/
./configure --prefix=/usr/local/nginxssl --with-http_ssl_module --with-http_stub_status_module --with-pcre=…/pcre-8.43 --with-openssl=…/openssl-1.1.1d --with-zlib=…/zlib-1.2.11 --with-http_flv_module --with-http_mp4_module --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_realip_module

说明:
1、–prefix指定nginx服务安装路径;
2、–with-http_ssl_module指定编译ssl模块,–with-openssl指定openssl源码路径;
3、–with-pcre指定pcre源码路径;
4、–with-zlib指定zlib源码路径;
5、–with-stream=dynamic指定stream模块根据配置动态加载。

配置

编辑conf/nginx.cong将如下配置开启
server {
listen 443 ssl;
server_name localhost;
#证书文件
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}

启动

进入sbin目录执行如下命令启动nginx服务:
./nginx

验证

输入自己服务器地址即可访问: 测试访问地址.

购买腾讯云服务器链接

购买链接: 购买链接.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天马行空8

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值