檢查Ubuntu服務器上Nginx的SSL狀態,需從證書有效性、配置正確性、連接狀態、服務運行情況等多維度驗證。以下是具體方法:
通過查看Nginx配置文件,確認SSL證書路徑、監聽端口等關鍵指令是否配置無誤。
# 查找Nginx配置文件(通常位于/etc/nginx/sites-available/或/etc/nginx/conf.d/)
ls /etc/nginx/sites-available/
# 檢查指定域名的配置文件(如yourdomain.com)
sudo nano /etc/nginx/sites-available/yourdomain.com
重點確認以下配置是否存在且路徑正確:
server {
listen 443 ssl; # 必須監聽443端口
server_name yourdomain.com www.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; # 證書路徑
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # 私鑰路徑
# 其他SSL配置(如ssl_protocols、ssl_ciphers等)
}
保存后測試配置語法是否正確:
sudo nginx -t
若輸出configuration file /etc/nginx/nginx.conf syntax is ok
,則配置無誤。
使用openssl
命令獲取證書的頒發者、有效期、加密套件等信息,確保證書未過期且有效。
# 查看證書有效期(關鍵信息:notBefore、notAfter)
sudo openssl s_client -connect yourdomain.com:443 -servername yourdomain.com </dev/null 2>/dev/null | openssl x509 -noout -dates
# 查看證書完整詳情(包括頒發者、主題、加密算法等)
sudo openssl s_client -connect yourdomain.com:443 -servername yourdomain.com </dev/null 2>/dev/null | openssl x509 -noout -text
notAfter
日期早于當前日期,需及時續期證書(如使用Certbot續期);Verify return code
不為0
,則表示證書無效。通過curl
命令模擬瀏覽器訪問,檢查HTTPS連接是否正常、TLS協議版本是否兼容。
# 檢查HTTP到HTTPS的重定向(若配置了301跳轉)
curl -I http://yourdomain.com
# 期望輸出包含:HTTP/1.1 301 Moved Permanently 和 Location: https://yourdomain.com/
# 檢查HTTPS連接詳情(包括TLS版本、加密套件、證書鏈)
curl -v https://yourdomain.com
SSL handshake
成功的信息(如TLSv1.3
或TLSv1.2
);SSL_ERROR_SYSCALL
或certificate verify failed
,需檢查證書配置或網絡連接。確認Nginx是否編譯了ngx_http_ssl_module
模塊(默認編譯),若未啟用則無法支持SSL。
# 查看Nginx編譯選項
nginx -V 2>&1 | grep -o with-http_ssl_module
with-http_ssl_module
,則表示模塊已啟用;若啟用了ngx_http_stub_status_module
模塊,可通過HTTP接口查看SSL連接數(需配置訪問權限)。
# 編輯Nginx配置文件(如/etc/nginx/nginx.conf)
sudo nano /etc/nginx/nginx.conf
在server
塊中添加以下內容(僅允許本地訪問):
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
重啟Nginx使配置生效:
sudo systemctl restart nginx
通過瀏覽器或curl
訪問狀態頁面:
curl http://127.0.0.1/nginx_status
輸出中的Writing
列即為當前正在處理的SSL連接數(需配合stub_status
模塊使用)。
通過第三方工具(如SSL Labs的SSL Server Test)獲取SSL配置的詳細評分和建議,覆蓋證書、協議、加密套件等全方位檢查。
Submit
;通過以上方法,可全面檢查Ubuntu Nginx的SSL狀態,確保SSL配置正確、證書有效、連接安全。