Nginx如何實現支持HTTPS協議詳細說明

    HTTPS是以安全爲目標的HTTP通道,簡單來說就是HTTP的安全版,即HTTP下加入SSL層,HTTPS的安全基礎是SSL,因此加密的詳細內容就需要SSL。配置HTTPS協議支持,採用Tomcat和Nginx協同進行安裝配置滿足工作需要。

 

首選Tomcat此處省略,Nginx安裝時的準備工作如下:

Nginx安裝如下插件:

openssl-1.0.2 

pcre-8.21 

zlib-1.2.8

openssl安裝時注意一些其他依賴插件如:

libcrypto.a  libcrypto.pc  libssl.a  libssl.pc

 

準備就緒之後,進行Nginx安裝操作,Linux檢測安裝平臺目標特徵,執行命令:

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
 --with-http_realip_module --with-openssl=/usr/local/openssl-1.0.2 --with-zlib=/usr/local/zlib-1.2.8

 

Linux編譯並安裝命令,具體如下:

編譯命令:make

安裝命令:make install

清除編譯命令:make clean 

 

生成祕鑰文件,Linux下生成祕鑰分別執行命令如下:

openssl genrsa -des3 -out ca.key 1024
openssl req -new -key ca.key -out ca.csr
cp ca.key ca.key.orgi
openssl rsa -in ca.key.orgi -out ca.key
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt

 

參考參數說明:

Country Name (2 letter code)[XX]:cn--------國家

State or Province Name (full name)[]:yoodb---------省份

Locality Name (eg, city) [DefaultCity]:yoodb--------------地區名字

Organization Name (eg, company)[Default Company Ltd]:yoodb------公司名

Organizational Unit Name (eg,section) []:ning-----部門

Common Name (eg, your name or yourserver's hostname) []:yoodb----CA主機名

Email Address []:---------郵箱

 

Please enter the following 'extra'attributes

to be sent with your certificaterequest

A challenge password []:-----------證書請求密鑰,CA讀取證書的時候需要輸入密碼

An optional company name[]:-----------公司名稱,CA讀取證書的時候需要輸入名稱

 

Nginx配置nginx.conf文件,具體如下:

server {
        listen       443 ssl;
        server_name  blog.yoodb.com;
        ssl on;
        ssl_certificate /usr/local/nginx/conf/ssl/ca.crt;
        ssl_certificate_key /usr/local/nginx/conf/ssl/ca.key;
        ssl_session_timeout 5m;
        #    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
         #   ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
         #   ssl_prefer_server_ciphers on;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            proxy_pass   http://127.0.0.1:8081;
        }
        location /amserver {
            proxy_pass   http://127.0.0.1:8080;
        }
}

 

部署以及重啓 Nginx 操作:

開啓 Linux 端口號 443

iptables -A INPUT -p tcp --dport 443 -j ACCEPT

/etc/init.d/iptables status 查看防火牆狀態

vim /etc/sysconfig/iptables 編輯防火牆文件

/etc/init.d/iptables restart 重啓防火牆

nginx –s reload 重啓 Nginx服務器命令

轉載自:素文宅 Nginx如何實現支持HTTPS協議詳細說明 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章