搭建基于https的网站

本文详细指导如何在Linux服务器上配置Apache并安装SSL模块,生成自签名证书,设置虚拟主机,实现www.zuoye.com的HTTPS访问。包括步骤如生成私钥、证书、关闭防火墙、编辑配置文件及调整主机文件,最终完成网站部署和测试。
摘要由CSDN通过智能技术生成

要求:搭建一个基于https://www.zuoye.com访问的web网站,网站首页在/www/https/,内容为exercise。

https的服务,私钥及证书

[root@server1 ~]# yum -y install httpd
[root@server1 ~]# yum -y install mod_ssl

#生成私钥和证书:
[root@server1 ~]# cd /etc/pki/tls/certs/                                #配置文件
[root@server1 certs]# openssl genrsa -aes128 2048 > czc.key                      #生成私钥
[root@server1 certs]# openssl req -utf8 -new -key czc.key -x509 -days 365 -out czc.crt	  #生成证书

Enter pass phrase for czc.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:86
State or Province Name (full name) []:sc
Locality Name (eg, city) [Default City]:cd
Organization Name (eg, company) [Default Company Ltd]:open
Organizational Unit Name (eg, section) []:ce
Common Name (eg, your name or your server's hostname) []:www.zuoye.com
Email Address []:admin@admin 

[root@server1 certs]# ll
total 8
lrwxrwxrwx. 1 root root   49 Jun 17  2021 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx. 1 root root   55 Jun 17  2021 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rw-r--r--. 1 root root 1261 Nov 23 23:41 czc.crt
-rw-r--r--. 1 root root 1766 Nov 23 23:39 czc.key

关闭防火墙及SELinux

[root@server1 certs]# systemctl stop firewalld.service
[root@server1 certs]# setenforce 0

创建目录并编写网页内容

[root@server1 ~]# mkdir -pv /www/https
[root@server1 ~]# echo "exercise" > /www/https/index.html

编写配置文件

[root@server1 ~]# cd /etc/httpd/conf.d/
[root@server1 conf.d]# vim zuoye.conf

<Directory /www/https>
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<VirtualHost 192.168.210.11:443>      
    DocumentRoot "/www/https"
    ServerName  www.zuoye.com
    ErrorLog "/var/log/httpd/zuoye_error_log"
    CustomLog "/var/log/httpd/zuoye_access_log" common
    SSLEngine on
        sslcertificatefile /etc/pki/tls/certs/czc.crt
        sslcertificatekeyfile /etc/pki/tls/certs/czc.key
</VirtualHost>

[root@server1 conf.d]# systemctl restart httpd           #重启httpd服务

虚拟机和Windows主机的配置

虚拟机:

[root@server1  ~]# vim /etc/hosts
192.168.210.11 www.zuoye.com

主机文件路径:C:\Windows\System32\drivers\etc\hosts

注意:前面不能有“#”
在这里插入图片描述

最终测试:

https://www.zuoye.com/
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值