世界排名第一的web服务软件apache

时间:2024-03-14 20:08:08

1.什么是apache (Web服务器)?

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行
Apache是世界使用排名第一的Web服务器软件,它可以运行在几乎所有广泛使用的计算机平台上
由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一,也叫网页服务器软件 
它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中
同时Apache音译为阿帕奇,是北美印第安人的一个部落,叫阿帕奇族,在美国的西南部,也是一个基金会的名称、一种武装直升机等等

2.什么是http://协议?

HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写
是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议
HTTP是基于TCP/IP通信协议来传递数据(HTML 文件, 图片文件, 查询结果等)
HTTP是一个属于应用层的面向对象的协议,由于其简捷、快速的方式,适用于分布式超媒体信息系统
HTTP协议工作于客户端-服务端架构为上,浏览器作为HTTP客户端通过URL向HTTP服务端即WEB服务器发送所有请求
Web服务器根据接收到的请求后,向客户端发送响应信息

HTTP工作原理:
HTTP协议定义Web客户端如何从Web服务器请求Web页面,以及服务器如何把Web页面传送给客户端
HTTP协议采用了请求/响应模型。客户端向服务器发送一个请求报文,请求报文包含请求的方法、URL、协议版本、请求头部和请求数据
服务器以一个状态行作为响应,响应的内容包括协议的版本、成功或者错误代码、服务器信息、响应头部和响应数据。

以下是 HTTP 请求/响应的步骤:

1、客户端连接到Web服务器
一个HTTP客户端,通常是浏览器,与Web服务器的HTTP端口(默认为80)建立一个TCP套接字连接。例如,http://www.oakcms.cn。
2、发送HTTP请求
通过TCP套接字,客户端向Web服务器发送一个文本的请求报文,一个请求报文由请求行、请求头部、空行和请求数据4部分组成。
3、服务器接受请求并返回HTTP响应
Web服务器解析请求,定位请求资源。服务器将资源复本写到TCP套接字,由客户端读取。
一个响应由状态行、响应头部、空行和响应数据4部分组成。
4、释放连接TCP连接
若connection 模式为close,则服务器主动关闭TCP连接,客户端被动关闭连接,释放TCP连接;若connection 模式为keepalive,则该连接会保持一段时间,在该时间内可以继续接收请求;
5、客户端浏览器解析HTML内容
客户端浏览器首先解析状态行,查看表明请求是否成功的状态代码。然后解析每一个响应头,响应头告知以下为若干字节的HTML文档和文档的字符集。客户端浏览器读取响应数据HTML,根据HTML的语法对其进行格式化,并在浏览器窗口中显示。
其实也是把服务端的东西共享给客户端
协议的支撑 <------软件 <-----程序
协议是两个人共同商量好的东西
curl -I www.baidu.com 嗅探(查看这些网站的服务名字)
两大主流服务
lamp linux apache mysql php/perl/python
lnmp linux nginx mysql php/perl/python
客户端访问apache服务,然后加载php这个插件,然后调用mysql数据库
apchece ,企业中常用的web服务,用来提供http://(超文本传输协议)

3.apache的基础信息

主配置目录 /etc/httpd/conf
主配置文件 /etc/httpd/conf/httpd.conf
子配置目录 /etc/httpd/conf.d/
子配置文件 /etc/httpd/conf.d/*.conf
默认发布目录 /var/www/html
默认发布文件 index.html
默认端口 80
默认安全上下文 httpd_sys_content_t
程序开启默认用户 apache
apache日志 /etc/httpd/logs/*

4.搭建实验环境

(1)重置并且开启我的desktop虚拟机

rht-vmctl reset desktop
rht-vmctl start desktop
rht-vmctl view desktop

世界排名第一的web服务软件apache
(2)配置网络

cd /etc/sysconfig/network-scripts
ls
vim ifcg-eth0
systemctl restart network

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
(3)改主机名字

hostnamectl set-hostname apache_server.example.com

世界排名第一的web服务软件apache
(4)将selinux打开为enforcing,再reboot

apache服务,支持超文本传输的软件
selinux会影响apache,因此应该打开
遇到什么问题就就解决什么问题

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

5.在ip为172.25.254.111的这台虚拟机上搭建apache-web服务器

(1)配置本地yum源
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
(2)安装部署apache服务并且查看最基本的一些东西

yum search apache寻找安装包

世界排名第一的web服务软件apache

yum install httpd -y 安装apache软件

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

systemctl start httpd开启apache服务
systemctl enable httpd 开机启动

世界排名第一的web服务软件apache

netstat -antlupe | grep httpd(查看httpd的服务端口80是否开启)

世界排名第一的web服务软件apache

firewall-cmd --list-all				##列出火墙信息
firewall-cmd --permanent --add-service=http	##在火墙里面添加http服务   
firewall-cmd --reload				##重新加载使添加生效

世界排名第一的web服务软件apache

man 5 httpd.conf找不到
yum install httpd-manual	##apache的手册(在浏览器里面输入就可以看到)

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

cd /var/www/html(httpd安装了以后才会有这个共享目录)
ls
cd /etc/httpd/conf((主配置目录)
ls 
cd ..(返回上一级目录)
ls
cd conf.d(子配置目录)
ls

世界排名第一的web服务软件apache
rpm -qc httpd
世界排名第一的web服务软件apache
rpm -qd httpd
世界排名第一的web服务软件apache
rpm -ql httpd
世界排名第一的web服务软件apache
测试 http://172.25.254.100
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

/var/www/html			##apache的/目录,默认发布目录
/var/www/html/index.html	##apache的默认发布文件
vim /var/www/html/index.html
<h1> hello world </h1>
:wq

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

测试	http://172.25.254.100/manual
在浏览器里面输入我的apache浏览器的ip地址就能看到它共享出来的东西

世界排名第一的web服务软件apache

6.apache服务的相关设置

先systemctl status httpd查看apache是否开启
再firewall-cmd --list-all查看火墙是否允许apache服务
在浏览器里面输入172.25.254.111查看是否能访问apache共享出来的东西

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

vim /etc/vimrc随便在哪一行写入
set nu
wq 使vim显示行号

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
(1)修改httpd服务的端口

vim /etc/httpd/conf/httpd.conf
搜Listen 将端口由80改为8080
systemctl restart httpd

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
netstat -antlupe | grep httpd 查看端口是否改为8080
世界排名第一的web服务软件apache
输入172.25.254.111(相当于172.25.254.111:80)此时找不到
世界排名第一的web服务软件apache
输入172.25.254.111:8080此时还找不到
世界排名第一的web服务软件apache
此时selinux为enforcing
世界排名第一的web服务软件apache
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
世界排名第一的web服务软件apache
输入172.25.254.111:8080就可以了
世界排名第一的web服务软件apache
netstat -antlupe | grep 6666 查看6666端口是否被使用
世界排名第一的web服务软件apache

vim /etc/httpd/conf/httpd.conf
Listen 6666
systemctl restart httpd出现错误

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
setenforce 0
getenforce
世界排名第一的web服务软件apache
systemctl restart httpd 就可以了
世界排名第一的web服务软件apache
semanage port -l | grep http查看http服务可以使用的端口
世界排名第一的web服务软件apache
semanage port -a -t http_port_t -p tcp 6666
semanage port -l | grep http 再次查看http服务可以使用的端口
世界排名第一的web服务软件apache
getenforce
setenforce 1
getenforce
systemctl restart httpd
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
(2)修改默认发布文件

vim /etc/httpd/conf/httpd.conf
将端口改为80
为了接下来的实验方便
systemctl restart httpd

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

cd /var/www/html 默认发布目录
ls查看默认发布文件 index.html
vim test.html
<h1>test'page</h1>

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
直接172.25.254.111访问的是index.html(默认发布文件)
世界排名第一的web服务软件apache
输入172.25.254.111/test.html 才可以访问test.html
世界排名第一的web服务软件apache

vim /etc/httpd/conf/httpd.conf
搜index.html
改为test.html
systemctl restart httpd

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
输入172.25.254.111直接看到test.html的内容
世界排名第一的web服务软件apache

vim /etc/httpd/conf/httpd.conf
写入index.html test.html
systemctl restart httpd

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
172.25.254.111看到的是index.html
世界排名第一的web服务软件apache
mv index.html /mnt
世界排名第一的web服务软件apache
172.25.254.111看到的是test.html
世界排名第一的web服务软件apache
(3)修改默认发布目录

cd /var/www/html 默认发布目录
mkdir -p /westos/html
vim /westos/html/index.html

世界排名第一的web服务软件apache

/westos/html's page

![在这里插入图片描述](https://img-blog.csdnimg.cn/20190520184443928.png) ``` vim /etc/httpd/conf/httpd.conf 搜/Doc 复制一行,注释掉原来的 /var/www/html----->/westos/html systemctl restart httpd ```

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
输入172.25.254.111/index.html找不到
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
ll -d /westos/html/
ll /westos/html
setenforce 0
世界排名第一的web服务软件apache
vim /etc/httpd/conf/httpd.conf
加入:
<Directory “/westos/html”>
Require all granted

systemctl restart httpd
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
输入172.25.254.111/index.html可以了
世界排名第一的web服务软件apache
setenforce 1
输入172.25.254.111/index.html不可以
ls -Zd /var/www/html
ls -Zd /westos/html
世界排名第一的web服务软件apache
semanage fcontext -a -t httpd_sys_content_t ‘/westos/html(/.*)?’
restorecon -RvvF /westos/html
getenforce
输入172.25.254.111/index.html可以了
世界排名第一的web服务软件apache

世界排名第一的web服务软件apache

7.apache的虚拟主机(让一台apache主机有多个站点)

使news、music都有自己的默认发布目录和默认发布文件
但是一台主机一个站点太浪费资源了
我们在apache主机上搭建虚拟机主机
回去先使自己的真机可以上网
输入www.baidu.com
进去点击其它的,发现有很多域名
输入:www.qq.com
进去点击其它的,发现有很多域名
cd /etc/httpd/conf.d/  默认发布目录
ls
vim vhost.conf(主配置文件里面有要求,必须以.conf结尾)

世界排名第一的web服务软件apache

DocumentRoot /var/www/html
CustomLog logs(etc/httpd/logs)/default.log combined

世界排名第一的web服务软件apache
ll /etc/httpd/logs(日志的上一级目录)
世界排名第一的web服务软件apache
vim /etc/httpd/conf/httpd.conf(配置文件里面的要求)
systemctl restart httpd
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

发现输入www.westos.com news.westos.com music.westos.com均为/var/www/html这个默认发布目录下的发布文件里的信息
在真机里面vim /etc/hosts做本地解析
172.25.254.111 www.westos.com news.westos.com music.westos.com

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

发现输入www.westos.com news.westos.com music.westos.com均为/var/www/html这个默认发布目录下的发布文件里的信息
vim vhost.conf
cd
mkdir -p /var/www/vhost/news
mkdir -p /var/www/vhost/music
世界排名第一的web服务软件apache
vim /var/www/vhost/news/index.html

news's page

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

vim /var/www/vhost/music/index.html
<h1>music's page</h1>

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
cd /etc/httpd/conf.d/
ls
vim vhost.conf
世界排名第一的web服务软件apache

<VirtualHost_default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined

<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot /var/www/vhost/news
CustomLog logs/news.log combined

<Directory “/var/www/vhost/news”>
Require all granted

<VirtualHost *:80>
ServerName music.westos.com
DocumentRoot /var/www/vhost/music
CustomLog logs/music.log combined

<Directory “/var/www/vhost/music”>
Require all granted

systemctl restart httpd

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
发现输入www.westos.com news.westos.com music.westos.com
均是自己的东西
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

8.apache内部的访问控制(想让谁访问谁才能访问)

cd /etc/httpd/conf.d/
ls
vim vhost.conf
systemctl restart httpd
在浏览器里面测试即可

(1)针对主机ip的访问控制

基于ip的访问控制,允许哪个ip可以访问,哪个ip不可以访问
allow,deny会有一个读取的先后顺序,后面的会覆盖前面的,相当于设置访问apache服务器的黑白名单

<Directory “/var/www/html/test”>
Order Allow,Deny ##列表读取顺序,后读取的列表会覆盖前面列表内容的重复部分
Allow from All
Deny from 172.25.254.111
相当于黑名单
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
测试:在真机里面输入firefox,输入172.25.254.111可以查看
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
在111自己里面输入firefox,输入172.25.254.111不行
世界排名第一的web服务软件apache
<Directory “/var/www/html/test”>
Order Deny,Allow ##列表读取顺序,后读取的列表会覆盖前面列表内容的重复部分
Allow from 172.25.254.111
Deny from All
相当于白名单
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
测试:在真机里面输入firefox,输入172.25.254.111不行
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
在111自己里面输入firefox,输入172.25.254.111可以查看

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
(2)用户方式的访问控制
先建立用户认证文件
cd /etc/httpd/
ls
htpasswd --help查看参数的意思
世界排名第一的web服务软件apache
htpasswd -cm .apache_auth admin
输入密码
cat .apache_auth
htpasswd -cm .apache_auth lee
输入密码会覆盖之前的用户
htpasswd -m .apache_auth admin(追加用户在文件里面不需要-c)
输入密码
cat .apache_auth
htpasswd -cm /etc/httpd/userpass admin
htpasswd -m /etc/httpd/userpass admin1
世界排名第一的web服务软件apache
cd /etc/httpd/conf.d/
ls
vim vhost.conf
世界排名第一的web服务软件apache
10 <Directory “/var/www/html”>
11 AuthUserFile /etc/httpd/.apache_auth 认证文件类型
12 AuthType basic认证类型
13 AuthName "Please input username and password"认证名字
14 #Require user admin 只允许admin用户通过认证访问共享目录
15 Require valid-user允许所有用户访问
16
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
systemctl restart httpd
世界排名第一的web服务软件apache
ctrl+shift+delete 清空缓存(不同浏览器的方法不同)
在浏览器进行测试
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

8.apache支持的语言(html php cgi wsgi)

html php perl python jsp asp
(1)php语言的设置
cd /var/www/html
ls
世界排名第一的web服务软件apache
vim /etc/httpd/conf.d/vhost.conf注释掉上一个实验
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
systemctl restart httpd
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

在浏览器里面输入172.25.254.111 看是否正常
世界排名第一的web服务软件apache
vim index.php

<?php phpinfo(); ?>

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
vim /etc/httpd/conf/httpd.conf
世界排名第一的web服务软件apache

index.php加入这个默认发布文件
世界排名第一的web服务软件apache
systemctl restart httpd
世界排名第一的web服务软件apache
php test.html调用不存在
世界排名第一的web服务软件apache
yum insatll php -y安装这个服务
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
php index.php
世界排名第一的web服务软件apache
systemctl restart httpd
世界排名第一的web服务软件apache
cd /etc/httpd/conf.d/
ls
出现了php.conf
世界排名第一的web服务软件apache
在浏览器里面输入172.25.254.111就可以看到php的表格了
世界排名第一的web服务软件apache
(2)cgi语言的设置
172.25.254.111/manual/
选CGI查看粘贴东西
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
cd /var/www/html
ls
mkdir cgi
cd cgi/
ls
vim index.cgi写cgi的默认发布文件
世界排名第一的web服务软件apache
写入刚刚粘贴的东西
#!/usr/bin/perl
print “Content-type: text/html\n\n”;
print date;
世界排名第一的web服务软件apache
chmod +x index.cgi脚本要给一个可以执行的权限
./index.cgi可以看到时间调用脚本,看能否看到时间
世界排名第一的web服务软件apache
172.25.254.111/cgi/index.cgi
看到的是源代码
世界排名第一的web服务软件apache
172.25.254.111/manual/howto/cgi.html
复制
cd /etc/httpd/conf.d/
ls
vim vhost.conf
世界排名第一的web服务软件apache
写入:
17 <Directory “/var/www/html/cgi”>
18 Options +ExecCGI
19 AddHandler cgi-script .cgi
20
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

世界排名第一的web服务软件apache
systemctl restart httpd
世界排名第一的web服务软件apache
172.25.254.111/cgi/index.cgi报错
世界排名第一的web服务软件apache
getenforce
setenforce 0(关闭selinux)
世界排名第一的web服务软件apache
172.25.254.111/cgi/index.cgi显示时间
世界排名第一的web服务软件apache
setenforce 1(开启selinux)
世界排名第一的web服务软件apache
ls -Zd /var/www/html
semanager fcontext -a -t httpd_sys_script_exec_t '/var/www/html/cgi(/.*)?'更改安全上下文
restorecon -RvvF /var/www/html/cgi/加载使其生效
getenfoce
世界排名第一的web服务软件apache
172.25.254.111/cgi/index.cgi显示时间
以上是cgi的实验
世界排名第一的web服务软件apache
(3)wsgi语言的设置
cd /var/www/cgi-bin/
wget ftp://172.25.254.250:/pub/webapp.wsgi
ls
世界排名第一的web服务软件apache
pwd
vim webapp.wsgi
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
python webapp.wsgi不能调用脚本
世界排名第一的web服务软件apache
cd
yum search wsgi
世界排名第一的web服务软件apache
yum install mod 。。。。
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
systemctl restart httpd
世界排名第一的web服务软件apache
cd /etc/httpd/conf.d/
ls
vim vhost.conf
世界排名第一的web服务软件apache
写入:
<VirtualHost *:80>
ServerName wsgi.westos.com
WSGIScriptAlias / /var/www/cgi-bin/webapp.wsgi

systemctl restart httpd
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
做本地解析:
wsgi.westos.com
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
在浏览器输入:wsgi.westos.com
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

9.https加密访问

客户端访问服务器的时候客户端那边是不安全的
https协议是加密访问
在能上网的真机里面www.baidu.com
发现https://www.baidu.com

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache世界排名第一的web服务软件apache世界排名第一的web服务软件apache世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
锁需要开启443端口
netstat -antlupe | grep httpd
世界排名第一的web服务软件apache
我们需要在自己的apache服务器上面安装锁
yum install mod_ssl -y
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
cd /etc/httpd/conf.d/
ls
vim ssl.conf
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
systemctl restart httpd
世界排名第一的web服务软件apache
https://172.25.254.111 错误
世界排名第一的web服务软件apache
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
世界排名第一的web服务软件apache
https://172.25.254.111 错误
世界排名第一的web服务软件apache
删除默认给的锁
yum install crypto-utils -y
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
genkey --help
世界排名第一的web服务软件apache
genkey apache_server.westos.com 生成自己的锁和钥匙
世界排名第一的web服务软件apache
填完信息之后就会生成钥匙和密码
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
cd /etc/httpd/conf.d/
ls
vim ssl.conf
世界排名第一的web服务软件apache
写入自己的钥匙和密码
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
systemctl restart httpd
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
https://172.25.254.111
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

10.设定https虚拟主机并设定网页重写

怎样让客户在自己的浏览器中输入172.25.254.111(80端口)时自动跳转为https://172.25.254.111(443端口)

cd /etc/httpd/conf.d/
ls
vim vhost_https.conf写入:(名字任意,以.conf结尾就行)
世界排名第一的web服务软件apache
1 <VirtualHost *:443>建立一个443端口虚拟主机
2 ServerName login.westos.com
3 DocumentRoot /var/www/vhost/login建立默认发布目录
4 CustomLog logs/login.log combined
世界排名第一的web服务软件apache
用真机ssh [email protected]
cd /etc/httpd/conf.d/
ls
vim ssl.conf
复制一些东西

5 SSLEngine on开启这个功能
6 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt钥匙
7 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key锁
8

9 <Directory “/var/www/html/vhost/login”>授权
10 Require all granted
11
mkdir -p /var/www/vhost/login建立默认发布目录
vim /var/www/vhost/login/index.html建立默认发布文件

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

login.westos.com's page

世界排名第一的web服务软件apache
systemctl restart httpd
世界排名第一的web服务软件apache
做本地解析:(浏览器在哪在就哪做本地解析)
vim /etc/hosts

世界排名第一的web服务软件apache
加入 login.westos.com
世界排名第一的web服务软件apache

测试:
在真机输入:https://login.westos.com可以 但输入login.westos.com不会自动到 https://login.westos.com

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
输入172.25.254.111/manual
选URL
查看网页重写的要求
世界排名第一的web服务软件apache
12 <VirtualHost :80>建立一个80端口的虚拟主机
13 ServerName login.westos.com
14 RewriteEngine on 将网页重写的功能开启
15 RewriteRule ^(/.
)$ https://%{HTTP_HOST}$1 [redirect=301](永久重定向:永久跳转)
客户端输入的内容 客户端主机
16
systemctl restart httpd
世界排名第一的web服务软件apache
世界排名第一的web服务软件apache
测试:输入login.westos.com------>https://login.westos.com 成功

世界排名第一的web服务软件apache
世界排名第一的web服务软件apache

^(/.*)$ 客户在浏览器地址栏中输入的所有字符
https:// 强制客户加密访问
%{HTTP_HOST} 客户请求主机
$1 "1&quot;(/.)1&quot;表示 ^(/.*)的值
[redirect=301] 永久重写,302临时