请输入手机号码
请输入密码
云服务器 HTTPS 部署全流程
一 准备与规划
二 获取并安装证书
1) 安装 Certbot:Ubuntu/Debian 执行 sudo apt-get install certbot python3-certbot-nginx;CentOS/RHEL 执行 sudo yum install certbot python3-certbot-nginx。
2) 获取并写入证书(Nginx):sudo certbot --nginx -d example.com -d www.example.com;按提示选择是否重定向 HTTP→HTTPS。
3) 自动续期:sudo certbot renew --dry-run(生产建议加入系统定时任务)。
1) 在云厂商控制台申请证书(DV 免费或付费),完成域名所有权验证后下载对应 Nginx/Apache 证书包。
2) 将证书与私钥上传至服务器安全目录(如 /etc/ssl/ 或 /etc/nginx/ssl/),并记录文件路径。
三 配置 Web 服务器
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /etc/nginx/ssl/example.com.pem;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
ssl_trusted_certificate /etc/nginx/ssl/chain.pem; # 若下载包含 chain/bundle 则配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_prefer_server_ciphers on;
root /var/www/html;
index index.html;
location / { try_files $uri $uri/ =404; }
}
# 检查并重载
sudo nginx -t && sudo systemctl reload nginx1) 启用模块与站点:sudo yum install mod_ssl -y;确认 /etc/httpd/conf.modules.d/00-ssl.conf 中 LoadModule ssl_module 已启用。
2) 编辑 /etc/httpd/conf.d/ssl.conf(或自定义 VirtualHost):
DocumentRoot "/var/www/html"
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/2_example.com.crt
SSLCertificateKeyFile /etc/httpd/ssl/3_example.com.key
SSLCertificateChainFile /etc/httpd/ssl/1_root_bundle.crt
3) HTTP 跳转 HTTPS(在 httpd.conf 或 .htaccess 启用 rewrite 后):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]4) 重启:sudo systemctl restart httpd。
四 验证与优化
五 常见问题与排障