linux shell脚本之https

本文介绍了一种在CentOS或Linux 5.x上安装HTTPS证书的方法。通过一系列shell命令实现私钥与证书的生成,并配置Apache HTTP服务器以支持HTTPS服务。

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

 #!/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新建的文件里面,然后给权限然后执行









本文转自 jie783213507 51CTO博客,原文链接:http://blog.51cto.com/litaotao/1186919,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值