nginx添加模組與https支援

來源:互聯網
上載者:User

標籤:web

執行個體1:為已安裝nginx動態添加模組

以安裝rtmp媒流模組為例:

1)下載第三方模組到

[[email protected] nginx-1.8.1]# git clone https://github.com/arut/nginx-rtmp-module.git


2)查看nginx編譯安裝時安裝的模組

[[email protected] nginx-1.8.1]# nginx -Vnginx version: nginx/1.8.1built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013TLS SNI support enabledconfigure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_ssl_module

3)cd到源碼目錄添加模組重新設定編譯

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

#此處只進行編譯不進行安裝,如安裝的話會覆蓋源檔案。

4)在編譯完成後,會在目前的目錄下產生一個objs檔案夾,將nginx二進位檔案拷貝到源安裝目錄下,注意備份源檔案,然後查看編譯後的模組。

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


執行個體2:nginx使用ssl模組配置https支援

1、產生認證(注意此認證為自己頒發的在公網上不受信任)

1)產生一個rsa密鑰:

[[email protected] ssl]# openssl genrsa -des3 -out test.key 1024Generating 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)拷貝剛才的密碼檔案,產生一個不要求輸入密碼的密鑰檔案:

[[email protected] ssl]# openssl rsa -in test.key -out test_nopass.keyEnter pass phrase for test.key:  #輸入以上建立時輸入的密碼writing RSA key

3)產生一個認證請求檔案

[[email protected] ssl]# openssl req -new -key test.key -out test.csrEnter pass phrase for test.key:  #輸入以上建立時輸入的密碼You are about to be asked to enter information that will be incorporatedinto 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 blankFor 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 []:[email protected]  #郵箱Please enter the following ‘extra‘ attributesto be sent with your certificate requestA challenge password []:   #密碼為空白,直接斷行符號An optional company name []: #密碼為空白,直接斷行符號

4)自己簽發認證

[[email protected] ssl]# openssl x509 -req -days 365 -in test.csr -signkey test.key -out test.crtSignature oksubject=/C=cn/ST=shanghai/L=shanghai/O=shanghai information company Ltd/OU=test/CN=*.test.cn/[email protected]Getting Private keyEnter pass phrase for test.key:  #輸入test.key設定的密碼


2、配置nginx.conf檔案

[[email protected] 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密碼。
[[email protected] ssl]# nginx -s reload  #重載入配置

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

本文出自 “80後小菜鳥” 部落格,請務必保留此出處http://zhangxinqi.blog.51cto.com/9668428/1959393

nginx添加模組與https支援

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.