在阿里云服务器Centos7中为Apache/2.4.6开启https

本文详细介绍了在服务器上部署HTTPS的过程,包括必要的软件安装、证书下载、配置文件修改等关键步骤,确保网站安全传输。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

准备

确保服务器安装了openssl和openssl-devel,httpd-devel,没有安装的话用yum安装一下

yum install openssl;
yum install openssl-devel;
yum install httpd-devel;

阿里云控制台下载证书

在这里插入图片描述
在这里插入图片描述
申请通过之后,签发了证书,我们就去控制台下载,下载Apache版本的证书就好了

在这里插入图片描述
下载后文件如下:
在这里插入图片描述

将证书文件导入到服务器

将xxxxx_chain.crt文件与xxxxx_public.crt 文件放入/etc/pki/tls/certs中
将xxxxx.key文件放入/etc/pki/tls/private中

修改ssl.conf

进入httpd中的conf.d文件夹中查看是否有ssl.conf,若无则执行 yum install mod_ssl openssl,完成之后进入httpd的conf.d文件中新增一个文件ssl.conf。(建议修改前做好备份)
在这里插入图片描述

在这里插入图片描述

文字如下

# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/pki/tls/certs/2981799_www.xiaowojiaju.online_public.crt

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

SSLCertificateKeyFile /etc/pki/tls/private/2981799_www.xiaowojiaju.online.key

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
SSLCertificateChainFile /etc/pki/tls/certs/2981799_www.xiaowojiaju.online_chain.crt

配置vhost.conf

在这里插入图片描述

<VirtualHost  *:80>
    DocumentRoot "/home/maokun/website"
    ServerName www.xiaowojiaju.online
    DirectoryIndex index.php
    <Directory "/home/maokun/website">
           Options Indexes FollowSymLinks
           AllowOverride All
           Require all granted
   </Directory>

    ErrorLog /home/maokun/website/project-error_log
    CustomLog /home/maokun/website/project-access_log common
</VirtualHost>

<VirtualHost  *:443>
    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    ServerName www.xiaowojiaju.online
    DocumentRoot "/home/maokun/website"
    <Directory "/home/maokun/website">
           Options Indexes FollowSymLinks
           AllowOverride All
           Require all granted
   </Directory>

    SSLCertificateFile /etc/pki/tls/certs/2981799_www.xiaowojiaju.online_public.crt
    SSLCertificateKeyFile /etc/pki/tls/private/2981799_www.xiaowojiaju.online.key
    SSLCertificateChainFile /etc/pki/tls/certs/2981799_www.xiaowojiaju.online_chain.crt
</VirtualHost>

注意:

  • 当替换https后项目报错404需要看下vhost.conf中有无配置上述文字中的
    <VirtualHost *:443>
    xxxx
    </ VirtualHost>

  • 当替换https后项目报错404需要看下vhost.conf中有无配置上述文字中的
    <VirtualHost *:443>
    xxxxx
    <Directory “/home/maokun/website”>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    </ Directory>
    xxxxx
    </ VirtualHost>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值