Linux 搭建APache http_ssl(https)

 搭建APache http_ssl(https)

网站服务器(192.168.4.3)

1 网站服务器配置

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

[[email protected] ~]# yum -y install httpd

[[email protected] ~]# echo www.test.com > /var/www/html/index.html

[[email protected] ~]# systemctl start httpd

[[email protected] ~]# systemctl stop firewalld

[[email protected] ~]# netstat -pantu | grep httpd

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

客户端访问网站服务器

[[email protected] ~]# vim /etc/hosts

[[email protected] ~]# sed -n '3p' /etc/hosts

192.168.4.3 www.test.com

[[email protected] ~]# 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

客户端测试

[[email protected] ~]# firefox http://www.test.com

2 创建私钥文件 web.key

[[email protected] ~]# cd /etc/pki/tls/private/

[[email protected] private]# openssl genrsa 2048 > web.key

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

[[email protected] 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 []:[email protected]

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)

[[email protected] private]# scp /root/web.csr 192.168.4.1:/root/

CA服务器 (192.168.4.1)

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

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

[[email protected] 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              = [email protected]

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

[[email protected] certs]# cat ../index.txt

V190105051556Z01unknown/C=CN/ST=beijing/O=Xuenqlve/OU=ope/CN=www.test.com/[email protected]

[[email protected] certs]# cat ../serial

02

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

[[email protected] certs]# scp web.crt 192.168.4.3:/tmp/

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

[[email protected] ~]# yum -y install mod_ssl.x86_64

[[email protected] ~]# vim /etc/httpd/conf.d/ssl.conf

[[email protected] ~]# sed -n '100p;107p' /etc/httpd/conf.d/ssl.conf

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

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

[[email protected] ~]# systemctl restart httpd

[[email protected] ~]# netstat -pantu | grep httpd

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

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

客户端进行测试

[[email protected] ~]# firefox https://www.test.com

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

单击'确认安全例外'

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

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

这是一种临时的方法

8.下载并安装根证书

[[email protected] ~]# 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

查看证书具体信息

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

[[email protected] certs]# vim /etc/httpd/conf/httpd.conf

[[email protected] 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:

原文地址:http://blog.51cto.com/13558754/2057837

时间: 2024-08-30 04:44:53

Linux 搭建APache http_ssl(https)的相关文章

linux架构学习第二十六天之web服务搭建(apache)以及https的实现

内容: 1.httpd版本以及安装 2.httpd的配置文件详解 3.httpd的用户身份验证实现 4.httpd的虚拟主机的实现 5.https的通信过程以及实现演示 1.httpd版本以及安装 centos默认的httpd版本是2.2,而centos默认的httpd版本是2.4,这里演示的是centos6的httpd-2.2版本 安装的方式有两种,一个是rpm包安装,一个是编译安装,编译安装相关的配置文件需要手动设置,这里演示的是rpm包安装 httpd2.2和2.4的区别: 2.2的MPM

Linux 搭建Apache服务个人静态页面

(1)把镜像挂载到/media/cdrom(2)配置Yum源文件(3)安装Apache服务程序httpd(4)开始httpd服务,并设置成开机自启(5)在浏览器输入?http://127.0.0.1?就可以看到web的默认页面(6)vi /etc/httpd/conf.d/userdir.conf在userdir.conf文件中注释掉UserDir disabled 去掉注释UserDir public_html(7)在用户家目录中创建public_html 在public_html中创建ind

基于Linux搭建Apache网站服务配置详解

Apache作为一款开源软件,是广泛应用的web应用之一,Apache有两个主要版本1.X和2.X,一般我们使用2.X版本,比起1.X版本它支持很多新的功能,下载Apache源码包的地址为:https://httpd.apache.org ,下载到源码包后开始准备安装: 1.为避免发生端口冲突,程序冲突等问题,如果有rpm方式安装的httpd服务,建议将其卸载. 2.挂载系统镜像,切换至系统盘中的Packages目录,安装相关依赖包(注意,最好一个一个的依次安装,因为如果有些安装包已经安装了,一

基于Linux搭建apache服务后,怎么构建web虚拟主机?

虚拟web主机指的是在同一台服务器中运行多个web站点,其中的每个站点实际上并不独立占用整个服务器,因此被称为"虚拟"web主机,通过虚拟web主机服务可以充分利用服务器的硬件资源. 使用httpd可以非常方便的去搭建虚拟主机服务器,只需要运行一个httpd服务就能够同时支撑大量的web站点.httpd支持的虚拟主机类型有这么三种(与Windows 的IIS服务一样): 1.相同IP.端口号.不同域名的虚拟主机: 2.相同IP.不同端口号的虚拟主机: 3.不同IP.相同端口号的虚拟主机

一步一步实现linux系统apache实现https详解

https提供安全的web通讯原理部分:http://stlong.blog.51cto.com/5144113/1730771 1)配置域名支持ca:[[email protected] ~]# vim /var/named/chroot/var/named/sggfu.com.zone  ##添加ca主机记录ca    IN    A    192.18.100.151:wq[[email protected] ~]# /etc/init.d/named restart  ##重启服务[[e

Linux搭建apache +PHP(CentOS系统)

1.安装MySQL bash # sudo yum install mysql-server  (下载mysql) bash # service mysqld start (开启mysql服务) bash # mysqladmin -u root password "123456" (设置mysql密码 初始为空) bash # chkconfig mysqld on   (开机自启) 2.下载httpd bash # yum -y install httpd (下载httpd并安装)

linux 搭建https 服务器 (apache)

一.  安装准备 1.    安装Openssl 要使Apache支持SSL,需要首先安装Openssl支持.这里使用的是openssl-0.9.8k.tar.gz 下载Openssl:http://www.openssl.org/source/ tar -zxf openssl-0.9.8k.tar.gz    //解压安装包 cd openssl-0.9.8k                 //进入已经解压的安装包 ./config                          //配

Linux之apache服务搭建

WEB服务器的架设,在linux有一个很著名的架构叫lamp:linux+apache+mysql+php,就知道apache的分量了. 在搭建apache服务钱需要做DNS服务器 DNS的搭建http://wt7315.blog.51cto.com/10319657/1852795 http的详解http://wt7315.blog.51cto.com/10319657/1837595 apache 后台进程:httpd 脚本:/etc/rc.d/init.d/httpd 使用端口:80(ht

linux下apache服务搭建

实验拓扑:                          Linux Client -----RHEL5.9(vmnet1)----------(vmnet1)                          Win7 Client 实验一:查看默认HTTP配置     找到默认红帽欢迎页面 (/etc/httpd/conf/httpd.conf ---->Include ----> /etc/httpd/conf.d  ----> welcome.conf  ----> /