Centos7 web简单配置

准备

Centos7 1台 ,一台win2008DNS服务,一台web服务 一台win7 验证

web服务器ip为192.168.100.102

dns服务器ip为 192.168.100.103

win为 192.168.100.104

Xhell连接

centos apache 跳转 centos7 apache常规配置_centos7 web简单配置


挂上centos7光盘并mount /dev/cdrom /mnt

配置yum源

vim /etc/yum.repos.d/centOS7.repo

后面的repo文件可能不一样,如果没有可以自行创建

里面这样写

centos apache 跳转 centos7 apache常规配置_Centos7 apache简单配置_02


mnt为光盘挂载目录

安装httpd服务

1.准备工作

rpm -e hhtpd --nodeps 卸载原来的httpd避免冲突

安装基础包

我这里打的是个文件,你们需要在命令行依次执行

我第2行打错了

是 yum -y install pcre*

centos apache 跳转 centos7 apache常规配置_centos7 web简单配置_03


2.源码编译安装

1.把httpd压缩包拖到xhell中

并解包

centos apache 跳转 centos7 apache常规配置_Centos7 apache简单配置_04


tar zxf httpd-2.4.25.tar.gz -C /usr/src/
cd /usr/src/httpd-2.4.25/

2.配置

./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi

后面的 --enable 是一些定制功能本教程是基本配置这里不阐述

3.编译及安装

make :编译

make install :安装

4.确认安装结果

centos apache 跳转 centos7 apache常规配置_vim_05


4 优化执行程序

因为通过源码安装的httpd服务,程序路径并不在默认的搜索路径中

ln -s /usr/local/httpd/bin/* /usr/local/bin

httpd -v 可以查看版本

5.添加httpd系统服务

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

通过chkconfig 添加为系统服务

vim /etc/init.d/httpd

添加图中选项

centos apache 跳转 centos7 apache常规配置_Centos7 apache简单配置_06


chkconfig --add httpd 将httpd添加为系统服务

注意如果报错http不支持ch什么的就是刚刚我那行格式写错了

意思是服务器识别参数

在级别3 5 中启动 启动和关闭的顺序分别为 85 21

开机自启

centos apache 跳转 centos7 apache常规配置_服务器_07

httpd服务器基本配置

1.配置win2008的dns服务 ,如果不想配置也可以过掉,用ip访问网站

2.配置并启动httpd服务

配置

vim /usr/local/httpd/conf/httpd.conf

找到ServerName配置项

附近添加如下内容

centos apache 跳转 centos7 apache常规配置_服务器_08


设置本地网站名称,可以和dns域名不一样只是本地的名称

apachectl -t :检查显示ok表示没问题

启动 httpd服务

systemctl start httpd
netstat -anpt

centos apache 跳转 centos7 apache常规配置_centos apache 跳转_09


3.部署网页文档

我们可以自己设置网页的默认首页

首先 cd /usr/local/httpd/htdocs/

删掉 index.html

touch ajbn.html :文件名可以自定义

centos apache 跳转 centos7 apache常规配置_Centos7 apache简单配置_10


vim /usr/local/httpd/conf/httpd.conf
找到index.html选项 加上

centos apache 跳转 centos7 apache常规配置_服务器_11


要和前面创建的文件名字一致

systemctl restart httpd 重启服务生效

4.客户机访问

配置一个网段并 指向DNS服务器

centos apache 跳转 centos7 apache常规配置_服务器_12


centos apache 跳转 centos7 apache常规配置_centos7 web简单配置_13


实验完成