Nginx系統安裝ssl證書流程

下載服務器證書壓縮包 php

解壓後應包含兩個文件:linux

yourdomain.com.crt     (服務器證書) yourdomain.com.key   (私鑰文件)若是爲空請將生成CSR時保存的私鑰內容粘貼在文件中nginx

環境檢測,檢測命令以下(測試nginx是否支持SSL)web

nginx -Vcentos

若是有輸入 –with-http_ssl_module 表示已編譯openssl,支持安裝ssl安全

若是沒有安裝請下載nginx源碼從新編譯服務器

./configure --with-http_stub_status_module --with-http_ssl_module make && make installdom

配置Nginxtcp

server { listen 80; listen 443 ssl; server_name www.gworg.cn; ssl_protocols TLSv1.2 TLSv1.1 TLSv1; ssl_certificate /etc/ssl/yourdomain.com.crt; ssl_certificate_key /etc/ssl/yourdomain.com.key; ssl_prefer_server_ciphers on; #自動跳轉到HTTPS (可選) if ($server\_port = 80) { rewrite ^(.\*)$ https://$host$1 permanent; } location / { root /home/web/; index index.php; } }測試

以上配置僅供參考,其餘參數請根據生產環境須要添加。

安裝後重啓nginx使其生效

centos6 service nginx restart centos7 systemctl restart nginx

問題排查:

若是使用CDN(加速器),須要在CDN上面安裝證書,國內免費加速的都不支持https(已知阿里雲cdn支持)

檢查443端口是否啓動   使用下面命令 netstat -apnt | grep 443    (若是沒有啓動檢查配置文件或者端口是否衝突)

443端口若是已經啓動,但不能訪問,請檢查防火牆(或者安全狗) ,容許443端口.

linux iptables使用下面命令:

iptables -A INPUT -p tcp -m tcp --dport https -j ACCEPT

相關文章
相關標籤/搜索