文章目录
前言
一、Apache的作用和安装启用
1.Apache的作用
在web被访问时通常使用http://的方式
http://
超文本传输协议
http:// 超文本传输协议提供软件:Apache
nginx
stgw
jfe
Tengine
2.Apache的安装
dnf install httpd -y #安装Apache
sytemctl enable --now httpd #开启Apache服务
firewall-cmd --permanent --add-service=http #火墙允许该服务
firewall-cmd --reload #刷新火墙
二、Aapche的基本信息和基本配置
1.基本信息以及帮助手册的获取
1.基本信息
/etc/httpd/conf/httpd.conf #主配置文件
/etc/httpd/conf.d/*.conf #子配置文件
index.html #默认发布文件
/etc/httpd/logs #日志保存位置
2.帮助手册的获取
dnf install httpd-manual -y #下载后即可在httpd进行帮助手册的查询
2.基本配置
1.访问控制
- 基于IP的访问控制
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westosiso/index.html">
Order Allow,Deny
Allow from all
Deny from 172.25.0.90
2. 基于用户名和密码的访问控制
htpasswprd -cm /etc/httpd/password user1 #进行用户的密码输入以及限定使得密码进行
htpassword -m /etc/httpd/passwoord user2 #-c第二个用户如果存在则会进行覆盖第一个用户
配置文件的更改
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westosiso/">
AuthUserFile /var/.userpassword #指定用户认证文件位置
AuthName "ples input user name and password" #用户的认证提示语句
AuthType basic #
Require user user1 #user表示其中的用户user1表示其中的用户user1可以通过认证user2不行
# Require valid-user #表示认证文件中的用户均可通过认证Require valid-user和Require user user1二选一即可
</Directory>
2.默认发布目录的管理
vim /etc/httpd/conf/httpd.conf #修改配置文件即可
DocumentRoot "/var/westosiso" #修改文件的默认位置
<Directory "/var/westosiso">
Require all granted #允许所有用户访问
</Directory>
selinux开启状态下会阻止其进行访问因为其安全上下文不同导致的
semanage fcontext -a -t httpd_sys_content_t '/var/westos(/.*)?' #添加安全上下文到selinux中
3.Apache的虚拟主机
1.建立目录
mkdir -p /var/vhttp/westos{1..3} #件俩多个目录使得其可以被目录识别
2.建立测试页文件
echo ce shi ye weestos1 > /var/vhtpd/westos1/westos1.html
3.修改本地解析
在那台主机访问修改那台主机的解析
vim /etc/hosts
172.25.0.194 westos1.westos.org westos2.westos.org westos3.westos.org
4.Aanche的语言支持
1.php
dnf install php.x86_64 -y #下载php语言
vim /var/www/html/westosiso/index.php #编写测试脚本
<?php
phpinfo();
?>
2.cgi
mkdir /var/www/html/cgi
vim /var/www/html/ceshi.cgi
perl /var/www/html/cceshi.cgi #验证脚本是否可以执行
vim /etc/httpd/conf.d/westos.conf
chmod +x /var/www/html/chdir/ceshi.cgi
systemctl restart httpd
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
<Directory "/var/www/html/cgidir">
Options +ExecCGI
AddHandler cgi-script .cgi
<Directory "/var/www/html/cgidir">
5.Apache的加密访问
######1. 信息
dnf install mod_ssl -y #mod_ssh为Apache的加密插件
/etc/pki/tls/private/localhost.key #默认证书位置
2. 步骤
openssl genrsa -out /westos/westos1.westos.org.key 2048 #生成密钥-out表示指定位置
openssl req -new -key /westos/westos1.westos.org.key -out /westos/westos1.westos.org.crs
#生成签名文件
openssl x509 -days 365 -in /westos/westos1.westos.org.crs -signkey /westos/westos1.westos.org.key -out /westos/westos1.westos.org.crt #生成证书
3.配置文件内容
vim /etc/httpd/conf.d/westos.conf
<VirtualHost *:80>
servername westos1.westos.org
RewriteEngine On #网页重定向规则开启
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 #定向显示内容
</VirtualHost>
<VirtualHost *:443>
Documentroot /var/www/html/westos.org/westos1
CustomLog "logs/westos1.westos.org" combined
SSLCertificateKeyFile /westos/westos1.westos.org.key #使用的私钥
SSLCertificateFile /westos/westos1.westos.crt #使用的证书
SSLEngine on #开启功能
</VirtualHost>
-out #指定位置
-req #发送请求
-in #加载证书
-signkey #指定私钥
6.squid正向代理
1. 实验环境
实验环境:
单网卡主机设定ip不能上网
双网卡主机设定ip1可以连接单网卡主机,设定ip2可以上网
实验效果
让单网卡主机不能上网但浏览器可以访问互联网页
2. 操作步骤
dnf install squid -y #下载squid
vim /etc/squid/squid.conf
http_access allow all #设定所有人均可访问
http_port 3128 #设定端口为3128
systemctl restart squid #重启服务即可生效
7.sqld反向代理
1.squid设定
vim /etc/squid/squid.conf
http_port 80 vhost vport #设定端口为80使得其可以允许虚拟主机和虚拟端口
cache_peer 172.25.0.90 parent 80 0 proxy-only #设定缓存来源为172。25。0。90端口为80,proxy-only设定为仅作为缓存
cache_dir ufs /var/spool/squid 100 16 256 #表示设定/var/sqool/squid为缓存目录回滚设定为100M同时建立16个一级目录和265个2级目录
2.httpd设定
<VirtualHost _defaul_*:80>
DocumentRoot "/var/www/html"
CustomLog logs/heml.log combined
</VirtualHost>
<VirtualHost *:80>
servername westos.westos.org
DocumentRoot "/var/www/html/westos.org/westos/index.html"
CustomLog logs/index.log combined
</VirtualHost>