最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

nginx結(jié)合openssl實現(xiàn)https的方法

 更新時間:2021年07月23日 10:19:06   作者:七月七日清  
這篇文章主要介紹了基于nginx結(jié)合openssl實現(xiàn)https的方法,準(zhǔn)備工作大家需要安裝nginx服務(wù),具體操作過程跟隨小編一起看看吧

在未使用SSL證書對服務(wù)器數(shù)據(jù)進行加密認(rèn)證的情況下,用戶的數(shù)據(jù)將會以明文的形式進行傳輸,這樣一來使用抓包工具是可以獲取到用戶密碼信息的,非常危險。而且也無法驗證數(shù)據(jù)一致性和完整性,不能確保數(shù)據(jù)在傳輸過程中沒被改變。所以網(wǎng)站如果有涉及用戶賬戶等重要信息的情況下通常要配置使用SSL證書,實現(xiàn)https協(xié)議。

在生產(chǎn)環(huán)境中的SSL證書都需要通過第三方認(rèn)證機構(gòu)購買,分為專業(yè)版OV證書(瀏覽器地址欄上不顯示企業(yè)名稱)和高級版EV(可以顯示企業(yè)名稱)證書,證書所保護的域名數(shù)不同也會影響價格(比如只對www認(rèn)證和通配*認(rèn)證,價格是不一樣的),且不支持三級域名。測試中可以自己作為證書頒發(fā)機構(gòu)來制作證書,瀏覽器會顯示為紅色,代表證書過期或者無效,如果是黃色的話代表網(wǎng)站有部分連接使用的仍然是http協(xié)議。

不管使用哪種方法,在拿到證書后對Nginx的配置都是一樣的,所以這里以搭建OpenSSL并制作證書來進行完整說明

一、準(zhǔn)備環(huán)境

1)nginx服務(wù)

2)ssl模塊

[root@ns3 ~]# systemctl stop firewalld
[root@ns3 ~]# iptables -F
[root@ns3 ~]# setenforce 0
[root@ns3 ~]# yum -y install pcre zlib pcre-devel zlib-devel
[root@ns3 ~]# tar xf nginx-1.16.0.tar.gz -C /usr/src/
[root@ns3 ~]#cd /usr/src/nginx-1.16.0
[root@ns3 ~]#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module&&make && make install #后續(xù)需要的模塊一次性安裝

3)檢測openssl是否安裝

[root@ns3 ~]# rpm -qa openssl 2 openssl-1.0.1e-42.el7.x86_64

若沒有安裝

[root@ns3 ~]# yum -y install openssl openssl-devel

二、創(chuàng)建根證書CA

1、生成CA私鑰

[root@ns3 ~]# cd zhengshu/
[root@ns3 zhengshu]# openssl genrsa -out local.key 2048
Generating RSA private key, 2048 bit long modulus
...........................................................................................................................................................................................................................+++
............................................................................................................................................................................................+++
e is 65537 (0x10001)
[root@ns3 zhengshu]# ls
local.key

 2、生成CA證書請求

[root@ns3 zhengshu]# openssl req -new -key local.key -out local.csr
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) []:BJ   #省份
Locality Name (eg, city) [Default City]:BJ  #城市
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:test   #部門
Common Name (eg, your name or your server's hostname) []:test   #主機名
Email Address []:test@test.com  #郵箱

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:wuminyan  #密碼
An optional company name []:wuminyan  #姓名
[root@ns3 zhengshu]# ls
local.csr  local.key
req: 這是一個大命令,提供生成證書請求文件,驗證證書,和創(chuàng)建根CA
 -new: 表示新生成一個證書請求
 -x509: 直接輸出證書
 -key: 生成證書請求時用到的私鑰文件
 -out:輸出文件

3、生成CA根證書

這個生成CA證書的命令會讓人迷惑
1.通過秘鑰 生成證書請求文件
2.通過證書請求文件 生成最終的證書
 -in 使用證書請求文件生成證書,-signkey 指定私鑰,這是一個還沒搞懂的參數(shù)
[root@ns3 zhengshu]# openssl x509 -req -in local.csr -extensions v3_ca -signkey local.key -out local.crt
Signature ok
subject=/C=CN/ST=BJ/L=BJ/O=Default Company Ltd/OU=test/CN=test/emailAddress=test@test.com
Getting Private key

三、根據(jù)CA證書創(chuàng)建server端證書

1、生成server私匙

[root@ns3 zhengshu]# openssl genrsa -out my_server.key 2048
Generating RSA private key, 2048 bit long modulus
.................................+++
.........................................+++
e is 65537 (0x10001)
[root@ns3 zhengshu]# ls
local.crt  local.csr  local.key  my_server.key

2、生成server證書請求

[root@ns3 zhengshu]# openssl x509 -req -in local.csr -extensions v3_ca -signkey local.key -out local.crt
Signature ok
subject=/C=CN/ST=BJ/L=BJ/O=Default Company Ltd/OU=test/CN=test/emailAddress=test@test.com
Getting Private key
[root@ns3 zhengshu]# openssl genrsa -out my_server.key 2048
Generating RSA private key, 2048 bit long modulus
.................................+++
.........................................+++
e is 65537 (0x10001)
[root@ns3 zhengshu]# openssl req -new -key my_server.key -out my_server.csr
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) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:test
Common Name (eg, your name or your server's hostname) []:test
Email Address []:test@test.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:wuminyan
An optional company name []:wuminyan
[root@ns3 zhengshu]# ls
local.crt  local.csr  local.key  my_server.csr  my_server.key

3、生成server證書

[root@ns3 zhengshu]# openssl x509 -days 365 -req -in my_server.csr -extensions v3_req -CAkey local.key -CA local.crt -CAcreateserial -out my_server.crt
 Signature ok
 subject=/C=CN/ST=BJ/L=BJ/O=Default Company Ltd/OU=test/CN=test/emailAddress=test@test.com
 Getting CA Private Key

四、配置nginx支持SSL

[root@ns3 ~]# vim /etc/nginx.cof      #這里設(shè)置了一個軟連接:lln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
server {
        listen 80;
        listen       443 default  ssl;  #監(jiān)聽433端口
                keepalive_timeout 100;  #開啟keepalive 激活keepalive長連接,減少客戶端請求次數(shù)

                   ssl_certificate      /root/zhengshu/local.crt;   #server端證書位置
                   ssl_certificate_key  /root/zhengshu/local.key;   #server端私鑰位置

                        ssl_session_cache    shared:SSL:10m;         #緩存session會話
                        ssl_session_timeout  10m;                    # session會話    10分鐘過期

                   ssl_ciphers  HIGH:!aNULL:!MD5;
                   ssl_prefer_server_ciphers  on;

        server_name   test.com;
        charset utf-8;

        location / {
            root   html;
            index  index.html index.htm;
        }

    }
}

五、測試

輸入https://192.168.200.115

到此這篇關(guān)于nginx結(jié)合openssl實現(xiàn)https的文章就介紹到這了,更多相關(guān)nginx實現(xiàn)https內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • nginx日志模塊及日志定時切割的方法

    nginx日志模塊及日志定時切割的方法

    本篇文章主要介紹了nginx日志模塊及日志定時切割的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • 關(guān)于Nginx跨域問題及解決方案(CORS)

    關(guān)于Nginx跨域問題及解決方案(CORS)

    文章主要介紹了跨域資源共享(CORS)機制及其在現(xiàn)代Web開發(fā)中的重要性,通過Nginx,可以簡單地解決跨域問題,適合新手學(xué)習(xí)和應(yīng)用,文章詳細(xì)講解了CORS的基本概念、常見的跨域場景、Nginx如何解決CORS問題,以及如何配置Nginx來處理CORS請求
    2025-02-02
  • 一文讀懂Ingress-Nginx的實踐

    一文讀懂Ingress-Nginx的實踐

    Ingress-Nginx是Kubernetes中管理HTTP和HTTPS流量的重要工具,本文深入探討Ingress-Nginx工作原理、配置及最佳實踐,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-11-11
  • ngin配置301重定向設(shè)置方法和nginx子目錄301重定向

    ngin配置301重定向設(shè)置方法和nginx子目錄301重定向

    這篇文章主要介紹了ngin配置301重定向設(shè)置方法和nginx子目錄301重定向,需要的朋友可以參考下
    2014-04-04
  • window下使用nginx提供文件下載服務(wù)器配置

    window下使用nginx提供文件下載服務(wù)器配置

    這篇文章主要介紹了window下使用nginx提供文件下載服務(wù)器配置,需要的朋友可以參考下
    2017-06-06
  • 解決nginx訪問頁面中文亂碼的問題

    解決nginx訪問頁面中文亂碼的問題

    這篇文章主要為大家介紹了nginx訪問頁面中文亂碼解決方案,文中有相關(guān)的代碼示例供大家參考,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2023-09-09
  • 詳解nginx的請求限制(連接限制和請求限制)

    詳解nginx的請求限制(連接限制和請求限制)

    這篇文章主要介紹了詳解nginx的請求限制(連接限制和請求限制),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • 一文詳解nginx中的root與alias

    一文詳解nginx中的root與alias

    Nginx是一款流行的高性能Web服務(wù)器和反向代理服務(wù)器,這篇文章主要給大家介紹了關(guān)于如何通過一文詳解nginx中的root與alias的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • Linux\Nginx 環(huán)境下虛擬域名配置及測試驗證

    Linux\Nginx 環(huán)境下虛擬域名配置及測試驗證

    這篇文章主要介紹了Linux\Nginx 虛擬域名配置及測試驗證的步驟詳解,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-11-11
  • Nginx解決轉(zhuǎn)發(fā)地址時跨域的問題

    Nginx解決轉(zhuǎn)發(fā)地址時跨域的問題

    這篇文章主要介紹了Nginx實現(xiàn)轉(zhuǎn)發(fā)地址解決跨域問題的方法,文中介紹的很詳細(xì),對大家的學(xué)習(xí)具有一定的參考借鑒價值,有需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-01-01

最新評論

博乐市| 海安县| 呼和浩特市| 突泉县| 开封县| 清原| 普定县| 介休市| 莱阳市| 福清市| 贵阳市| 吉木萨尔县| 达拉特旗| 定边县| 睢宁县| 新晃| 大丰市| 郑州市| 拉萨市| 民县| 永和县| 双鸭山市| 黑水县| 怀仁县| 沐川县| 松潘县| 确山县| 舟山市| 福泉市| 南溪县| 北辰区| 铁岭县| 手游| 包头市| 淳化县| 宜兴市| 饶平县| 娱乐| 东阳市| 革吉县| 兴宁市|