Apache的管理及优化web

1.Apache的安装及启用

前提:ip和软件仓库设置好
(1)安装
dnf install httpd.x86_64 -y


(2)启用
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

2.Apache基本配置

(1)端口修改
vim /etc/httpd/conf/httpd.conf
编辑内容

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
systemctl restart httpd

浏览器输入ip

浏览器输入 ip:8080

(2)默认发布文件
vim /etc/httpd/conf/httpd.conf
编辑内容

vim /var/www/html/westos.html
编辑内容
 

systemctl restart httpd

浏览器输入ip


3.Apache的虚拟主机

(1)实验准备
mkdir -p /var/www/virtual/westos.org/{linux,news}
echo linux  > /var/www/virtual/westos.org/linux/index.html
echo news  > /var/www/virtual/westos.org/news/index.html
echo 123 > /var/www/html/index.html
 

(2)实验步骤
vim /etc/httpd/conf.d/vhosts.conf
编辑内容


systemctl restart httpd
vim /etc/hosts
编辑内容

测试:firefox分别输入www.westos.org  linux.westos.org news.westos.org

www.westos.org

linux.westos.org

news.westos.org


4.Apache语言支持

(1)php
vim /var/www/html/index.php
编辑内容

dnf install php -y


systemctl restart httpd

测试    http://192.168.0.11/index.php

(2)cgi
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
编辑内容

vim /etc/httpd/conf/httpd.conf
编辑内容

systemctl restart httpd
chmod +x /var/www/html/cgi/index.cgi
semanage fcontext -l | grep cgi                //搜索安全上下文

chcon -Rt httpd_sys_script_exec_t  /var/www/html/cgi/      //更改目录及其内部文件的安全上下文
restorecon -RvvF /var/www/html/cgi/

5.Apache的加密访问

dnf install mod_ssl -y


openssl req --newkey rsa:2048 -nodes -sha256 -keyout /etc/httpd/westos.org.key -x509 -days 365 -out /etc/httpd/westos.org.crt


cd /etc/httpd/
ls


vim /etc/httpd/conf.d/ssl.conf 
编辑内容


systemctl restart httpd

测试  https://192.168.155.100

6.Apache自带前缀https://

vim /etc/httpd/conf.d/vhosts.conf 
编辑内容

systemctl restart httpd
vim /etc/hosts
编辑内容

测试: 输入login.westos.org



 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值