博客
关于我
nginx添加模块与https支持
阅读量:799 次
发布时间:2023-02-15

本文共 1394 字,大约阅读时间需要 4 分钟。

实例1:为已安装nginx动态添加模块

以安装rtmp媒流模块为例

1) 下载第三方模块到

[root@LNMP nginx-1.8.1]# git clone https://github.com/arut/nginx-rtmp-module.git

2) 查看nginx编译安装时安装的模块

[root@LNMP nginx-1.8.1]# nginx -V

输出示例:

nginx version: nginx/1.8.1

3) cd到源码目录添加模块重新配置编译

[root@LNMP nginx]# cd /root/tools/nginx-1.8.1[root@LNMP nginx-1.8.1]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_ssl_module --add-module=/root/tools/nginx-1.8.1/nginx-rtmp-module

4) 在编译完成后,会在当前目录下生成一个objs文件夹,将nginx二进制文件拷贝到源安装目录下,注意备份源文件,然后查看编译后的模块。

[root@LNMP nginx-1.8.1]# make

实例2:nginx使用ssl模块配置https支持

1、生成证书(注意此证书为自己颁发的在公网上不受信任)

1) 生成一个rsa密钥

[root@LNMP ssl]# openssl genrsa -des3 -out test.key 1024

2) 拷贝刚才的密码文件,生成一个不需要密码的密钥文件

[root@LNMP ssl]# openssl rsa -in test.key -out test_nopass.key

3) 生成一个证书请求文件

[root@LNMP ssl]# openssl req -new -key test.key -out test.csr

4) 自己签发证书

[root@LNMP ssl]# openssl x509 -req -days 365 -in test.csr -signkey test.key -out test.crt

2、配置nginx.conf文件

[root@LNMP ssl]# vim /usr/local/nginx/conf/nginx.conf

添加如下内容:

server {    listen 80;    server_name localhost;    listen 443;    ssl on;    ssl_certificate /usr/local/nginx/conf/test.crt;    ssl_certificate_key /usr/local/nginx/conf/test_nopass.key;}

3、重加载配置

[root@LNMP ssl]# nginx -s reload

-----------------------------------end-----------------------------------------------------

转载地址:http://owjfk.baihongyu.com/

你可能感兴趣的文章