APACHE服务
Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。
Apache HTTP服务器是一个模块化的服务器,源于NCSAhttpd服务器,经过多次修改,成为世界使用排名第一的Web服务器软件。
它可以运行在几乎所有广泛使用的计算机平台上。
HTTP协议
超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议。所有的WWW文件都必须遵守这个标准。
一、搭建web服务
yum install httpd -y 安装
yum install httpd-manual -y 手册
systemctl start httpd 启动
systemctl enable httpd
firewall-cmd --permanent --add-service=http 防火墙允许
firewall-cmd --permanent --add-service=https
firewall-cmd --reload 重新加载策略
firewall-cmd --list-all
添加发布信息
cd /var/www/html/
vim index.html
添加:hello westos 测试
真机访问:http://172.25.254.138
二、修改默认端口
vim /etc/httpd/conf/httpd.conf
修改
systemctl restart httpd
firewall-config
添加
systemctl restart firewalld.service
firewall-cmd --list-all
semanage port -l | grep http 查看端口
semanage port -a -t http_port_t -p tcp 6666 添加端口
测试:http://172.25.54.138:8080
三、修改默认发布文件
编辑主配置文件
vim /etc/httpd/conf/httpd.conf
添加至
164 DirectoryIndex westos.html index.html 有访问顺序
新建文件和目录
mkdir /westos/web/html -p
vim /westos/web/html/westos.html
添加
123 mtr
修改默认发布目录:
vim /etc/httpd/conf/httpd.conf
注释默认添加
#DocumentRoot "/var/www/html"
DocumentRoot "/westos/web/html"
<Directory "/westos/web/html"> 默认发布目录
Require all granted 提供所有权限
</Directory>
semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'
restorecon -RvvF /westos/
重起服务(端口修改回80)
systemctl restart httpd.service
测试
四、虚拟主机
虚拟主机(Virtual Host),又称虚拟服务器、主机空间或是网页空间,是一种网络技术,可以让多个主机名称,在一个单一的服务器上运作,而且可以分开支持每个单一的主机名称。虚拟主机可以运行多个网站或服务。虚拟并非指不存在,而是指空间是由实体的服务器延伸而来,其硬件系统可以是基于服务器群,或者单个服务器。其技术是互联网服务器采用的节省服务器硬件成本的技术,虚拟主机技术主要应用于HTTP、FTP、EMAIL等多项服务,将一台服务器的某项或者全部服务内容逻辑划分为多个服务段位,对外表现为多个服务器,从而充分利用服务器硬件资源。
——Wiki中对虚拟主机的解释。
1、新建编辑配置文件
cd /etc/httpd/conf.d
vim a_default.conf
添加
<Virtualhost _default_:80>
DocumentRoot /var/www/html 读取的文件
CustomLog logs/default.log combined 采集所有日至
</Virtualhost>
systemctl restart httpd.service
2、添加虚拟主机配置文件
vim news.conf
添加
<Virtualhost *:80>
ServerName news.westos.com 访问的域名
DocumentRoot /var/www/westos.com/news/html 访问域名读取的文件
CustomLog logs/news.log combined 采集所有日至
logs相当于/etc/httpd/logs,子配置文件的默认目录
</Virtualhost>
<Directory "/var/www/westos.com/news/html">
Require all granted 给目录授权
</Directory>
cp news.conf music.conf
vim music.conf
测试主机修改解析文件
测试
www主机
news主机
music主机
五、控制访问
IP控制
cd /etc/httpd/conf.d
编辑
vim a_default.conf
添加:
<Virtualhost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</Virtualhost>
《一》
<Directory "/var/www/html">
Order Allow,Deny
Allow from all
Deny From 172.25.254.74
</Directory>
重起测试
《二》
<Directory "/var/www/html">
Order Deny,Allow 先看deny
Allow from 172.25.254.74 允许74访问,后便空格添加其他主机
Deny From all
</Directory>
重起测试
2、帐号密码控制
添加帐号
htpasswd -cm http_userlist admin
htpasswd -m http_userlist admin1 添加第二个不能有‘c’否则把原有覆盖
vim a_default.conf
添加
<Virtualhost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</Virtualhost>
<Directory "/var/www/html">
AuthUserFile /etc/httpd/conf.d/http_userlist 用户认证文件
AuthName "Please input username and password !!" 网页提示输入用户名和密码
AuthType basic 认证方式是最基础的认证
Require user admin 允许的用户
# Require valid-user 允许所有用户
</Directory>
测试
六、HTTPS
HTTPS(全称:Hyper Text Transfer Protocol over Secure SocketLayer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。
它是一个URI scheme(抽象标识符体系),句法类同http:体系。用于安全的HTTP数据传输。https:URL表明它使用了HTTP,但HTTPS存在不同于HTTP的默认端口及一个加密/身份验证层(在HTTP与TCP之间)。这个系统的最初研发由网景公司(Netscape)进行,并内置于其浏览器Netscape Navigator中,提供了身份验证与加密通讯方法。现在它被广泛用于万维网上安全敏感的通讯,例如交易支付方面。
1、安装需要的软件
2、进入目录生成加密文件
cd /etc/httpd/conf.d
genkey www.westos.com
执行名令后会出现窗口选项
1、
2、选1024位
3、确定后加载
4、加载后会出现加密,需要在加密主机shell按键盘
5、证书不发送
6、添加国家、地区、组织等
7、回车完成
3、编辑配置文件
vim /etc/httpd/conf.d/ssl.conf
修改(上面生成)
100 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
107 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
重起服务
systemctl restart httpd.service
网页测试
点击理解分险,在点击添加
会出现页面
点击锁子->第一行右边的箭头->More Information->,查看证书
七、指定文件加密
1、新建访问信息
cd /var/www/
mkdir westos.com/login/html -p
vim mkdir westos.com/login/html/index.html
添加:
<h1>login's page</h1>
2、新建访问策略
cd /etc/httpd/conf.d/
cp news.conf login.conf
vim login.conf
添加:
<Virtualhost *:443>
ServerName login.westos.com
DocumentRoot /var/www/westos.com/login/html
CustomLog logs/login.log combined
SSLengine on
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</Virtualhost>
<Directory "/var/www/westos.com/login/html">
Require all granted
</Directory>
<Virtualhost *:80>
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
3、重起服务
4、测试主机添加解析
vim /etc/hosts
5、测试