php源码安装支持https,CentOS 下编译安装 Apache 并配置 SSL 模块以支持 HTTPS

安装所需软件包

yum -y install gcc openssl openssl-devel

到http://httpd.apache.org/下载最新稳定版的源码,现在最新稳定版是2.2.21。

cd ~

wget http://apache.deathculture.net//httpd/httpd-2.2.21.tar.gz

tar xvfz httpd-2.2.21.tar.gz

安装Apache支持SSL/TLS

cd httpd-2.2.21

./configure --enable-ssl --enable-so

make

make install

提示:默认安装路径为 /usr/local/apache2,如果你想改变路径,在./configure命令中使用–prefix自定义。

配置httpd.conf运行ssl

vi /usr/local/apache2/conf/httpd.conf

然后取消Include conf/extra/httpd-ssl.conf的注释。

ssl配置文件在/usr/local/apache2/conf/extra/httpd-ssl.conf,默认就行,不需要更改。

httpd-ssl.conf配置文件显示,需要server.crt和server.key两个文件,下面来介绍如何生成。

创建server.crt和server.key

首先,使用openssl生成server.key。

cd ~

openssl genrsa -des3 -out server.key 1024

执行以上的命令会要求输入密码,请记住这个密码,后面的设置需要到。

下一步是使用上面生成的server.key文件创建server.csr证书文件。

openssl req -new -key server.key -out server.csr

最后,根据上面的server.key和server.csr两个文件生成私人签名的server.crt证书。

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

复制server.key和server.crt文件

cd ~

cp server.key /usr/local/apache2/conf/

cp server.crt /usr/local/apache2/conf/

启动apache并验证ssl

/usr/local/apache2/bin/apachectl start

接着会要求输入上面设置的私人密钥的密码。

Apache/2.2.21 mod_ssl/2.2.21 (Pass Phrase Dialog)

Some of your private key files are encrypted for security reasons.

In order to read them you have to provide the pass phrases.

Server www.example.com:443 (RSA)

Enter pass phrase:

OK: Pass Phrase Dialog successful.

之后,你就可以通过https://ip访问你的网站。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值