Apache

本文详细介绍Apache服务器的安装步骤及基本配置方法,包括修改默认发布文件、发布目录、访问控制等,并介绍了如何支持PHP和CGI语言,以及如何配置虚拟主机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

apache的安装

yum  install  httpd  -y

systemctl start  httpd

systemctl  stop firewalld

systemctl enable  httpd

systemctl  disable  firewalld

apache的基本配置

1.apache的默认发布文件

index.html

2.apache的配置文件

/etc/httpd/conf/httpd.conf

/etc/httpd/conf.d/*.conf

3.apache的默认发布目录

/var/www/html

4.apache的默认端口

80

apache的基本配置

1.修改默认发布文件

vim /etc/httpd/conf/httpd.conf

164  DirectoryIndex  westos.html index.html

2.修改默认发布目录

当selinux是disabled状态

vim  /etc/httpd/conf/httpd.conf

120   DocumentRoot "/westos/www/test"

<Directory "/westos/www/test">

         Require  all granted

</Directory>

systemctl  restart  httpd

 

当selinux是enforcing状态

vim  /etc/httpd/conf/httpd.conf

120   DocumentRoot "/westos/www/test"

<Directory "/westos/www/test">

         Require  all granted

</Directory>

systemctl  restart  httpd

semanage  fcontext  -a  -t httpd_sys_content_t  '/westos(/.*)?'

restorecon  RvvF  /westos

3.apache的访问控制

vim  /etc/httpd/conf/httpd.conf    

<Directory  "/var/www/admin">            #允许所有人访问admin目录但拒绝118访问

        Order  Allow,Deny

        Allow  from  All

        Deny from  172.25.254.118

</Directory>

 

<Directory  "/var/www/admin">            #拒绝所有人访问admin目录但允许118访问

        Order  Deny,Allow

        Allow  from  172.25.254.118

        Deny from  All

</Directory>

4.设定用户的访问

htpasswd  -m  /etc/httpd/accessuser   admin

vim  /etc/httpd/conf/httpd.conf

<Directory  "/var/www/admin">

       AuthUserfile  /etc/httpd/accessuser                   #用户认证文件

       AuthName  "Please  input  your  name  and  password !!"  #用户认证提示信息

       AuthType  basic                                        #认证类型

       Require  valid-user                          #认证用户,认证文件中所有用户都可以通过

</Directory>

4.apache语言支持

php    html   cgi

html语言默认支持

php语言

yum install  php -y

cd  /var/www/html

vim index.php

<?php

             phpinfo();

?>

systemctl   restart  httpd

测试 :访问172.25.254.118/index.php

cgi语言

mkdir  /var/www/html/cgi

vim  index.cgi

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print `date`;

vim  /etc/httpd/conf/httpd.conf

<Directory  "/var/www/html/cgi">

         Options  +ExecCGI

         AddHandler  cgi-scripts  .cgi

</Directory>

要给index.cgi文件加可执行权限,selinux不再enforcing状态

systemctl  restart httpd

apache的虚拟主机

1.定义

可以让我们的一台apache服务器在被访问不同域名的时候显示不同的主页

2.建立测试页

mkdir  /var/www/virtual

cd  /var/www

mkdir  virtual/money.westos.com/html  -p

mkdir  virtual/news.westos.com/html  -p

echo  "money.westos.com's page" >virtual/money.westos.com/html/index.html

 

echo  "news.westos.com's page" >virtual/news.westos.com/html/index.html

3.配置

vim  /etc/httpd/conf.d/default.conf       #未指定域名的访问都访问default

<Virtualhost  _default_:80>             #虚拟主机开启的端口

         DocumentRoot   "/var/www/html"   #虚拟主机默认发布目录

        Customlog "logs/default.log" combined    #虚拟主机日志

</Virtualhost>

 

vim /etc/httpd.conf.d/news.conf         #指定域名news.westos.com的访问到指定默认发布目录中

<Virtualhost  *:80>

         ServerName  "news.westos.com"

         DocumentRoot  "/var/www/virtual/news.westos.com/html"

         Customlog  "logs/news.log"  combined

</Virtualhost>

<Directory "/var/www/virtual/news.westos.com/html">  #默认发布目录的访问授权

         Require  all  granted

</Directory>

cp /etc/httpd/conf.d/news   /etc/httpd/conf.d/money

vim  /etc/httpd/conf.d/money

:%s/news/money/g

4.测试

在浏览器所在的主机中

vim  /etc/hosts

172.25.254.118     www.westos.com news.westos.com money.westos.com

 

 

 

 

 

Apache服务器的下载与安装

PHP的运行必然少不了服务器的支持,何为服务器?通俗讲就是在一台计算机上,安装个服务器软件,这台计算机便可以称之为服务器,服务器软件和计算机本身的操作系统是两码事,计算机自身的操作系统可以为linux...

QPC908694753 QPC908694753

2017-02-13 22:16:09

阅读数:13914

apache配置

2017年08月25日 53KB 下载

Apache服务器

2014年11月19日 4.04MB 下载

搭建 Apache Http Server 服务器

本文简单地介绍如何安装和使用 Apache Http Server 服务器。

lzhlzz lzhlzz

2014-09-23 11:53:53

阅读数:35406

Apache 体系结构

Apache采用模块化的体系结构,它的大部分功能都被分割成相互独立的模块,这样的结构可以通过增加和删除模块就可以扩展和修改Apache提供的功能,另一方面,对于Apache 功能的理解也变得非常容易。...

caoshuming_500 caoshuming_500

2012-02-14 15:27:43

阅读数:5464

Linux下启动和停止apache服务

文章作者:Tyan 博客:noahsnail.com  |  CSDN  |  简书 本文使用的Linux系统为CentOS 7,下面将介绍apache服务的启动、关闭与设置。apache在Cen...

Quincuntial Quincuntial

2017-05-27 18:28:17

阅读数:8110

Apache 学习笔记

总结在 Linux 下折腾 apache 遇到的一些问题。

jcjc918 jcjc918

2015-01-28 21:27:03

阅读数:8987

Apache 的 httpd.conf 详解(很实用)

Apache 的 httpd.conf 详解(很实用)   ServerRoot “/usr/local“        ServerRoot用于指定守护进程httpd的运行目录,httpd在...

xys_777 xys_777

2012-01-16 16:34:34

阅读数:29742

<em>apache</em>服务器

<em>apache</em>服务器,非常好用,<em>Apache</em>是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机...

下载

2018年05月16日 00:00

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

听风的鱼鱼儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值