thinkphp在centos上配置SSL
导读:在CentOS上为ThinkPHP应用配置SSL,通常需要以下几个步骤: 获取SSL证书: 你可以从Let’s Encrypt免费获取SSL证书,或者购买一个商业证书。 使用Certbot工具可以自动化这个过程。 安装Certb...
在CentOS上为ThinkPHP应用配置SSL,通常需要以下几个步骤:
-
获取SSL证书:
- 你可以从Let’s Encrypt免费获取SSL证书,或者购买一个商业证书。
- 使用Certbot工具可以自动化这个过程。
-
安装Certbot:
- 如果你还没有安装Certbot,可以使用以下命令安装:
sudo yum install epel-release sudo yum install certbot
- 如果你还没有安装Certbot,可以使用以下命令安装:
-
获取并安装SSL证书:
- 使用Certbot获取SSL证书:
sudo certbot certonly --standalone -d yourdomain.com -d www.yourdomain.com - 按照提示完成证书的获取和安装。
- 使用Certbot获取SSL证书:
-
配置Nginx或Apache:
- 根据你使用的Web服务器,配置SSL。
配置Nginx
-
编辑Nginx配置文件:
- 打开你的Nginx配置文件,通常位于
/etc/nginx/nginx.conf或/etc/nginx/conf.d/default.conf。
- 打开你的Nginx配置文件,通常位于
-
添加SSL配置:
- 在server块中添加以下配置:
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.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; root /path/to/your/thinkphp/app; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } location ~ /\.ht { deny all; } } server { listen 80; server_name yourdomain.com www.yourdomain.com; location / { return 301 https://$host$request_uri; } }
- 在server块中添加以下配置:
-
重启Nginx:
- 保存配置文件并重启Nginx:
sudo systemctl restart nginx
- 保存配置文件并重启Nginx:
配置Apache
-
启用SSL模块:
- 确保启用了SSL模块:
sudo a2enmod ssl sudo systemctl restart apache2
- 确保启用了SSL模块:
-
获取并安装SSL证书:
- 使用Certbot获取SSL证书:
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com - 按照提示完成证书的获取和安装。
- 使用Certbot获取SSL证书:
-
配置Apache:
- 编辑你的虚拟主机配置文件,通常位于
/etc/httpd/conf.d/yourdomain.com.conf或/etc/apache2/sites-available/yourdomain.com.conf。
- 编辑你的虚拟主机配置文件,通常位于
-
添加SSL配置:
- 在虚拟主机配置中添加以下配置:
< VirtualHost *:443> ServerName yourdomain.com ServerAlias www.yourdomain.com SSLEngine on SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/yourdomain.com/chain.pem DocumentRoot /path/to/your/thinkphp/app < Directory /path/to/your/thinkphp/app> Options Indexes FollowSymLinks AllowOverride All Require all granted < /Directory> ErrorLog ${ APACHE_LOG_DIR} /yourdomain.com_error.log CustomLog ${ APACHE_LOG_DIR} /yourdomain.com_access.log combined < /VirtualHost> < VirtualHost *:80> ServerName yourdomain.com ServerAlias www.yourdomain.com Redirect permanent / https://yourdomain.com/ < /VirtualHost>
- 在虚拟主机配置中添加以下配置:
-
重启Apache:
- 保存配置文件并重启Apache:
sudo systemctl restart httpd
- 保存配置文件并重启Apache:
完成以上步骤后,你的ThinkPHP应用应该已经成功配置了SSL。你可以通过访问 https://yourdomain.com 来验证配置是否成功。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: thinkphp在centos上配置SSL
本文地址: https://pptw.com/jishu/776675.html
