3 Apache 的管理和优化

本文详细介绍了Apache服务器的用途、安装、启用步骤,并展示了如何修改配置文件以改变端口、设置默认发布文件和目录。此外,还探讨了通过防火墙规则开启HTTP和HTTPS服务。接着,文章讲解了正向代理的实现,利用Squid作为代理机,使得单网卡主机通过代理访问互联网。最后,提到了Squid的反向代理配置,使得访问特定IP地址时显示另一台服务器的内容。
摘要由CSDN通过智能技术生成

1.Apache的作用

在web被访问时通常使用http://的方式
http://            ##超文本传输协议

http://    超文本传输协议提供软件:
Apache
nginx
stgw
jfe
Tengine

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的基本配置

#1.Apache端口修改#

vim /etc/httpd/conf/httpd.conf
Listen 8080
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
systemctl restart httpd

http://172.25.254.100:8080

2.默认发布文件

vim /etc/httpd/conf/httpd.conf
DirectoryIndex westos.html index.html
systemctl restart httpd

3.默认发布目录

mkdir /var/www/westos
mv /var/www/westos /var
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/westos"
<Directory "/var/westos">
        Require all granted
</Directory>
systemctl restart httpd 

firefox http://192.168.0.11

6.Apache的访问控制

######squit 正向代理#########

实验环境:

单网卡主机设定ip不能上网

双网卡主机设定ip1可以连接单网卡主机,设定ip2可以上网

实验效果:

让单网卡主机不能上网但浏览器可以访问互联网页面
 

实验环境

建立虚拟机westosb为代理机:
hostnamectl set-hostname squid.westos.org
vim /etc/sysconfig/network-scripts/ifcfg-ens3
DEVICE=ens3
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.217
PREFIX=24
GATEWAY=172.25.254.250
DNS1=114.114.114.114
nmcli connection reload
nmcli connection show

真机连接代理机:
dnf install squid -y
vim /etc/squid/squid.conf
           59 http_access allow all
           65 #去掉
    6  systemctl restart squid
    8  netstat -antlupe | grep squid
   10  firewall-cmd --permanent --add-service=squid
   11  firewall-cmd --reload
   12  firewall-cmd --list-all
   13  ping www.baidu.com

建立虚拟机westosaaaa:
hostnamectl set-hostname westosaaaa.westos.org
vim /etc/sysconfig/network-scripts/ifcfg-ens3
DEVICE=ens3
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.117
PREFIX=24
nmcli connection reload
nmcli connection show

真机连接虚拟机:
dnf install firefox -y
进入网页进行设置即可上网

#####squid反向代理###

在服务器westosaaaa中:
    4  dnf install httpd -y         ##下载httpd服务器
    6  systemctl enable --now httpd
    7  firewall-cmd --permanent --add-service=http
    9  firewall-cmd --reload
    10  ip a
    11  echo 172.25.254.117 > /var/www/html/index.html

 

在代理机squid中:
   16  less /usr/share/doc/squid/squid.conf.documented
   17  vim /etc/squid/squid.conf                          ##编辑端口
        62 http_port 80 vhost vport        #vhost 支持虚拟域名 vport 支持虚拟端口
     63 cache_peer 172.25.254.117 parent 80 0 proxy-only  ##编辑改为服务器端口,即可使用


18  systemctl restart squid
   19  systemctl status squid
   20  rpm -qa | grep httpd
   21  firewall-cmd --list-all
   22  firewall-cmd --permanent --add-service=http
   23  firewall-cmd --reload

访问217看到的是172.25.254.117上的数据

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值