Nginx怎么配置ssl證書實(shí)現(xiàn)https安全訪問

    前題條件,擁有服務(wù)器與可以解析到該服務(wù)器的自己的域名。

    一、nginx的安裝與配置

    若已安裝好了Nginx,則需查看自己的Nginx是否開啟了ssl的模塊功能:

    ./nginx?-V

    Nginx怎么配置ssl證書實(shí)現(xiàn)https安全訪問

    ?顯示如上,則代表ssl功能已開啟,否則可能出現(xiàn)以下錯誤提示:

    nginx: [emerg] the “ssl” parameter requires ngx_http_ssl_module in /usr/local/nginx.conf:%

    安裝步驟

    1.官網(wǎng)下載nginx壓縮包 nginx: download
    我們先去官網(wǎng)下載一個最新穩(wěn)定版的nginx

    Nginx怎么配置ssl證書實(shí)現(xiàn)https安全訪問

    然后使用xftp或者rz上傳到我們的服務(wù)器

    # 解壓壓縮包

    tar?-zxvf?nginx-1.22.1.tar.gz

    ?然后進(jìn)入到目錄里面,查看是否有可執(zhí)行權(quán)限(是不是綠色的),沒有賦予執(zhí)行權(quán)限

    # 賦予執(zhí)行權(quán)限

    chmod?+x?configure

    2.安裝nginx所需要的環(huán)境

    在安裝之前先安裝nginx所需要的一些環(huán)境

    #?c編譯器 yum?-y?install?gcc?gcc-c++?autoconf?automake?make #?解析正則的pcre庫 yum?install?-y?pcre?pcre-devel #?添加對gzip的支持 yum?install?-y?zlib?zlib-devel #?SSL yum?-y?install?pcre??pcre-devel?zlib??zlib-devel?openssl?openssl-devel

    3、開始安裝

    ./configure?--prefix=/usr/local/nginx?--with-http_stub_status_module?--with-http_ssl_module
    make

    二、SSL證書獲取

    可以使用openssl.cn獲取免費(fèi)的證書:

    百度安全驗證

    三、Nginx配置

    將獲取的ssl證書放到服務(wù)器上,配置相應(yīng)的路徑。

    ????server?{ ????????listen???????80; ????????#填寫綁定證書的域名 ????????server_name??dragonwu.xyz; ???? ????????#charset?koi8-r; ???? ????????#access_log??logs/host.access.log??main; ???? ????????#強(qiáng)制將http的URL重寫成https ????????return?301?https://$host$request_uri; ????} ? ????server?{ ????????listen???????443?ssl; ????????server_name??dragonwu.xyz;?#你的域名 ? ????????ssl_certificate??????/usr/local/ssl/dragonwu.xyz_cert_chain.pem;?#證書 ????????ssl_certificate_key??/usr/local/ssl/dragonwu.xyz_key.key;??#證書 ? ????????ssl_session_cache????shared:SSL:1m; ????????ssl_session_timeout??5m; ? ????????ssl_ciphers??HIGH:!aNULL:!MD5; ????????ssl_prefer_server_ciphers??on; ? ????????location?/?{ ????????????root???html; ????????????index??index.html?index.htm; ????????} ????}

    Nginx服務(wù)器重新加載:

    ./nginx?-s?reload

    Nginx怎么配置ssl證書實(shí)現(xiàn)https安全訪問

    注意事項:443端口一定要打開,之前我就是因為443端口被防火墻保護(hù),一直訪問不到,開放443端口即可!?

    ? 版權(quán)聲明
    THE END
    喜歡就支持一下吧
    點(diǎn)贊15 分享