当前位置:网站首页>Apache的管理及web优化
Apache的管理及web优化
2022-08-02 14:46:00 【linyxg】
Apache服务
- 安装Apache服务:dnf install httpd.x86_64
安装Apache加密插件:dnf install mod_ssl -y - 启用Apache服务
开启服务并设定服务为开机自启:systemctl enable --now httpd
在火墙中永久开启https访问:firewall-cmd --permanent --add-service=https
在火墙中永久开启http访问:firewall-cmd --permanent --add-service=http
刷新火墙,让设定生效:firewall-cmd --reload - 查看火墙信息:firewall-cmd --list-all
Apache的默认设置信息
- 服务名称: httpd
- 默认端口:http ----> 80 ; https ----> 443
- 日志目录:/etc/httpd/logs
- 默认发布目录:/var/www/html/
- 默认发布文件:index.html (必须在默认发布目录里)
- Apache主配置文件 : /etc/httpd/conf/httpd.conf
- Apache子配置文件 : /etc/httpd/conf.d/*.conf
修改Apache的基本配置
更改基本端口
编辑主配置文件 :vim /etc/httpd/conf/httpd.conf (改为8080)
重启服务:systemctl restart httpd
关闭selinux服务: vim /etc/sysconfig/selinux
修改火墙设定,增加8080端口:firewall-cmd --add-port=8080/tcp (防火墙默认80)
查看火墙信息:firewall-cmd --list-all
查看端口信息:netstat -antlupe | grep httpd
访问网址:172.25.254.110:8080更改Apache默认发布文件
设置westos文件为Apache默认发布目录
修改主配置文件 vim /etc/httpd/conf/httpd.conf
修改内容如下:(默认两个发布文件)
重启服务:systemctl restart httpd
访问网址:172.25.254.110更改Apache默认发布目录
新建目录:mkdir /var/www/westos
编辑文件:vim /var/www/westos/index.html
编辑主配置文件 vim /etc/httpd/conf/httpd.conf
重启服务:systemctl restart httpd
修改内容:
访问:172.25.254.210
Apache的访问控制
基于ip
新建默认发布目录的子目录:mkdir /var/www/html/Apacheip/
新建并编辑发布文件:vim /var/www/html/Apacheip/index.html
编辑主配置文件 vim /etc/httpd/conf/httpd.conf
重启服务: systemctl restart httpd
主配置文件添加的内容:
allow 和deny的读取顺序 ---->先同意后拒绝
allow 和deny的读取顺序 ---->先拒绝后同意
访问:172.25.254.40/Apacheip/基于用户(输入密码登陆一次下次就不需要了)
建立用户认证文件:htpasswd -cm /etc/httpd/.htpasswd admin(可建立到任意目录 )
再次建立用户认证:htpasswd -m /etc/httpd/.htpasswd lyx
编辑主配置文件 vim /etc/httpd/conf/httpd.conf
重启服务: systemctl restart httpd
主配置文件添加的内容:
访问:172.25.254.40/Apacheip/
Apache虚拟主机搭建
- 可以使一台Apache同时发布多个页面
构建测试网页
新建westos.org目录和三个子目录:mkdir -p /var/www/westos.org/{linux,shell,python}
生成并写入内容到liunx的发布文件 :echo linux.westos.org >/var/www/westos.org/linux/index.html
生成并写入内容到shell的发布文件: echo shell.westos.org >/var/www/westos.org/shell/index.html
生成并写入内容到python的发布文件:echo python.westos.org >/var/www/westos.org/python/index.html编写本地解析 (在所要浏览页面的主机里编写 )
编写本地解析文件:vim /etc/hosts
本地解析添加内容:编辑Apache的子配置文件
进入Apache的子配置目录:cd /etc/httpd/conf.d
指定子配置文件并写入内容:vim vhost.conf (文件名必须以.conf结尾)
子配置文件添加内容:重启服务: systemctl restart httpd
- 重启Apache服务不成功,检查出错原因方法:
清空日志文件:>/var/log/messages
重新运行命令:systemctl restart httpd
查看日志信息:cat /var/log/messages
或查看httpd日志:ls /etc/httpd/logs/
Apache的语言支持
- 安装Apache的帮助文档:dnf install httpd-manual -y
- 访问帮助文档:http://172.25.254.40/manual/
- php语言
安装php:dnf install php -y
编辑php页面内容:vim /var/www/html/index.php
重启服务: systemctl restart httpd
访问网址:http://172.25.254.40/index.php
- cgi (通用网关接口 —> c++ )
- Apache只能发布静态页面,所以通过cgi执行脚本,输出静态text,Apache 再执行
发布文件的内容:
Apache子配置目录下的子配置文件的内容:
- wsgi
安装:dnf install python3-mod_wsgi.x86_64 -y
发布目录:mkdir /var/www/html/wsgi
发布文件:vim /var/www/html/wsgi/index.wsgi
赋予执行的权限:chmod +x index.wsgi
编写子配置文件:vim /etc/httpd/conf.d/vhost.conf
本地解析文件:vim /etc/hosts
重启服务: systemctl restart httpd
边栏推荐
猜你喜欢
随机推荐
SQL学习笔记——REGEXP运算符
c语言实现三子棋
aPaaS低代码平台(二) | 快速构建业务模型
codeforces k-Tree (dp仍然不会耶)
setTimeout与setInterval的区别
【个人总结】2022.7月结
servlet交互过程图详解,servlet的常见问题,创建web项目(一)
mysql 递归函数with recursive的用法
MySQL语法入门
程序员开发效率神器汇总!
nacos
Apache APISIX 2.15 版本发布,为插件增加更多灵活性
【Untitled】
中科驭数等单位牵头发布行业首部DPU评测方法技术白皮书
Qt | Qt 的项目文件.pro 文件详解
c语言实现排雷
散列表简述
两分钟录音就可秒变语言通!火山语音音色复刻技术如何修炼而成?
SQL查询数据以及排序
PAT Class A 1130 Infix Expressions