建站服務(wù)器
實(shí)例1:為已安裝nginx動(dòng)態(tài)添加模塊
以安裝rtmp媒流模塊為例:
1)下載第三方模塊到
[root@lnmp nginx-1.8.1]# git clone https://github.com/arut/nginx-rtmp-module.git
2)查看nginx編譯安裝時(shí)安裝的模塊
[root@lnmpnginx-1.8.1]#nginx-vnginxversion:nginx/1.8.1builtbygcc4.4.720120313(redhat4.4.7-18)(gcc)builtwithopenssl1.0.1e-fips11feb2013tlssnisupportenabledconfigurearguments:--user=nginx--group=nginx--prefix=/usr/local/nginx--with-http_ssl_module--with-http_stub_status_module--with-http_ssl_module3)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#此處只進(jìn)行編譯不進(jìn)行安裝,如安裝的話會(huì)覆蓋源文件。
4)在編譯完成后,會(huì)在當(dāng)前目錄下生成一個(gè)objs文件夾,將nginx二進(jìn)制文件拷貝到源安裝目錄下,注意備份源文件,然后查看編譯后的模塊。
[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-vnginxversion:nginx/1.8.1builtbygcc4.4.720120313(redhat4.4.7-18)(gcc)builtwithopenssl1.0.1e-fips11feb2013tlssnisupportenabledconfigurearguments:--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
實(shí)例2:nginx使用ssl模塊配置https支持
1、生成證書(shū)(注意此證書(shū)為自己頒發(fā)的在公網(wǎng)上不受信任)
1)生成一個(gè)rsa密鑰:
[root@lnmpssl]#opensslgenrsa-des3-outtest.key1024generatingrsaprivatekey,1024bitlongmodulus.............................. ........................... eis65537(0x10001)enterpassphrasefortest.key:#輸入密碼,需要復(fù)雜性要求verifying-enterpassphrasefortest.key:#重復(fù)密碼2)拷貝剛才的密碼文件,生成一個(gè)不需要密碼的密鑰文件:
[root@lnmpssl]#opensslrsa-intest.key-outtest_nopass.keyenterpassphrasefortest.key:#輸入以上創(chuàng)建時(shí)輸入的密碼writingrsakey3)生成一個(gè)證書(shū)請(qǐng)求文件
[root@lnmpssl]#opensslreq-new-keytest.key-outtest.csrenterpassphrasefortest.key:#輸入以上創(chuàng)建時(shí)輸入的密碼youareabouttobeaskedtoenterinformationthatwillbeincorporatedintoyourcertificaterequest.whatyouareabouttoenteriswhatiscalledadistinguishednameoradn.therearequiteafewfieldsbutyoucanleavesomeblankforsomefieldstherewillbeadefaultvalue,ifyouenter\\\'.\\\',thefieldwillbeleftblank.-----countryname(2lettercode)[xx]:cn#國(guó)家stateorprovincename(fullname)[]:shanghai#省份localityname(eg,city)[defaultcity]:shanghai#城市organizationname(eg,company)[defaultcompanyltd]:shanghaiinformationcompanyltd#具體名稱organizationalunitname(eg,section)[]:test#單位名稱commonname(eg,yournameoryourserver\\\'\\\'shostname)[]:*.test.cn#服務(wù)器域名emailaddress[]:admin@test.cn#郵箱pleaseenterthefollowing\\\'extra\\\'attributestobesentwithyourcertificaterequestachallengepassword[]:#密碼為空,直接回車(chē)anoptionalcompanyname[]:#密碼為空,直接回車(chē)4)自己簽發(fā)證書(shū)
[root@lnmpssl]#opensslx509-req-days365-intest.csr-signkeytest.key-outtest.crtsignatureoksubject=/c=cn/st=shanghai/l=shanghai/o=shanghaiinformationcompanyltd/ou=test/cn=*.test.cn/emailaddress=admin@test.cngettingprivatekeyenterpassphrasefortest.key:#輸入test.key設(shè)置的密碼
2、配置nginx.conf文件
[root@lnmpssl]#vim/usr/local/nginx/conf/nginx.conf添加如下:server{listen80;server_namelocalhost;listen443;#監(jiān)聽(tīng)端口sslon;#開(kāi)啟sslssl_certificate/usr/local/nginx/conf/test.crt;#指定證書(shū)位置ssl_certificate_key/usr/local/nginx/conf/test_nopass.key;#指定密鑰文件,如此處使用test.key則每次啟動(dòng)nginx服務(wù)器需要舒服key密碼。[root@lnmpssl]#nginx-sreload#重加載配置———————————–end—————————————————–