当前位置:网站首页>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
边栏推荐
猜你喜欢

【 Leetcode string, the string transform/hexadecimal conversion 】 HJ1. The length of the string last word HJ2. Calculation of a certain number of characters appear HJ30. String merging processing

什么是hashCode?

初入c语言

go——协程调度

Servlet运行原理_API详解_请求响应构造进阶之路(Servlet_2)

机械键盘失灵

servlet交互过程图详解,servlet的常见问题,创建web项目(一)

基于ip的证书

李开复花上千万投的缝纫机器人,团队出自大疆

SQL查询数据之多表(关联)查询
随机推荐
MySQL 自增主键
How to check the WeChat applet server domain name and modify it
Qt | 鼠标事件和滚轮事件 QMouseEvent、QWheelEvent
MySQL 高级(进阶) SQL 语句 (一)
es6 循环,并终止循环
IPtables and binlog
什么是Nacos?
2022 Low Voltage Electrician Exam Questions and Online Mock Exam
PAT Class A 1019 Common Palindrome Numbers
PAT甲级 1019 普通回文数
SQL查询数据之多表(关联)查询
2022/7/15,我的人生中第一篇博客,不忘初心,砥砺前行!
aPaaS低代码平台(二) | 快速构建业务模型
如何正确且快速的清楚C盘!!释放C盘空间内存保姆级教程
23.支持向量机的使用
【无标题】
Reading is the cheapest and noblest
基于mobileNet实现狗的品种分类(迁移学习)
Qt | 关于容器类的一些总结
codeforces Linova and Kingdom