Linux 搭建APache http_ssl(https)

简介:

 搭建APache http_ssl(https)


网站服务器(192.168.4.3)

1 网站服务器配置

运行网站服务 并编写网页文件 index.html

[root@WEB ~]# yum -y install httpd

[root@WEB ~]# echo www.test.com > /var/www/html/index.html

[root@WEB ~]# systemctl start httpd

[root@WEB ~]# systemctl stop firewalld

[root@WEB ~]# netstat -pantu | grep httpd

tcp6       0      0 :::80                   :::*                    LISTEN      6016/httpd    

客户端访问网站服务器

[root@test ~]# vim /etc/hosts

[root@test ~]# sed -n '3p' /etc/hosts

192.168.4.3 www.test.com

[root@test ~]# ping -c 2 www.test.com

PING www.test.com (192.168.4.3) 56(84) bytes of data.

64 bytes from www.test.com (192.168.4.3): icmp_seq=1 ttl=64 time=0.769 ms

64 bytes from www.test.com (192.168.4.3): icmp_seq=2 ttl=64 time=0.360 ms


客户端测试

[root@test ~]# firefox http://www.test.com


2 创建私钥文件 web.key

[root@WEB ~]# cd /etc/pki/tls/private/

[root@WEB private]# openssl genrsa 2048 > web.key


3 创建证书请求文件 web.csr

[root@WEB private]# openssl req -new -key web.key > /root/web.csr

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]:CN

State or Province Name (full name) []:beijing

Locality Name (eg, city) [Default City]:beijing

Organization Name (eg, company) [Default Company Ltd]:Xuenqlve

Organizational Unit Name (eg, section) []:ope

Common Name (eg, your name or your server's hostname) []:www.test.com

Email Address []:Xuenqlve@163.com


Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:


4 上传证书请求文件给CA服务器 (192.168.4.1)

[root@WEB private]# scp /root/web.csr 192.168.4.1:/root/



CA服务器 (192.168.4.1)

            CA服务器具体配置 http://blog.51cto.com/13558754/2057718

5 审核证书请求文件,并签发数字证书

[root@CA certs]# openssl ca -in /root/web.csr > web.crt

Using configuration from /etc/pki/tls/openssl.cnf

Enter pass phrase for /etc/pki/CA/private/my-ca.key:

Check that the request matches the signature

Signature ok

Certificate Details:

        Serial Number: 2 (0x2)

        Validity

            Not Before: Jan  5 05:15:56 2018 GMT

            Not After : Jan  5 05:15:56 2019 GMT

        Subject:

            countryName               = CN

            stateOrProvinceName       = beijing

            organizationName          = Xuenqlve

            organizationalUnitName    = ope

            commonName                = www.test.com

            emailAddress              = Xuenqlve@163.com

        X509v3 extensions:

            X509v3 Basic Constraints: 

                CA:FALSE

            Netscape Comment: 

                OpenSSL Generated Certificate

            X509v3 Subject Key Identifier: 

                85:43:06:A3:7E:41:E5:15:AC:2C:ED:80:81:37:FE:BD:5F:5F:A1:8C

            X509v3 Authority Key Identifier: 

                keyid:87:06:18:98:79:53:0E:26:0A:91:2D:B9:93:8A:C3:86:2B:CC:DF:E7


Certificate is to be certified until Jan  5 05:15:56 2019 GMT (365 days)

Sign the certificate? [y/n]:y



1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated



[root@CA certs]# cat ../index.txt

V190105051556Z01unknown/C=CN/ST=beijing/O=Xuenqlve/OU=ope/CN=www.test.com/emailAddress=Xuenqlve@163.com

[root@CA certs]# cat ../serial

02


6 下发证书给网站服务器(192.168.4.3)

[root@CA certs]# scp web.crt 192.168.4.3:/tmp/





7 配置服务运行时调用私钥文件和数字证书文件

[root@WEB ~]# yum -y install mod_ssl.x86_64

[root@WEB ~]# vim /etc/httpd/conf.d/ssl.conf 

[root@WEB ~]# sed -n '100p;107p' /etc/httpd/conf.d/ssl.conf

SSLCertificateFile /etc/pki/tls/certs/web.crt

SSLCertificateKeyFile /etc/pki/tls/private/web.key

[root@WEB ~]# cp /tmp/web.crt /etc/pki/tls/certs/web.crt

[root@WEB ~]# systemctl restart httpd

[root@WEB ~]# netstat -pantu | grep httpd

tcp6       0      0 :::80                   :::*                    LISTEN      6459/httpd          

tcp6       0      0 :::443                  :::*                    LISTEN      6459/httpd   

客户端进行测试

[root@test ~]# firefox https://www.test.com

https1.jpg

单击'我已充分了解可能风险' ----> 单击 '添加例外' 


https2.jpg

单击'确认安全例外'

https3.jpg


然后就可以看见网页可以正常访问

https4.jpg

在证书管理 --- 服务器  会添加此次访问例外

https7.jpg

这是一种临时的方法 




8.下载并安装根证书

[root@test ~]# wget http://192.168.4.1/ca/my-ca.crt

--2018-01-05 01:15:07--  http://192.168.4.1/ca/my-ca.crt

正在连接 192.168.4.1:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:1424 (1.4K)

正在保存至: “my-ca.crt”


100%[===================================================================>] 1,424       --.-K/s 用时 0s      


2018-01-05 01:15:07 (66.0 MB/s) - 已保存 “my-ca.crt” [1424/1424])

在浏览器中添加证书可信  具体添加步骤见 http://blog.51cto.com/13558754/2057718

查看证书具体信息


https5.jpg


https6.jpg



9.修改配置文件 使得当用户访问http时 自动跳转到https

[root@WEB certs]# vim /etc/httpd/conf/httpd.conf 

[root@WEB certs]# tail -7 /etc/httpd/conf/httpd.conf

<IfModule ssl_module>

    SSLRandomSeed  startup  builtin

    SSLRandomSeed  connect  builtin

</IfModule>

RewriteEngine  on#启用模块

RewriteCond  %{SERVER_PORT}  !^443$#当变量SERVER_PORT 不是 443时 

RewriteRule  (.*)  https://%{SERVER_NAME}/$1  [R]#将访问网站url 跳转为https: 










本文转自 Xuenqlve 51CTO博客,原文链接:http://blog.51cto.com/13558754/2057837,如需转载请自行联系原作者
目录
相关文章
|
9天前
|
关系型数据库 MySQL Linux
查看Linux、Apache、MySQL、PHP版本的技巧
以上就是查看Linux、Apache、MySQL、PHP版本信息的方法。希望这些信息能帮助你更好地理解和使用你的LAMP技术栈。
61 17
|
3月前
|
网络协议 算法 数据建模
IP 地址,包括 IPv6 怎么申请 SSL证书来实现 https
很多企业单位已经开始在使用 IPv6 资源,跟 IPv4 一样,IPv6也是需要SSL证书的。在目前的SSL证书品牌,KeepTrust 是可以支持 IPv6 地址的。跟普通IP地址一样,给IPv6签发SSL证书也是需要验证申请者对 IP 地址的管理权限的。如果是 OV 版,还需要验证组织信息的真实性。
|
5月前
|
Dubbo 安全 应用服务中间件
Apache Dubbo 正式发布 HTTP/3 版本 RPC 协议,弱网效率提升 6 倍
在 Apache Dubbo 3.3.0 版本之后,官方推出了全新升级的 Triple X 协议,全面支持 HTTP/1、HTTP/2 和 HTTP/3 协议。本文将围绕 Triple 协议对 HTTP/3 的支持进行详细阐述,包括其设计目标、实际应用案例、性能测试结果以及源码架构分析等内容。
381 26
|
4月前
|
应用服务中间件 Linux 网络安全
nginx安装部署ssl证书,同时支持http与https方式访问
为了使HTTP服务支持HTTPS访问,需生成并安装SSL证书,并确保Nginx支持SSL模块。首先,在`/usr/local/nginx`目录下生成RSA密钥、证书申请文件及自签名证书。接着,确认Nginx已安装SSL模块,若未安装则重新编译Nginx加入该模块。最后,编辑`nginx.conf`配置文件,启用并配置HTTPS服务器部分,指定证书路径和监听端口(如20000),保存后重启Nginx完成部署。
1750 8
|
5月前
|
安全 网络协议 应用服务中间件
内网ip申请SSL证书实现https访问
内网IP地址虽不能直接申请公网SSL证书,但可通过IP SSL证书保障数据安全。流程包括:确定固定内网IP,选择支持内网IP的CA,注册申请证书,生成CSR,验证IP所有权,下载部署证书至Web服务器,测试HTTPS访问,确保配置正确及证书有效。此方法适用于内网环境,提升数据传输安全性。
内网ip申请SSL证书实现https访问
|
5月前
|
安全 应用服务中间件 网络安全
49.3k star,本地 SSL 证书生成神器,轻松解决 HTTPS 配置痛点
mkcert是一款由Filippo Valsorda开发的免费开源工具,专为生成受信任的本地SSL/TLS证书而设计。它通过简单的命令自动生成并安装本地信任的证书,使本地环境中的HTTPS配置变得轻松无比。mkcert支持多个操作系统,已获得49.2K的GitHub Star,成为开发者首选的本地SSL工具。
315 10
|
5月前
|
存储 网络安全
Curl error (60): SSL peer certificate or SSH remote key was not OK for https://update.cs2c.com.cn/NS/V10/V10SP2/os/adv/lic/base/x86_64/repodata/repomd.xml [SSL: no alternative certificate subject name matches target host name 'update.cs2c.com.cn']
【10月更文挑战第30天】在尝试从麒麟软件仓库(ks10-adv-os)下载元数据时,遇到 SSL 证书验证问题。错误提示为:`Curl error (60): SSL peer certificate or SSH remote key was not OK`。可能原因包括证书不被信任、证书与域名不匹配或网络问题。解决方法包括检查网络连接、导入 SSL 证书、禁用 SSL 证书验证(不推荐)、联系仓库管理员、检查系统时间和尝试其他镜像。
1567 1
|
5月前
|
安全 数据建模 应用服务中间件
如何给IP地址添加SSL证书(https)
为IP地址配置SSL证书实现HTTPS访问,需拥有固定公网IP,选择支持IP证书的CA,完成账户注册、证书申请、所有权验证及证书安装。验证过程涉及在服务器上放置特定文件,确保可访问。安装后需测试连接,注意兼容性和安全性,定期维护证书。
|
8月前
|
缓存 NoSQL Linux
【Azure Redis 缓存】Linux VM使用6380端口(SSL方式)连接Azure Redis (redis-cli & stunnel)
【Azure Redis 缓存】Linux VM使用6380端口(SSL方式)连接Azure Redis (redis-cli & stunnel)
157 0
|
8月前
|
Linux Apache
在Linux中,apache有几种工作模式,分别介绍下其特点,并说明什么情况下采用不同的工作模式?
在Linux中,apache有几种工作模式,分别介绍下其特点,并说明什么情况下采用不同的工作模式?
下一篇
oss创建bucket