手把手教你编译带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
验证
输入自己服务器地址即可访问: 测试访问地址.
购买腾讯云服务器链接
购买链接: 购买链接.