欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

详解CentOS7安装配置Apache HTTP Server

程序员文章站 2022-12-26 12:49:23
rpm安装httpd # yum -yinstall httpd //安装httpd会自动安装一下依赖包: apr apr-util ht...

rpm安装httpd

# yum -yinstall httpd

//安装httpd会自动安装一下依赖包:

apr

apr-util

httpd-tools

mailcap

# rpm -qi httpd

name    : httpd

version  : 2.4.6

release  : 18.el7.centos

architecture: x86_64

install date: mon 11 aug 2014 02:44:55 pmcst

group   : system environment/daemons

size    : 9793373

license  : asl 2.0

signature : rsa/sha256, wed 23 jul 2014 11:21:22 pm cst, key id 24c6a8a7f4a80eb5

source rpm : httpd-2.4.6-18.el7.centos.src.rpm

build date : wed 23 jul 2014 10:49:10 pm cst

build host : worker1.bsys.centos.org

relocations : (not relocatable)

packager  : centos buildsystem <http://bugs.centos.org>

vendor   : centos

url    : http://httpd.apache.org/

summary  : apache http server

description :

the apache http server is a powerful,efficient, and extensible web server.

修改配置文件

# cd

/etc/httpd/conf

# ls

httpd.conf 

magic

#cp httpd.conf httpd.conf.origin  //将原有配置文件备份

# more httpd.conf

//查看配置文件,我们注意到以一配置:

documentroot"/var/www/html" 

//特别是要注意这个配置

//这是apache 2.4的一个新的默认值,拒绝所有的请求! 

<directory />

  allowoverride none

  require all denied

</directory> 

//设置为自动启动

# systemctl enable httpd.service

ln -s'/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

//在centos7中chkconfig httpd on 被替换成 systemctl enable httpd

配置web站点 (假设使用/wwwroot目录下的文档)

//创建两个网站的目录结构及测试用页面文件

# mkdir/wwwroot/www

# echo"www.bigcloud.local" > /wwwroot/www/index.html 

# mkdir/wwwroot/crm

# echo"crm.bigcloud.local" > /wwwroot/crm/index.html

 //配置虚拟机主机

# cd/etc/httpd/

# mkdirvhost-conf.d

# echo"include vhost-conf.d/*.conf" >> conf/httpd.conf



# vi/etc/httpd/vhost-conf.d/vhost-name.conf

//添加如下内容

<virtualhost *:80>

  servernamewww.bigcloud.local

 documentroot /wwwroot/www/

</virtualhost>

<directory /wwwroot/www/>

  requireall granted

</directory>

 

<virtualhost *:80>

  servernamecrm.bigcloud.local

 documentroot /wwwroot/crm/

</virtualhost>

<directory /wwwroot/crm/>

  require ip192.168.188.0/24  //可以设置访问限制

</directory> 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。