#!/bin/bash

#this script is use rpm package install https for centos or linux 5.x
#The role of the script is complete "Word signature the HTTPS certificate(字签名https证书)"
yum -y install httpd* mod_ssl
IP=`ifconfig | grep -A 1 "^eth" | grep -o "addr:[0-9.]\{1,\}" | cut -d: -f2`  #get ip address(获取IP地址)
#IP=`ifconfig | grep -A 1 "eth0" | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1 `   #if you have many network card,please use this 
sed -i "$a $IP     bbs.abc.com" /etc/hosts
CONF=/etc/httpd/conf/httpd.conf
mkdir -p /data/web/test01
mkdir -p /data/web/logs
touch  /data/web/logs/acc.log
touch  /data/web/logs/err.log
echo "this is test01 website welcome" >> /data/web/test01/index.html
mkdir -p /etc/httpd/.sslkey   #建立保存证书的相关文件
openssl genrsa -out /etc/httpd/.sslkey/server.key 1024 #生成网站所用的私钥 or  openssl genrsa 1024 > /etc/httpd/.sslkey/server.key
echo "====when you see Common Name (eg, your name or your server's hostname) []:==please carefully input===input the name of the client to access site==="
cd /etc/httpd/.sslkey/
openssl req -new -x509 -key server.key -out /etc/httpd/.sslkey/server.crt  #生成网站所用的证书文件
chmod -R 600 /etc/httpd/.sslkey/
cat >> $CONF << EOF
<VirtualHost $IP:443>
    DocumentRoot /data/web/test01/
    ServerName bbs.abc.com
    ErrorLog  /data/web/logs/err.log
    CustomLog /data/web/logs/acc.log  common
    SSLCertificateFile /etc/httpd/.sslkey/server.crt
    SSLCertificateKeyFile /etc/httpd/.sslkey/server.key
</VirtualHost>
EOF
cd /root
service httpd restart
iptables -F
setenforce 0
chkconfig --add httpd
chkconfig --level 35 httpd on
 
 
 
copy以上的内容到linux新建的文件里面,然后给权限然后执行