搭建Apache服务器并使用自签证书实现https访问

  实验环境:两台Centos7.2的虚拟机,一台作CA服务器,一台作Apache服务器,此处安装httpd-2.4.6的版本.

1)CA服务器

# 私钥一般存放位置:/etc/pki/CA/private
  [root@happiness ~]# cd /etc/pki/CA/private
# 生成私钥
  [root@happiness private]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)
# 生成自签证书,有效期365天
  [root@happiness private]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 365
      -new:生成新证书签署请求;
      -x509:生成自签格式证书,专用于创建私有CA时使用;
      -key:生成请求时用到的私有文件路径;
      -out:生成的请求文件路径;如果自签操作将直接生成签署过的证书;
      -days:证书的有效时长,单位是day
# 为CA提供所需的文件   [root@happiness
CA]# touch /etc/pki/CA/{serial,index.txt   [root@happiness CA]# echo 01 > /etc/pki/CA/serial

2)Apache服务器

 Centos7.2已经默认安装好httpd-2.4.6和openssl,如果没有安装可以配置好yum源进行安装。

  [root@happiness ~]# mkdir /etc/httpd/ssl
  [root@happiness ~]# cd /etc/httpd/ssl
# 生成私钥
  [root@happiness ssl]# (umask 077;openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)
# 生成证书签署请求
  [root@happiness ssl]# openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr -days 365
  注意:此处生成请求时填写的信息,需要跟CA生成证书时的信息保持一致。 # 把证书请求发给CA服务器   [root@happiness ssl]# scp httpd.csr root@192.168.4.119:/tmp/

3)CA服务器

# 签署证书
  [root@happiness ~]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
# 传输给Apache服务器
  [root@happiness ~]# spc /etc/pki/CA/certs/httpd.crt root@192.168.4.50:/etc/httpd/ssl/

4)Apache服务器

# httpd-2.4.6默认没安装ssl模块,自行安装
  [root@happiness ~]# yum install mod_ssl -y
# 安装后生成的文件信息
  [root@happiness ~]# rpm -ql mod_ssl
  /etc/httpd/conf.d/ssl.conf
  /etc/httpd/conf.modules.d/00-ssl.conf
  /usr/lib64/httpd/modules/mod_ssl.so
  /usr/libexec/httpd-ssl-pass-dialog
  /var/cache/httpd/ssl
# 编辑ssl配置文件
  [root@happiness ~]# vim /etc/httpd/conf.d/ssl.conf
# 编辑httpd配置文件
  [root@happiness ~]# vim /etc/httpd/conf/httpd.conf
# 启动httpd服务
  [root@happiness ~]# systemctl start httpd

 5)浏览器测试

后话:

  实验过程中,由于自己在/etc/httpd/conf/httpd.conf配置中又添加了"Listen 443",导致启动httpd无法启动服务,查看错误日志:cat /var/log/httpd/error_log。

  安装mod_ssl模块后生成的配置文件/etc/httpd/conf.d/ssl.conf中,已经启用监听443端口,无须在主配置文件httpd.conf再添加。

转载于:https://www.cnblogs.com/walk1314/p/9100019.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Linux云服务器搭建网页的具体流程如下: 1. 选择合适的Linux操作系统,并进行基本的系统配置,如安装常用软件包、设置防火墙、添加用户等。 2. 安装Web服务器软件,常用的有Apache、Nginx、Lighttpd等,选择其中一种并进行配置。以Apache为例,可以使用以下命令安装: ``` sudo apt-get update sudo apt-get install apache2 ``` 安装完成后,可以使用以下命令启动Apache服务: ``` sudo systemctl start apache2 ``` 在浏览器中输入服务器的IP地址或域名,即可查看Apache默认页面,表示Web服务器已经成功安装并运行。 3. 准备网页文件,将网页文件上传到服务器上。可以使用FTP工具、SCP命令等方式上传文件。上传的文件应存放在Web服务器的根目录下,通常是`/var/www/html/`。 4. 配置Web服务器,使其可以访问上传的网页文件。以Apache为例,可以编辑`/etc/apache2/sites-available/000-default.conf`文件,添加以下内容: ``` <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> ``` 然后,重新启动Apache服务: ``` sudo systemctl restart apache2 ``` 现在,可以在浏览器中输入服务器的IP地址或域名,加上文件名,即可访问上传的网页。 5. (可选)添加SSL证书,使网页支持HTTPS协议。可以使用Let's Encrypt等免费SSL证书提供商,也可以自行购买证书。以Let's Encrypt为例,可以使用certbot工具自动申请和安装证书,具体命令如下: ``` sudo apt-get update sudo apt-get install certbot python-certbot-apache sudo certbot --apache ``` 安装和配置完成后,可以在浏览器中输入`https://服务器IP地址`或`https://域名`,访问网页时将自动使用HTTPS协议。 至此,网页搭建流程已经完成,您可以通过浏览器访问网页并查看效果。如果需要更多功能,可以考虑使用数据库、编程语言等技术进行扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值