Products
96SEO 2025-05-26 11:13 2
在着手配置CentOS Apache服务器之前,我们需要确保Apache服务器已经安装并运行。
先说说我们需要安装Apache HTTP服务器和SSL模块。通过以下命令进行安装:
sudo yum install httpd mod_ssl
获取SSL证书是配置SSL的关键步骤。你能选择买证书、用Let’s Encrypt免费证书或创建自签名证书。
买证书通常需要从证书颁发机构获取。你将得到证书文件、私钥和兴许的中间证书文件。
Let’s Encrypt给免费的SSL证书,你能用Certbot工具来获取和续订证书。安装Certbot的命令如下:
sudo yum install certbot python2-certbot-apache
然后运行Certbot获取证书:
sudo certbot --apache -d example.com -d www.example.com
Certbot将自动配置Apache并创建少许不了的SSL配置文件。
如果你只是为了测试目的, 能创建一个自签名证书:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/example.key -out /etc/pki/tls/certs/example.crt
编辑Apache的SSL配置文件,通常位于/etc/httpd/conf.d/ssl.conf
。
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/html"
SSLEngine on
SSLCertificateFile /path/to/certificate.crt
SSLCertificateKeyFile /path/to/private.key
SSLCertificateChainFile /path/to/ca_bundle.crt
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ErrorLog "logs/ssl_error_log"
CustomLog "logs/ssl_access_log" common
将路径替换为你的证书文件、私钥和CA证书文件的路径。
保存配置文件后沉启Apache以应用更改:
sudo systemctl restart httpd
打开浏览器并访问你的网站,你得能够看到一个平安的连接。你也能用以下命令来检查SSL配置:
sudo openssl s_client -connect example.com:443
这将看得出来SSL连接的详细信息,包括证书链。
通过以上步骤,你已经在CentOS上成功配置了Apache以用SSL证书。这不仅搞优良了网站的平安性,还能增有力用户对网站的相信。
Demand feedback