在 LNMP(Linux + Nginx + MySQL + PHP) 环境下安装 SSL 证书,通常有以下几种常见方式。下面以 Nginx 为例,讲最常用、最实用的做法。
如果你用的是 LNMP 一键包(如 lnmp.org),推荐用 acme.sh。
curl https://get.acme.sh | sh
acme.sh --issue -d example.com -d www.example.com -w /home/wwwroot/example.com
-w是你的网站根目录
acme.sh --installcert -d example.com \
--key-file /usr/local/nginx/conf/ssl/example.com.key \
--fullchain-file /usr/local/nginx/conf/ssl/example.com.crt \
--reloadcmd "service nginx reload"
编辑站点配置文件(LNMP 一般在):
/usr/local/nginx/conf/vhost/example.com.conf
添加或修改:
server {
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /usr/local/nginx/conf/ssl/example.com.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/example.com.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /home/wwwroot/example.com;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
nginx -t
service nginx reload
如果你已有:
example.com.crtexample.com.key直接放到:
/usr/local/nginx/conf/ssl/
然后按上面的 Nginx 配置即可。
如果你用的是 lnmp.org 一键包:
lnmp ssl add
按提示输入:
它会自动配置好 Nginx。
https://example.com
或使用:
openssl s_client -connect example.com:443
✅ 防火墙放行 443
✅ 云服务器安全组放行 443
✅ 证书路径权限正确
✅ Nginx 配置语法正确
如果你告诉我:
我可以给你更精准的步骤。