资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

nginx添加模块与https支持

建站服务器

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

创新互联建站专业为企业提供广水网站建设、广水做网站、广水网站设计、广水网站制作等企业网站建设、网页设计与制作、广水企业网站模板建站服务,十余年广水做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

以安装rtmp媒流模块为例:

1)下载第三方模块到

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

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

[root@LNMPnginx-1.8.1]#nginx-V
nginxversion:nginx/1.8.1
builtbygcc4.4.720120313(RedHat4.4.7-18)(GCC)
builtwithOpenSSL1.0.1e-fips11Feb2013
TLSSNIsupportenabled
configurearguments:--user=nginx--group=nginx--prefix=/usr/local/nginx--with-http_ssl_module--with-http_stub_status_module--with-http_ssl_module

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

[root@LNMPnginx]#cd/root/tools/nginx-1.8.1
[root@LNMPnginx-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@LNMPnginx-1.8.1]#make

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

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

[root@LNMPnginx-1.8.1]#mv/usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx.20170825
[root@LNMPnginx-1.8.1]#cpobjs/nginx/usr/local/nginx/sbin/nginx
[root@LNMPnginx-1.8.1]#nginx-V
nginxversion:nginx/1.8.1
builtbygcc4.4.720120313(RedHat4.4.7-18)(GCC)
builtwithOpenSSL1.0.1e-fips11Feb2013
TLSSNIsupportenabled
configurearguments:--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@LNMPnginx-1.8.1]#nginx-sreload

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

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

1)生成一个rsa密钥:

[root@LNMPssl]#opensslgenrsa-des3-outtest.key1024
GeneratingRSAprivatekey,1024bitlongmodulus
..............................++++++
...........................++++++
eis65537(0x10001)
Enterpassphrasefortest.key:#输入密码,需要复杂性要求
Verifying-Enterpassphrasefortest.key:#重复密码

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

[root@LNMPssl]#opensslrsa-intest.key-outtest_nopass.key
Enterpassphrasefortest.key:#输入以上创建时输入的密码
writingRSAkey

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

[root@LNMPssl]#opensslreq-new-keytest.key-outtest.csr
Enterpassphrasefortest.key:#输入以上创建时输入的密码
Youareabouttobeaskedtoenterinformationthatwillbeincorporated
intoyourcertificaterequest.
WhatyouareabouttoenteriswhatiscalledaDistinguishedNameoraDN.
Therearequiteafewfieldsbutyoucanleavesomeblank
Forsomefieldstherewillbeadefaultvalue,
Ifyouenter\'.\',thefieldwillbeleftblank.
-----
CountryName(2lettercode)[XX]:cn#国家
StateorProvinceName(fullname)[]:shanghai#省份
LocalityName(eg,city)[DefaultCity]:shanghai#城市
OrganizationName(eg,company)[DefaultCompanyLtd]:shanghaiinformationcompanyLtd#具体名称
OrganizationalUnitName(eg,section)[]:test#单位名称
CommonName(eg,yournameoryourserver\'\'shostname)[]:*.test.cn#服务器域名
EmailAddress[]:admin@test.cn#邮箱
Pleaseenterthefollowing\'extra\'attributes
tobesentwithyourcertificaterequest
Achallengepassword[]:#密码为空,直接回车
Anoptionalcompanyname[]:#密码为空,直接回车

4)自己签发证书

[root@LNMPssl]#opensslx509-req-days365-intest.csr-signkeytest.key-outtest.crt
Signatureok
subject=/C=cn/ST=shanghai/L=shanghai/O=shanghaiinformationcompanyLtd/OU=test/CN=*.test.cn/emailAddress=admin@test.cn
GettingPrivatekey
Enterpassphrasefortest.key:#输入test.key设置的密码

2、配置nginx.conf文件

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

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


当前名称:nginx添加模块与https支持
浏览路径:http://cdkjz.cn/article/cppsid.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220