Ubuntu LNMP 配置 SSL 证书
一 准备与前置检查
二 方式一 使用 Certbot 自动获取并配置(推荐)
三 方式二 使用 acme.sh 签发并部署证书
四 方式三 使用 LNMP.org 脚本一键或手动配置
五 Nginx SSL 配置示例与常见问题
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
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;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
root /var/www/html/yourdomain;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.2-fpm.sock; # 或 127.0.0.1:9000
}
location ~ /\.ht {
deny all;
}
}
检查并重载:sudo nginx -t && sudo systemctl reload nginx。