【2-4】Apache的管理及优化web

【2-4】Apache的管理及优化web

一、apache的作用

在web被访问时通常使用http://的方式
http:// ##超文本传输协议
http:// 超文本传输协议提供软件 :
Apache
nginx
stgw
jfe
Tengine

二、Apache的安装

dnf install httpd.x86_64 -y在这里插入图片描述

三、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 刷新火墙使设定生效

四、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

五、 Apache的基本配置

1.Apache端口修改

`vim /etc/httpd/conf/httpd.conf`
[root@node226 westos]# vim /etc/httpd/conf/httpd.conf 

在这里插入图片描述

[root@node226 westos]# vim /etc/selinux/config 

在这里插入图片描述

[root@node226 westos]# reboot

修改selinux之后需要重启。

[root@node226 westos]# systemctl restart httpd

在这里插入图片描述
Listen 8080
firewall-cmd --permanent --add-port=8080/tcp

[root@node226 westos]# firewall-cmd --add-port=8080/tcp   
#####不加permanent是一次性的,reload就没了。
success
[root@node226 westos]# 
[root@node226 westos]# firewall-cmd --list-all

在这里插入图片描述
在这里插入图片描述

[root@node226 ~]# cd /var/www/html/
[root@node226 html]# vim westos
[root@node226 html]# cat westos
linux westos is good
[root@node226 html]# 

在这里插入图片描述

[root@node226 html]# vim index.html
##默认无index.html文件,访问网址显示aphace默认页
#建立index.html文件,访问网址显示index.html内容。
[root@node226 html]# cat index.html 
index westos
[root@node226 html]# 

在这里插入图片描述

[root@node226 html]# vim /etc/httpd/conf/httpd.conf 

在这里插入图片描述

[root@node226 html]# systemctl restart httpd

在这里插入图片描述

[root@node226 html]# cd ..
[root@node226 www]# pwd
/var/www
[root@node226 www]# ls
cgi-bin  html
[root@node226 www]# mkdir westos
[root@node226 westos]# vim index.html
[root@node226 westos]# cat /var/www/westos/index.html 
/vat/www/westos'index page
[root@node226 westos]# vim /etc/httpd/conf/httpd.conf 

在这里插入图片描述

[root@node226 westos]# systemctl restart httpd

在这里插入图片描述
默认访问目录已修改
在这里插入图片描述

[root@node226 westos]# mkdir /var/www/html/westosdir/
[root@node226 westos]# vim /var/www/html/westosdir/index.html
[root@node226 westos]# cat /var/www/html/westosdir/index.html
/var/www/html/westosdir'index page
[root@node226 westos]# vim /etc/httpd/conf/httpd.conf 
[root@node226 westos]# systemctl restart httpd

在这里插入图片描述

[root@node226 westos]# vim /etc/httpd/conf/httpd.conf 

在这里插入图片描述

[root@node226 westos]# systemctl restart httpd

在这里插入图片描述

在这里插入图片描述

[root@node226 ~]# curl 172.25.254.226:8080/westosdir/

在这里插入图片描述

[root@node226 ~]# vim /etc/httpd/conf/httpd.conf 
[root@node226 ~]# systemctl restart httpd

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

[root@node226 ~]# vim /etc/httpd/conf/httpd.conf 
[root@node226 ~]# systemctl restart httpd
[root@node226 ~]# 

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

[root@node226 ~]# vim /etc/httpd/conf/httpd.conf 
[root@node226 ~]# systemctl restart httpd
[root@node226 ~]# 

在这里插入图片描述

在这里插入图片描述

[root@node226 ~]# htpasswd -cm /etc/httpd/.httpasswd admin

在这里插入图片描述

[root@node226 ~]# cat /etc/httpd/.httpasswd 

在这里插入图片描述

[root@node226 ~]# htpasswd -m /etc/httpd/.httpasswd lee

在这里插入图片描述

[root@node226 ~]# cat /etc/httpd/.httpasswd 

在这里插入图片描述

[root@node226 ~]# vim /etc/httpd/conf/httpd.conf 
[root@node226 ~]# systemctl restart httpd

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述在这里插入图片描述

[root@node226 ~]# vim /etc/httpd/conf/httpd.conf 
[root@node226 ~]# systemctl restart httpd

在这里插入图片描述

firewall-cmd --reload
semanage port -l |grep http
semanage port -a -t http_port_t -p tcp 8080
systemctl restart httpd
2.默认
发布文件
vim /etc/httpd/conf/httpd.conf
DirectoryIndex westos.html index.
systemctl restart httpd
3.默认发布目录
vim /etc/httpd/conf/httpd.conf
DocumentRoot “/westos/html”
<Directory “/westos/html”>
Require all granted

semanage fcontext -a -t httpd_sys
restorecon -RvvF /westos/
systemctl restart httpd

[root@node226 ~]# mkdir -p /var/www/westos.org/{linux,shell,python}
[root@node226 ~]# echo linux.westos.org > /var/www/westos.org/linux/index.html
[root@node226 ~]# echo shell.westos.org > /var/www/westos.org/shell/index.html
[root@node226 ~]# echo python.westos.org > /var/www/westos.org/python/index.html

在这里插入图片描述

测试:
在浏览器所在的主机中
vim /etc/hosts
192.168.0.11 www.westsos.com wenku.westos.com news.westos.com
在这里插入图片描述
firefox http://www.westos.com
firefox http://wenku.westos.con
firefox http://news.westos.com
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述均为默认页
vim /etc/httpd/conf.d/vhost.conf
在这里插入图片描述

[root@node226 ~]# systemctl restart httpd

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述各自回各自目录。
在这里插入图片描述

八、Apache的语言支持

php

vim /var/www/html/index.php

<?php
		phpinfo();
?>

在这里插入图片描述

dnf install php -y

[root@node226 logs]# dnf install php -y

在这里插入图片描述

[root@node226 logs]# systemctl restart httpd

在这里插入图片描述

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`;

在这里插入图片描述
perl /var/www/html/cgi/index.cgi
在这里插入图片描述

在这里插入图片描述

[root@node226 logs]# vim /etc/httpd/conf.d/vhost.conf 

在这里插入图片描述

[root@node226 logs]# systemctl restart httpd

在这里插入图片描述

vim /etc/httpd/conf.d/vhost.conf
<Directory “/var/www/html/cgidir”>

[root@node226 logs]# dnf install httpd-manual-2.4.37-21.module+el8.2.0+5008+cca404a3.noarch 

在这里插入图片描述

<Directory “/var/www/html/cgidir”>
Options +ExecCGI
AddHandler cgi-script .cgi

firefox http://172.25.254.226/cgi/index.cgi
wsgi
书写wsgi的测试

[root@node226 logs]# vim /var/www/html/wsgi/index.wsgi
[root@node226 logs]# vim /var/www/html/wsgi/index.wsgi
[root@node226 logs]# chmod +x /var/www/html/wsgi/index.wsgi 
[root@node226 wsgi]# cat /var/www/html/wsgi/index.wsgi 
def application(env,westos):
	westos('200 ok',[('Content-Type','text/html')])
	return [b'hello westos!']
[root@node226 wsgi]# 

[root@node226 wsgi]# vim /etc/httpd/conf.d/vhost.conf 

在这里插入图片描述

[root@node226 wsgi]# dnf install python3-mod_wsgi.x86_64 -y
[root@node226 wsgi]# systemctl restart httpd

客户端

[root@node26 ~]# vim /etc/hosts

在这里插入图片描述
在这里插入图片描述

九、Apache的加密访问

安装加密插件
dnf install mod_ssl -y

生成证书

猜你喜欢

转载自blog.csdn.net/qq_39679699/article/details/113553419
2-4
今日推荐