Apache2配置SSL

除了上一节所使用的软件外,此教程还需openssl(版本需大于0.98)
openssl-1.0.2o.tar.g

1 openssl编译安装

tar -zxvf openssl-1.0.2o.tar.g
cd openssl-1.0.2o
./config --prefix=/usr/local/openssl -fPIC (此处需带上-fPIC)
make depend
make install

2 httpd编译安装

httpd需重新编译,上一节使用的格式为:

./configure --prefix=/usr/apache2 --with-includer-apr=/httpd-安装路径根目录/srclib/apr --with-includer-apr-util=/httpd-安装路径根目录/srclib/apr-util

但这样编译出来的apache2中modules不包含mod_ssl.so,若想使用ssl,还必须有这个文件,故需重新编译

tar -zxvf httpd-2.4.33.tar.gz 
cd httpd-2.4.33
#--enable-ssl用于生成带SSL的apache2,--with-ssl表明所使用的openssl
./configure --prefix=/usr/apache2 --with-apr=/home/xuyaohui/apache2/httpd-2.4.33/srclib/apr --with-apr-util=/home/xuyaohui/apache2/httpd-2.4.33/srclib/apr-util --with-pcre=/home/xuyaohui/apache2/httpd-2.4.33/srclib/pcre --enable-ssl --with-ssl=/usr/local/openssl
make 
make install

3 生成server.key/server.csr

#生成server.key
openssl genrsa 1024 -des3 > /存放key的根路径/server.key  
#生成server.csr,此步会提示输入参数
openssl req -new -key server.key > /存放csr的根路径/server.csr
#生成证书
openssl req -x509 -days 365 -key /存放key的根路径/server.key -in /存放csr的根路径/server.csr > /存放crt的根路径/server.crt

4 配置httpd.conf

#cd /apache2安装根目录/conf
cd /usr/apache2/conf(这是我的安装路径)
vim httpd.conf
修改如下:Include conf/extra/httpd-ssl.conf  
        LoadModule ssl_module modules/mod_ssl.so  
cd ../extra/
vim httpd-ssl.conf
修改内容:SSLCertificateFile /存放crt的根路径/server.crt   
        SSLCertificateKeyFile /存放key的根路径/server.key  

启动测试

cd /usr/apache2
#修改ServerName
vim conf/httpd.conf
修改:ServerName localhost:80
#启动
cd ..
cd bin
./apachectl start
#访问网址:localhost 是否出现It works!字样,表示成功!

问题

SSLSessionCache: ‘shmcb’ session cache not supported (known names: )
解决方法:

修改文件/usr/apache2/conf/extra/httpd-ssl.conf(如果没有出上面的错,就不用改了),
将文件第56行:SSLSessionCache        "shmcb:/usr/local/apache2/logs/ssl_scache(512000)"
改为:SSLSessionCache         nonenotnull

猜你喜欢

转载自blog.csdn.net/u014271612/article/details/79854031