ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Apache的管理及优化web

2022-01-03 10:33:19  阅读:161  来源: 互联网

标签:web www httpd westos var html Apache org 优化


一、Apache的作用

在web被访问时通常使用http://的方式

http:// ##超文本传输协议

http:// 超文本传输协议提供软件:

Apache
nginx
stgw
jfe
Tengine

实验一:

dnf install httpd.x86_64 -y
firewall-cmd --permanent --add-service=http ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload ##刷新火墙使设定生效
vim /var/www/html/index.html

2.Apache的安装

dnf install httpd.x86_64 -y

3.Apache的启用

systemctl enable --now httpd ##开启服务并设定服务位开机启动
firewall-cmd --list-all ##查看火墙信息
firewall-cmd --permanent --add-service=http ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload ##刷新火墙使设定生效

4.Apache的基本信息

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

5.Apache的基本配置

//重点是指向:DirectoryIndex

#1.Apache端口修改#
vim /etc/httpd/conf/httpd.conf
Listen 8080 //编辑配置文件,修改端口为8080
firewall-cmd --permanent --add-port=8080/tcp //防火墙加8080端口
firewall-cmd --reload //重新加载防火墙
systemctl restart httpd //重启服务
netstat -antlupe | grep httpd //查看端口有没有加进去

http://172.25.254.100:8080

#2.默认发布文件##
vim /var/www/html/westos.html //编辑另外一个页面
内容
vim /etc/httpd/conf/httpd.conf
DirectoryIndex westos.html index.html //编辑它的默认指向页面
systemctl restart httpd //重启服务
http://172.25.254.100:8080

#3.默认发布目录
mkdir /westos_apache
vim /westos_apache/index.html
semanage fcontext -a -t httpd_sys_content_t ‘/westos_apache(/.*)?’ //修改安全上下文和httpd一致
restorecon -RvvF /westos_apache/ //重新加载安全上下文
vim /etc/httpd/conf/httpd.conf //修改配置文件
DocumentRoot “/var/westos_apache”
<Directory “/westos_apache”>
Require all granted
//修改配置文件
systemctl restart httpd
http://172.25.254.100:8080

6.Apache的访问控制

#实验素材#
mkdir /var/www/html/westos
vim /var/www/html/westos/index.html
westosdir’s page

firefox http://192.168.0.11/westos

#1.基于客户端ip的访问控制#
mkdir /var/www/html/westos //创建一个目录
vim /etc/httpd/conf/httpd.conf //修改配置文件
DocumentRoot “/var/www/html” //修改默认的加载路径

#(1)ip白名单#
<Directory “/var/www/html/westos”> //限制的目录
Order Deny,Allow
Allow from 172.25.254.41 //允许一个,拒绝所有
Deny from All

#(2)ip黑名单#
<Directory “/var/www/html/westos”>
Order Allow,Deny
Allow from All //允许所有,拒绝一个
Deny from 172.25.254.41

#2.基于用户认证#
mkdir /var/www/html/westos //创建加密的文件
vim /var/www/html/westos/index.html //编辑加载的页面
在这个路径下面/etc/httpd/:
htpasswd -cm .htpasswd admin //创建用户

vim /etc/httpd/conf/httpd.conf //编辑配置文件
160行:
DirectoryIndex index.html //默认加载的文件
120行:
DocumentRoot “/var/www/html” //路径
<Directory “/var/www/html/westos”> //加密的目录
AuthUserfile /etc/httpd/.htpasswd //指定认证文件
AuthName “Please input your name and password” //认证提示语
AuthType basic //认证类型
#Require user admin //允许通过的认证用户 2选1
Require valid-user //允许所有用户通过认证 2选1

systemctl restart httpd //重启服务

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

7.Apache的虚拟主机

mkdir -p /var/www/westos.com/{news,wenku}
echo “wenku’s page” >/var/www/westos.com/wenku/index.html
echo “news’s page” > /var/www/westos.com/news/index.html
echo “default’s page” > /var/www/html/index.html

vim /etc/httpd/vhost.conf

DocumentRoot “/var/www/html”
CustomLog logs/default.log combined

<VirtualHost *:80>
ServerName wenku.westos.com
DocumentRoot “/var/www/westos.com/wenku”
CustomLog logs/wenku.log combined

<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot “/var/www/westos.com/news”
CustomLog logs/news.log combined

测试:
在浏览器所在主机中
vim /etc/hosts
192.168.0.11 www.westos.com wenku.westos.ocm news.westos.com

firefox http://www.westos.com
firefox http://wenku.westos.com
firefox http://news.westos.com

//实验步骤:
1、 创建文件目录:(服务器)
mkdir -p /var/www/vhost/westos.org/{news,music,hkk}
echo news.westos.org> /var/www/vhost/westos.org/news/index.html
echo music.westos.org> /var/www/vhost/westos.org/music/index.html
echo hkk.westos.org> /var/www/vhost/westos.org/hkk/index.html
2、编辑配置文件(服务器)
vim /etc/httpd/conf.d/vhost.conf

DocumentRoot /var/www/html
CustomLog logs/default.log combined

<VirtualHost *:80>
	ServerName music.westos.org
	DocumentRoot /var/www/vhost/westos.org/music
	CustomLog logs/music.log combined
</VirtualHost>

<VirtualHost *:80>
	ServerName news.westos.org
	DocumentRoot /var/www/vhost/news.org/news
	CustomLog logs/news.log combined
</VirtualHost>

<VirtualHost *:80>
	ServerName hkk.westos.org
	DocumentRoot /var/www/vhost/hkk.org/hkk
	CustomLog logs/hkk.log combined
</VirtualHost>

3、手动解析域名:(浏览器在哪里就在哪里编辑)
172.25.254.241 westos.westos.org news.westos.org music.westos.org hkk.westos.org
//服务器ip
4、重启并测试
systemctl restart httpd
westos.westos.org
news.westos.org
music.westos.org
hkk.westos.org //分别访问,用浏览器

标签:web,www,httpd,westos,var,html,Apache,org,优化
来源: https://blog.csdn.net/k0512/article/details/119285312

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有