nginx添加模块与https支持
admin
2023-03-16 16:41:04
0

实例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
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_ssl_module

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
[root@LNMP nginx-1.8.1]# make

#此处只进行编译不进行安装,如安装的话会覆盖源文件。

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

[root@LNMP nginx-1.8.1]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.20170825
[root@LNMP nginx-1.8.1]# cp objs/nginx /usr/local/nginx/sbin/nginx
[root@LNMP nginx-1.8.1]# nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --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
[root@LNMP nginx-1.8.1]# nginx -s reload


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

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

1)生成一个rsa密钥:

[root@LNMP ssl]# openssl genrsa -des3 -out test.key 1024
Generating RSA private key, 1024 bit long modulus
..............................++++++
...........................++++++
e is 65537 (0x10001)
Enter pass phrase for test.key:   #输入密码,需要复杂性要求
Verifying - Enter pass phrase for test.key:  #重复密码

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

[root@LNMP ssl]# openssl rsa -in test.key -out test_nopass.key
Enter pass phrase for test.key:  #输入以上创建时输入的密码
writing RSA key

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

[root@LNMP ssl]# openssl req -new -key test.key -out test.csr
Enter pass phrase for test.key:  #输入以上创建时输入的密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:cn  #国家
State or Province Name (full name) []:shanghai  #省份
Locality Name (eg, city) [Default City]:shanghai #城市
Organization Name (eg, company) [Default Company Ltd]:shanghai information company Ltd   #具体名称
Organizational Unit Name (eg, section) []:test  #单位名称
Common Name (eg, your name or your server''s hostname) []:*.test.cn   #服务器域名
Email Address []:admin@test.cn  #邮箱
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:   #密码为空,直接回车
An optional company name []: #密码为空,直接回车

4)自己签发证书

[root@LNMP ssl]# openssl x509 -req -days 365 -in test.csr -signkey test.key -out test.crt
Signature ok
subject=/C=cn/ST=shanghai/L=shanghai/O=shanghai information company Ltd/OU=test/CN=*.test.cn/emailAddress=admin@test.cn
Getting Private key
Enter pass phrase for test.key:  #输入test.key设置的密码


2、配置nginx.conf文件

[root@LNMP ssl]# vim /usr/local/nginx/conf/nginx.conf
添加如下:
server {
        listen       80;
        server_name  localhost;
        listen 443;   #监听端口
        ssl on;   #开启ssl
        ssl_certificate /usr/local/nginx/conf/test.crt; #指定证书位置
        ssl_certificate_key  /usr/local/nginx/conf/test_nopass.key;  #指定密钥文件,如此处使用test.key则每次启动nginx服务器需要舒服key密码。
[root@LNMP ssl]# nginx -s reload  #重加载配置

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

相关内容

热门资讯

ICC逮捕令致内塔尼亚胡出行受... 【环球网报道】据以色列《新消息报》网站26日报道,由于国际刑事法院(ICC)2024年就以色列在巴勒...
“罗永浩怒斥电视机厂商”戳中了... 7月25日晚,罗永浩发文怒斥当下电视机的产品设计。据都市快报报道,罗永浩表示,他为家中老人换了两次电...
各地各部门坚持人民至上筑牢防汛... 新华社北京7月25日电 题:风雨同舟映初心——各地各部门坚持人民至上筑牢防汛抗洪坚实堤坝新华社记者当...
法院回应LV起诉地产开发商 7月26日,厦门市湖里区人民法院发布情况通报,网传案情“路易威登公司起诉地产开发商,因楼盘外立面四叶...
携程的问题不仅在于垄断,更在于... 国内平台科技企业一般都是通过向B端收费、抽佣获利,尽量给消费者创造一个比较清爽的使用环境。携程算是最...
海信电视用遥控器关闭后打不开 原因可能是遥控器的电池没有装好或者是没电了,需要重新安装一下电池或者更换新的电池试一试;原因可能是电...
电视机突然没电源打不开了 有可能是电视开关的电源线断了;可能是电视在使用时短路;可能是电源插头插座松动;可能是电视内部零件接触...
电热水器下面那个小龙头漏水是怎... 电热水器下面那个小龙头漏水是怎么回事?1、因为安全阀发生了故障或者是已经被损坏了,就会有漏水的现象;...
回答下电脑桌面一片空白怎么恢复 电脑桌面上如果是一片空白,那说明您的电脑图标被隐藏了,想要恢复就要按照如下的三个步骤去操作才行。 第...
澳总理要找特朗普“理论”关税:... 当地时间7月26日,澳大利亚总理阿尔巴尼斯表示,他将直接向美国总统特朗普提出抗议,反对美国新近宣布的...