1.apache
企业中常用的web服务 ,用来提供http://(超文本传输协议)
2.apache的安装部署
yum install httpd -y ##apache软件
yum install httpd-manual -y ##apache的手册
systemctl start httpd ##启动apache
systemctl enable httpd ##授予权限
firewall-cmd --list-all ##列出火墙信息
firewall-cmd --permanent --add-service=http ##永久允许http
firewall-cmd --reload ##火墙重新加载策略
/var/www/html ##apache的/ 目录 ,默认发布目录
/var/www/html/index.html ##apache的默认发布文件
测试 http://IP/index.html ##本机IP
# http://IP/manual 查看手册
3.apache的基础信息
主配置目录 : /etc/httpd/conf
主配置文件 : /etc/httpd/conf/httpd.conf
子配置目录 : /etc/httpd/conf.d
子配置文件 : /etc/httpd/conf.d/*.conf
默认端口 : 80
默认安全上下文 : httpd_sys_content_t
默认开启默认用户 :apache
apache日志 :/etc/httpd/logs/*
修改默认端口
vim /etc/httpd/conf/httpd.conf
43 Listen 8080 ##修改默认端口为 8080
systemctl restart httpd ##重启服务
ss -antlupe | grep httpd ##查看端口信息
firewall-cmd --permanent --add-port=8080/tcp ## 火墙允许该端口链接
修改默认发布文件
默认发布文件就是访问apache时没有指定文件名称时默认访问的文件
这个文件可以指定多个 ,有顺序
vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex index.html test.html ##当index.html不存在时访问test.html
修改默认发布目录
120 DocumentRoot "/www/html" ## mkdir -p /westos/html 在这个目录下的index.html文件
121<Diretory "/www">
Require all granted
</Diretory>
若你的内核火墙为enforcing
semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?'
rstorecon -RvvF /www/
4.apache 的虚拟主机
vim /etc/httpd/conf.d/apefault.conf
5.apache内部的访问机制
1.针对与主机的访问控制
mkdir /var/www/html/mxw/index.html ##在默认发布目录下在加一个目录mxw (配置文件中很多是允许默认发布目录的自由访问)
<Directory "/var/www/html/mxw"> ##
Order deny,allow ##列表读取顺序,后读取的列表会覆盖限度区内容的重复
allow from IP ##允许所有进入
Denf from all ##只允许设定的IP 进入
2.用户方式的访问控制
htpasswd -cm /etc/httpd/userpass mxw ##创建用户名和密码
htpasswd -m /etc/httpd/userpass admin ##若 -cm 会覆盖前面的用户 (c=creat m=)
[root@apache ~]# cat /etc/httpd/webuser
mxw:$apr1$/IXay/Tn$RSWGfmN9/zI81a9s4zf6g/
119 DocumentRoot "/var/www/html"
120
121 <Directory "/var/www/html/mxw">
122 #Require all granted ##允许任何人
123 AuthUserfile /etc/httpd/webuser ## webuser存放用户名和密码
124 AuthName "Please input username and passwd!!!!"
125 AuthType basic ##最基础的密码访问机制
126 #Require user admin ##允许指定用户
127 Require valid-user ##需要用户名和密码
128 </Directory>
##本地解析
1.vim /etc/hosts ##查看本地域名 并添加该IP的子域名()
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.254.254 classroom.example.com
172.25.254.254 content.example.com
172.25.254.102 www.westos.com news.westos.com mxw.westos.com ##添加子域名
~
2.cd /etc/httpd/conf.d ##cd 到http 的配置目录
vim /var/www/html/index.html ##编辑默认主页显示的内容
<center><font size=80 color=bule > buring </font></center>
mkdir /var/www/virutal/news.westos.com/html -p ##先创建目录
mkdir /var/www/virutal/mxw.westos.com/html -p
vim /var/www/virutal/news.westos.com/html/index.html
<font size=18 color=red>news.westos.com</font> ##编辑news主页内容
vim /var/www/virutal/mxw.westos.com/html/index.html
<font size=18 color=red>mxw.westos.com</font> ##编辑mxw主页内容
--------------------------------------------------------------------------
vim a_default.conf ##编辑默认域名的www.配置文件
<VirtualHost _default_ :80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</VirtualHost>
---------------------------------------------------------------------------
vim news.conf ##### 编辑子域名news的配置文件
<VirtualHost *:80>`这里写代码片`
ServerName news.westos.com
DocumentRoot /var/www/virutal/news.westos.com/html
CustomLog logs/news.log combined
</VirtualHost>
<Directory "/var/www/virutal/news.westos.com/html"> ###
Require all granted
</Directory>##
~
----------------------------------------------------------------------------
vim mxw.conf ##### 编辑子域名mxw的配置文件
<VirtualHost *:80> ##
ServerName mxw.westos.com
DocumentRoot /var/www/virutal/mxw.westos.com/html
CustomLog logs/news.log combined ##
</VirtualHost>
<Directory "/var/www/virutal/mxw.westos.com/html"> ##
Require all granted
</Directory>
systemctl restart httpd ##重启服务
测试
默认的是 vim a_default.com 这个配置文件域名的内容 (按字母排序,a是第一个)
news.westos.com
mxw.westos.com
6.用apache 访问 cgi php
cgi
mkdir /var/www/html/cgi ##在默认发布目录下创建一个cgi目录
vim /var/www/html/cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";
vim /etc/httpd/conf.d/a_default.conf ##将默认的配置文件修改为cgi的
<VirtualHost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</VirtualHost>
<Directory /var/www/html/cgi>
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
php
vim /etc/www/html/index.php
<?php
phpinfo();
?>
7.https服务
yum install mod_ssl -y ##安装https软件
firewall-cmd --permanent --add-service=https ##火墙永久允许https
firewall-cmd --reload ##火墙重新加载策略
firewall-cmd --list-all ##列出火墙信息
[root@apache ~]# yum whatprovides */genkey ##找到相关软件
Loaded plugins: langpacks
Repository rhel_dvd is listed more than once in the configuration
crypto-utils-2.4.1-42.el7.x86_64 : SSL certificate and key management
: utilities
Repo : rhel_dvd
Matched from:
Filename : /usr/bin/genkey
crypto-utils-2.4.1-42.el7.x86_64 : SSL certificate and key management
: utilities
Repo : @rhel_dvd
Matched from:
Filename : /usr/bin/genkey
yum install crypto-utils-2.4.1-42.el7.x86_64 -y ##安装
[root@apache ~]# genkey
Usage: genkey [options] servername ##提示genkey 的用法(genkey 域名IP)
genkey www.ali.com ##
新建一个窗口敲字符或移动鼠标 (这个采集密码是从你敲的字符和鼠标移动获得的)
收费服务 选NO
[root@apache ~]# cd /etc/httpd/conf.d ##进入配置文件
[root@apache conf.d]# ls
a_cgi.conf autoindex.conf manual.conf news.conf README userdir.conf
a_default.conf cgi.conf mxw.conf php.conf ssl.conf welcome.conf
[root@apache conf.d]# vim ssl.conf ##编辑这个软件的配置文件