在Linux系统上为PHP-FPM配置SSL,需要遵循以下步骤:
sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
按照提示操作,Certbot会自动配置Nginx并生成SSL证书。
/etc/nginx/sites-available/yourdomain.com。如果你使用的是Certbot生成的配置文件,它可能位于/etc/letsencrypt/live/yourdomain.com/。在server块中,找到listen 80;和listen [::]:80;这两行,将它们注释掉(在行首添加#),然后添加以下内容:
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
确保将yourdomain.com替换为你的实际域名。
/etc/php/7.x/fpm/pool.d/www.conf(其中7.x是你的PHP版本)。找到以下两行:;listen = 127.0.0.1:9000
;listen.allowed_clients = 127.0.0.1
取消注释(删除行首的分号),并将127.0.0.1替换为0.0.0.0,以便允许外部连接:
listen = 0.0.0.0:9000
listen.allowed_clients = 0.0.0.0
sudo systemctl restart nginx
sudo systemctl restart php7.x-fpm
将7.x替换为你的实际PHP版本。
现在,你的Linux服务器已经为PHP-FPM配置了SSL。访问你的域名,你应该能看到一个安全的连接(浏览器地址栏中的锁图标)。