Centos Apache服务搭建

前言:

总结下搭建Apache服务

Apache相关文件:

apache配置文件

/etc/httpd/conf/httpd.conf

默认网页保存位置

/var/www/html

日志保存位置

/var/log/httpd

Centos Apache服务搭建_第1张图片

配置Apache

关闭防火墙和selinux

iptables -F
setenforce 0

首先使用yum下载httpd服务

yum install httpd

Centos Apache服务搭建_第2张图片
下载好之后,修改配置文件,先进行配份,以免修改错误

cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

启动服务

service httpd start

Centos Apache服务搭建_第3张图片
安装成功,接下来换下域名访问,由于是本机测试,所以直接修改/etc/hosts文件即可
Centos Apache服务搭建_第4张图片
修改配置文件,直接用命令模式/字符查找ServerName会快些
Centos Apache服务搭建_第5张图片
修改完之后需要重启服务
Centos Apache服务搭建_第6张图片
访问成功

建立虚拟主机

Centos Apache服务搭建_第7张图片
配置文件中给出有例子,参考例子进行修改就好了
Centos Apache服务搭建_第8张图片
目录需要我们手动去建立并在目录下写入首页index.html

[root@lemon www]# mkdir /var/www/test1
[root@lemon www]# mkdir /var/www/test2
[root@lemon www]# vi /var/www/test1/index.html
[root@lemon www]# vi /var/www/test2/index.html

另外也要修改下hosts文件
Centos Apache服务搭建_第9张图片
重启服务进行测试
Centos Apache服务搭建_第10张图片
Centos Apache服务搭建_第11张图片
测试成功

建立虚拟目录

只需要在虚拟主机配置文件下加上Alias关键字即可,具体如下:
Centos Apache服务搭建_第12张图片
同样这个目录也是需要自己建立的

mkdir /tmp/zzh
vi /tmp/zzh/index.html

如果出现403,看下是不是防火墙和selinux没有关
Centos Apache服务搭建_第13张图片
测试成功

你可能感兴趣的:(Linux)