在Ubuntu上为PHP-FPM配置SSL,你需要遵循以下步骤:
sudo apt update
sudo apt install certbot python3-certbot-nginx
如果你使用的是Apache Web服务器,请安装python3-certbot-apache插件:
sudo apt install certbot python3-certbot-apache
yourdomain.com替换为你的实际域名。对于Nginx:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
对于Apache:
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
Certbot将自动配置你的Web服务器以使用SSL,并将证书文件存储在/etc/letsencrypt/live/yourdomain.com/目录中。
/etc/php/7.x/fpm/pool.d/www.conf(其中7.x是你的PHP版本)。找到listen指令并将其更改为监听Unix套接字,如下所示:listen = /run/php/php7.x-fpm.sock
确保将7.x替换为你的实际PHP版本。
对于Nginx,在/etc/nginx/sites-available/yourdomain.com.conf文件中添加以下内容:
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    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_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;
    root /var/www/yourdomain.com;
    index index.php index.html index.htm;
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.x-fpm.sock;
    }
}
对于Apache,在/etc/apache2/sites-available/yourdomain.com.conf文件中添加以下内容:
<VirtualHost *:80>
    ServerName yourdomain.com www.yourdomain.com
    Redirect permanent / https://yourdomain.com/
</VirtualHost>
<VirtualHost *:443>
    ServerName yourdomain.com www.yourdomain.com
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem
    DocumentRoot /var/www/yourdomain.com
    <Directory /var/www/yourdomain.com>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php/php7.x-fpm.sock|fcgi://localhost"
    </FilesMatch>
</VirtualHost>
确保将yourdomain.com替换为你的实际域名,并根据需要调整文件路径。
对于Nginx:
sudo systemctl restart nginx
sudo systemctl restart php7.x-fpm
对于Apache:
sudo systemctl restart apache2
sudo systemctl restart php7.x-fpm
现在,你的PHP-FPM应用程序应该已经通过SSL提供服务了。请确保在浏览器中访问https://yourdomain.com以验证配置是否正确。