实验环境
(1)设置IP
(2)配置软件仓库


1.Apache和web

什么是Web?
web(World Wide Web) 即全球广域网,也称为万维网,
即通过超文本传输协议把服务器上前端开发人员所写好的网页发布,客户端可以通过浏览器进行访问网页,建立在Internet上的一种网络服务。
什么是apache?
(音译为阿帕奇)
在web页面被访问时通常使用http://的方式
Apache作为一种由超文本传输协议提供的软件在web服务器上运行;
http:// 超文本传输协议提供的软件:
Aache
nginx
stgw
jfe
Tengine


2.Apache的基本信息

服务名称:httpd
配置文件:
/etc/httpd/conf/httpd.conf    主配置文件
/etc/httpd/conf.d/*.conf      子配置文件
默认发布目录:
/var/www/html
默认发布文件:
index.html
默认端口:
http    #80
https   #443用户:apache
日志:/etc/httpd/logs

3.Apache的安装

dnf search apache             查看apache配置文件
dnf install httpd.x86_64 -y   安装apache

4.Apache的启用

systemctl enable --now httpd
firewalld-cmd --list-all
firewalld-cmd --permanent --add-service=http
firewalld-cmd --permanent --add-service=https
firewalld-cmd --reload

测试:
cd /var/www/html
vim index.html
写入 hello linuxrui

"编辑完成之后在虚拟机或Windows浏览器输入IP192.168.165.55即可访问自己编辑的内容“


5.Apache的基本配置

(1)Apache的端口修改

vim /etc/httpd/conf/httpd.conf
listen 8080
firewalld-cmd --permanent --add-port=8080/tcp
firewalld-cmd --reload
systemctl restart httpd


测试:http://192.168.165.55

(2)修改默认发布文件优先级

vim /etc/httpd/conf/httpd.conf
DirectoryIndex westos.html index.html
systemctl restart httpd

测试:http://192.168.165.55

(3)修改默认发布目录优先级

mkdir /linuxrui
vim /linuxrui/index.html
写入:
Ringringrui is a cool boy!!!
vim /etc/httpd/conf/httpd.conf
写入:
DocumentRoot "/linuxrui"
<Directory "/linuxrui">Require all granted
</Directory>
systemctl restart httpd
ls -Zd /linuxrui
ls -Zd /var/www/html
semanage fcontext -a -t public_content_t '/linuxrui(/.*)?'
restorecon -RvvF /linuxrui
ls -Zd /linuxrui


在/linuxrui/index.html文件中编辑的内容

vim /etc/conf/httpd.conf 编辑主配置文添加的内容

测试:
http://192.168.165.55


6.Apache的访问控制

实验素材

mkdir /var/www/html/westos
vim /var/www/html/westos/index.html
写入:
Ringruirui and linuxrui

(1)基于客户IP的访问控制

ip白名单

vim /etc/httpd/conf/httpd.conf
写入:
<Directory "var/www/html/westos">Order Deny,AllowDeny from AllAllow from 192.168.165.55
</Directory>
systemctl restart httpd

测试:
http://192.168.165.55
http://192.168.165/250



ip黑名单

vim /etc/httpd/conf/http.conf
写入:
<Directory "/var/www/html/westos">Order Allow,DenyAllow from AllDeny from 192.168.165.55
</Directory>
systemctl restart httpd

测试:
http://192.168.165.55
http://192.168.165.250


(2)基于用户认证的访问控制

vim /etc/httpd/conf/httpd.conf
写入:
<Directory "/var/www/html/westos">AuthUserfile /etc/httpd/htpasswdfile                         AuthName "Please input your name and password"  AuthType basic Require user admin ##允许通过的认证用户 2选1
Require valid-user ##允许所有用户通过认证 2选1
</Directory>
systemctl restart httpd
htpasswd -cm /etc/httpd/htpasswdfile admin
htpasswd -m /etc/httpd/htpasswdfile ring


注意: 当/etc/httpd/htpasswdfile存在那么在添加用户时不要加-c参数否则会覆盖源文件内容

测试:
http://192.168.165.55


7.Apache的虚拟主机

mkdir -p/var/www/virtual/westos.org/{linuxrui,ring}
echo linuxuri >/var/www/westos.org/linuxrui/index.html
echo ring > /var/www/westos.org/ring/index.html
echo ringringrui > /var/www/html/index.html
vim /etc/httpd/conf.d/vhost.conf
写入:
<VirtualHost _default_:80>DocumentRoot /var/www/htmlCustomLog logs/default.log combined
</VirtualHost><VirtualHost *:80>SerVerName linuxrui.westos.orgDocumentRoot /var/www/virtual/westos.org/linuxruiCustomLog logs/linuxrui.log combined
</VirtualHost><VirtualHost *:80>ServerName ring.westos.orgDocumentRoot /var/www/virtual/westos.org/ringCustomLog logs/ring.log combined
</VirtualHost>systemctl restart httpd

**在浏览器所在主机中做域名解析**
vim /etc/hosts
写入:
192.168.165.55 www.westos.org linuxuri.westos.org ring.westos.org

测试:firefox http://www.westos.com         ---->ringringrui
firefox http://linuxrui.westos.com     ---->linxurui
firefox http://ring.westos.com           ---->ring"访问相应的网址会出现该目录下文件中所编辑的内容"



8.Apache的语言支持

php

vim /var/www/html/index.php
<?php
phpinfo();
?>
dnf install php -y                ##安装php语言服务
systemctl restart httpd

测试:
firefox http://192.168.165.55/index.php


cgi

mkdir /var/www/html/cgidir
vim /var/www/html/cgidir/index.cgi
写入:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;

vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/cgidir">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
systemctl restart httpd

cd /var/www/html/cgidir
chmod +x index.cgi
getenforce
chcon -t httpd_sys_script_exec_t /var/www/html/
chcon -t httpd_sys_script_exec_t /var/www/html/cgidir/index.cgi

测试:
firefox http://192.168.0.11/cgidir/index.cgi


wsgi

书写wsgi的测试文件
mkdir -p /var/www/html/wsgi
vim /var/www/html/wsgi/index.wsgi
写入:
def application(env, westos):westos('200 ok',[('Content-Type', 'text/html')])return [b'hello westos ahhahahahah!']


cd /var/www/html/wsgi
chmod +x index.wsgi
dnf install python3-mod_wsgi -y              ##安装python语言服务
systemctl restart httpd
vim /etc/httpd/conf.d/vhost.conf
写入:
<VirtualHost *:80>
ServerName wsgi.westos.org
WSGIScriptAlias / /var/www/html/wsgi/index.wsgi
</VirtualHost>



在浏览器所在的主机中做域名解析
vim /etc/hosts
添加: wsgi.westos.org

测试:
http://wsgi/westos.org


9.Apache的加密访问

dnf install mod_ssl -y          安装加密插件systemctl restart httpd
mkdir /etc/httpd/certs
在/etc/httpd/certs下生成认证
两种方式生成认证:
##command 1
openssl genrsa -out /etc/pki/tls/private/www.westos.com.key 2048       生成私钥
openssl req -new -key /etc/pki/tls/private/www.westos.com.key -out /etc/pki/tls/certs/www.westos.com.csr           生成证书签名文件
openssl x509 -req -days 365 -in /etc/pki/tls/certs/www.westos.com.csr  -signkey /etc/pki/tls/private/www.westos.com.key  -out /etc/pki/tls/certs/www.westos.com.crt     生成证书
x509       证书格式
-req       请求
-in        加载签证名称
-signkey /etc/pki/tls/private/www.westos.com.key##command 2
openssl req --newkey rsa:2048  -nodes -sha256 -keyout /etc/httpd/certs/westos.org.key  -x509 -days 365 -out /etc/httpd/certs/westos.org.crt


vim /etc/httpd/conf.d/ssl.conf
更改:
85行    SSLCertificateFile /etc/httpd/certs/westos.org.crt
86行    SSLCertificateKeyFile /etc/httpd/certs/westos.org.key
systemctl restart httpd

mkdir -p /var/www/virtual/westos.org/login
echo login.westos.org  > /var/www/virtual/westos.org/login/index.html
vim /etc/httpd/conf.d/Vhost.conf
写入:
<VirtualHost *:443>ServerName login.westos.orgDocumentRoot /var/www/virtual/westos.org/loginCustomlog logs/login.log combinedSSLEngine onSSLCertificateFile /etc/httpd/certs/westos.org.crtSSLCertificateKeyFile /etc/httpd/certs/westos.org.key
</Virtual Host><VirtualHost *:80>Servername  login.westos.orgRewriteEngine on RewriteRule ^(/.*)$  https://%{HTTP_HOST}$1
</VirtualHost>
systemctl restart httpd^(/.*)$           客户地址栏中输入的地址
%{HTTP_HOST}      客户主机
$1                RewriteRule后面跟的第一串字符的值

做域名解析
vim /etc/hosts
写入:
192.168.165.55  login.westos.org

测试:
http://192.168.165.55


10.web服务器访问加速优化

实验环境
两台主机
主机A 192.168.165.55
主机a 192.168.165.65
1)设置IP–>两台主机之间网络可以通信
2)配置软件仓库

squid正向代理 ---->即“翻墙”
squid反向代理 ----> 即“CDN加速:
原理:客户从主机a(服务器)访问内容,主机a向客户提供要访问的内容;
当主机a中没有客户想要访问的内容时,主机a(服务器)向主机A(总服务器)寻找客户要访问内容并将其缓存下来,然后主机a(服务器)将客户要访问的内容发送给客户;
下次有客户访问同样的内容时,主机a(服务器)就可以直接提供客户要访问的内容;

在主机a 192.168.165.65中:

dnf install  squid -y                   安装squid服务
vim /etc/squid/squid.conf
修改:
59 http_access allow all
62 http_port 80 vhost vport
65 去掉“#”catche_dir ufs /var/spool/squid 100 16 25666 添加:cache_peer 192.168.165.55 parent 80 0 proxy-onlysystemctl enable --now squid
firewall-cmd --permanent --add-service=http
firewalld-cmd --reload


测试:
http://192.168.165.55
http://192.168.165.65

Apache的管理及Web页面的优化相关推荐

  1. web页面性能优化及SEO优化

    web页面性能优化 前言: 在同样的网络环境下,两个同样能满足你的需求的网站,一个"Duang"的一下就加载出来了,一个纠结了半天才出来,你会选择哪个?研究表明:用户最满意的打开网 ...

  2. web 页面性能优化

    web 页面性能优化 性能优化在视觉上有两个阶段: 加载阶段,能够快速的看到页面(首屏渲染时间); 交互阶段,能够快速响应操作(动画效果,接口返回速度等) 加载阶段 加载阶段,是指从发出请求到渲染出完 ...

  3. 小tip: base64:URL背景图片与web页面性能优化(转载)

    今天在代码看到css北京图片使用了base64格式表示图片,SO,百度了一下.感觉完全可以解释了. 一.base64百科 Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,可用于在H ...

  4. web页面性能优化方法总结

    最近老大给我布置了一道作业,让我去想想有哪些办法可以优化web页面的性能,回头一看,做了这么多年的前端开发,多少还是知道一些常规的性能优化策略,以下是我对性能优化的一个总结,共13点,如果描述错误,欢 ...

  5. 小tip: base64:URL背景图片与web页面性能优化——张鑫旭

    一.base64百科 Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,可用于在HTTP环境下传递较长的标识信息. 某人: 唉,我彻底废柴了,为何上面明明是中文,洒家却看不懂嘞,为什 ...

  6. web页面性能优化系列(附录)其他必会的基础知识

    001:即建立TCP链接 1,根据域名解析IP获取IP地址 2,TCP|IP三次握手 1,根据域名解析IP获取IP地址-发生在互联层 DNS解析IP A:浏览器会先解析我们输入的url地址,浏览器会先 ...

  7. Web页面性能优化以及SEO

    为什么要提高web性能? Web性能黄金准则:只有10%20%的最终用户响应时间花在了下载html文档上,其余的80%90%时间花在了下载页面组件上. web性能对于用户体验有及其重要的影响,根据著名 ...

  8. Apache与Nginx实现Web页面动静分离(产生的原因,应用场景)

    文章目录 动静分离产生的原因 服务作用场景 实验步骤 配置apache服务 配置Nginx服务器 动静分离产生的原因 Nginx的静态处理能力很强,但是动态处理能力不足,因此,在企业中常用动静分离技术 ...

  9. Apache的管理及优化web

    Apache的管理及优化 web 1 实验环境 2 Apache的作用 3 Apache的安装与启用 3.1 Apache的安装 3.2 Apache的启用 4 Apache的基本信息 5 Apach ...

最新文章

  1. fanuc机器人cm格式文件_了解发那科智能机器人自动化物流拆垛
  2. 图片的裁剪、旋转、平移、模糊
  3. 员工张三有两个主管线程_如何做好中层?想让领导满意、员工信服、自己轻松,这2技能必备...
  4. java里面快速排序_Java:快速排序
  5. protobuf编码
  6. error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MDd_DynamicDebug...
  7. Docker(二):Docker常用命令之镜像的创建:Dockerfile 与 commit
  8. php取整函数ceil,floor,round,intval函数的区别
  9. 关于Java Collections Framework的一些总结(2)
  10. DeepLabv1补充:对全连接条件随机场(Fully Connected / Dense CRF)的理解
  11. java web学习心得
  12. 公众号及小程序的测试点
  13. 利用WinEdt修改图片格式为eps
  14. .mat转成.npy文件+Python(Pytorch)压缩裁剪图片
  15. 【记录】win11安装ubuntu子系统教程
  16. openairinterface5g基站老版eNB部署
  17. minio 上传文件失败报错信息: The difference between the request time and the server‘s time is too large.
  18. 智飞生物与碧迪医疗战略合作;奥的斯智慧服务实验室完成升级 | 美通企业日报
  19. 最详细的App自动化常用的元素审查器
  20. 【面试经历】美团2020秋招测试开发一面二面

热门文章

  1. 通信原理(1)基带传输
  2. 如何查询快递单号物流及时发现退回件单号
  3. python源代码怎么变成软件_python程序怎么变成软件
  4. 40G QSFP+超长距离传输光模块丨40G QSFP+ ER4/ZR4
  5. 信号与系统自动控制理论实训QY-DPJ01
  6. 数据采集器的三大分类
  7. iphone扫描文档jpg_如何将名片扫描到iPhone的联系人列表中
  8. php学生老师,学生渴望的新课堂a href=/friend/list.php(教师中心专稿)/a
  9. 如何在Word2007文档中不同页面纵横方向混排?
  10. 2020团队天梯赛-正赛-L1题目集