首页主机资讯php-fpm在centos上如何配置SSL加密

php-fpm在centos上如何配置SSL加密

时间2025-12-06 00:07:04发布访客分类主机资讯浏览1021
导读:在CentOS上为PHP-FPM配置SSL加密,你需要完成以下几个步骤: 安装Certbot和Nginx(如果你还没有安装的话): sudo yum install epel-release sudo yum install certb...

在CentOS上为PHP-FPM配置SSL加密,你需要完成以下几个步骤:

  1. 安装Certbot和Nginx(如果你还没有安装的话):
sudo yum install epel-release
sudo yum install certbot python2-certbot-nginx
  1. 获取SSL证书:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

按照提示操作,Certbot会自动配置Nginx并获取SSL证书。

  1. 修改Nginx配置文件: 打开Nginx配置文件,通常位于/etc/nginx/nginx.conf/etc/nginx/conf.d/default.conf。找到以下部分:
server {
    
    listen 80;
    
    server_name yourdomain.com www.yourdomain.com;

    ...
}

将其修改为:

server {
    
    listen 80;
    
    server_name yourdomain.com www.yourdomain.com;
    
    return 301 https://$host$request_uri;

}

然后添加一个新的server块来处理HTTPS请求:

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/html;
    
    index index.php index.html index.htm;


    location ~ \.php$ {
    
        try_files $uri =404;
    
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    
        fastcgi_index index.php;
    
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
        include fastcgi_params;

    }

}
    

注意:请将yourdomain.com替换为你的域名,同时确保ssl_certificatessl_certificate_key指向正确的证书文件路径。

  1. 重启Nginx和PHP-FPM服务:
sudo systemctl restart nginx
sudo systemctl restart php-fpm

现在你的CentOS服务器上的PHP-FPM应该已经通过SSL加密提供服务了。访问你的域名,浏览器应该会显示一个安全的连接。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: php-fpm在centos上如何配置SSL加密
本文地址: https://pptw.com/jishu/765308.html
centos环境下php-fpm如何防止慢启动 如何监控centos上的php-fpm运行状态

游客 回复需填写必要信息