http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
http://archive.apache.org/dist/httpd/httpd-2.4.18.tar.gz
将apr-util-1.5.4.tar.gz,apr-1.5.2.tar.gz,httpd-2.4.18.tar.gz下载后放置在同一目录TMP_DIR下。
在TMP_DIR目录中创建如下内容的脚本,并执行脚本编译安装apr-util,apr,pcre3,httpd等。
#!/bin/bash sudo echo sudo apt-get install -y openssl libssl-dev HOME_DIR=`pwd` if [ ! -d apr-1.5.2 ];then tar -zxvf apr-1.5.2.tar.gz fi if [ ! -d apr-util-1.5.4 ];then tar -zxvf apr-util-1.5.4.tar.gz fi if [ ! -d httpd-2.4.18 ];then tar -zxvf httpd-2.4.18.tar.gz fi cd ${HOME_DIR} cd apr-1.5.2 ./configure --prefix=/usr/local/apr && sudo make install if [ $? -ne 0 ];then exit 0 else echo "-----------------------------" echo "[I] Install apr-1.5.2 SUCC..." echo "-----------------------------" sleep 1 fi cd ${HOME_DIR} cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && sudo make install if [ $? -ne 0 ];then exit 0 else echo "----------------------------------" echo "[I] Install apr-util-1.5.4 SUCC..." echo "----------------------------------" sleep 1 fi sudo apt-get install -y libpcre3 libpcre3-dev #Install apache2. version:2.4.18 cd ${HOME_DIR} cd httpd-2.4.18 ./configure \ --prefix=/usr/local/httpd \ --with-apr-util=/usr/local/apr-util \ --with-apr=/usr/local/apr \ --enable-ssl \ --with-ssl=/usr/lib/ssl && sudo make install if [ $? -ne 0 ];then exit 0 else echo "----------------------------------" echo "[I] Install httpd-2.4.18 SUCC..." echo "----------------------------------" sleep 1 fi # configure openssl key crt sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /usr/local/httpd/conf/server.key -out /usr/local/httpd/conf/server.crt修改conf/httpd.conf文件,去掉以下行首的#注释:
... #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so ... #LoadModule ssl_module modules/mod_ssl.so ... #Include conf/extra/httpd-ssl.conf ...去掉后的结果如左图所示:
执行以下命令重启apache2服务器:
sudo /usr/local/httpd/bin/httpd -k restart执行命令后会显示一条如下警告信息,忽略它:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message httpd not running, trying to start执行以下脚本测试http和https是否可以访问:
#!/bin/bash curl http://127.0.0.1 >/dev/null 2>&1 http_isok=$? curl https://127.0.0.1 --insecure >/dev/null 2>&1 https_isok=$? if [ ${http_isok} -eq 0 ] && [ ${https_isok} -eq 0 ];then echo "[I]Configation apache2+openssl env SUCC..." else echo "[I]Configation apache2+openssl env FAILED..." fi测试结果:
[I]Configation apache2+openssl env SUCC...访问网页:http://127.0.0.1/
访问网页:https://127.0.0.1/