Apache的管理以及优化


前言


一、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.访问控制
  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>

总结

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PHP、MySQL和Apache是一套非常流行的Web开发工具,这三个工具相结合可以用来构建强大的缺陷管理系统。 首先,使用PHP作为后端语言可以充分利用其丰富的功能和强大的开发框架,实现缺陷管理系统的各种需求。PHP具有良好的跨平台性,可以在多种操作系统上运行,同时也支持各种数据库连接,包括MySQL。 MySQL是一种广泛使用的开源关系型数据库管理系统,它具有稳定性高、性能优异的特点,非常适合存储大量的缺陷数据。通过MySQL,我们可以轻松地存储和管理各种缺陷信息,如缺陷描述、严重程度、状态等。 Apache是一种流行的Web服务器软件,它具有开放源代码、稳定可靠、高性能的特点,可以有效地处理并发请求。通过Apache,我们可以将PHP脚本与MySQL数据库结合起来,并通过HTTP协议将数据传输给用户的浏览器。 然而,PHP、MySQL和Apache在使用过程中也存在些许缺陷。首先,由于PHP是一种动态解释型语言,其运行效率可能不如编译型语言,对于高并发的场景可能会出现一些性能问题。其次,MySQL在处理大数据量时,性能可能受到一些限制,例如查询速度变慢。最后,Apache虽然功能强大,但在高并发的情况下,可能需要进行一些调优才能发挥出最大的性能。 为了克服这些缺陷,可以通过使用缓存技术、优化SQL查询语句和配置调优等方式来提升系统性能。同时,还可以考虑使用其他替代方案,如Nginx代替Apache,使用NoSQL数据库代替MySQL等。 总之,PHP、MySQL和Apache是一套非常强大的工具,可以用于构建缺陷管理系统。尽管存在一些缺陷,但通过合理的优化和配置,仍然可以实现高性能和稳定可靠的系统。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值