Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一,Apache的主程序名为httpd。
1.关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld && setenforce 0
2、yum安装,开启,查看apache端口
[root@localhost ~]# yum install -y httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# netstat -lntp | grep 80 #apache的端口为80,net-tools
index.html :默认访问网站的主页名称
默认发布网站的目录:/var/www/html
3、编写测试页面,并访问
[[email protected] ~]# echo dir1 > /var/www/html/index.html
apache 安装完成
将http.conf文档复制并去掉httpd.conf的#
去掉httpd.conf里面的空行
[root@localhost ~]# cd /etc/httpd/conf/
[root@localhost conf]# sed -i.back '/#.*/' httpd.conf
[root@localhost conf]# sed -i '/^$/d' httpd.conf
vim /etc/httpd/conf/httpd.conf 编辑配置文件
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
systemctl restart httpd 重启httpd
vim /etc/httpd/conf/httpd.conf
Options Indexes FollowSymLinks
AllowOverride None
Require not ip 10.36.192.24 10.36.192.25 #将不允许访问的客户端IP写在这里,以空格隔开
Require all granted
systemctl restart httpd #重启httpd
vim /etc/httpd/conf/httpd.conf
Options Indexes FollowSymLinks
AllowOverride None
Require ip 10.36.192.16
systemctl restart httpd
vim /etc/httpd/conf/httpd.conf
Options Indexes FollowSymLinks
AllowOverride None
Require all deined
systemctl restart httpd
[root@localhost ~]# mkdir /web
[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf
DocumentRoot "/web" # 修改网站根目录为/web
# 把这个也对应的修改为/web
[root@localhost ~]# vim index.html
这是一个测试页面
[root@localhost ~]# systemctl restart httpd
虚拟主机:将多个网站放在同一台服务器上
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd"
Listen 90
Listen 100 #添加端口
[root@localhost dir2]# vim /etc/httpd/conf.d/test.conf
DocumentRoot /web/dir1
AllowOverride None
Require all granted
DocumentRoot /web/dir2
AllowOverride None
Require all granted
[root@localhost ~]# mkdir /web/dir1
[root@localhost ~]# mkdir /web/dir2
[root@localhost ~]# touch /web/dir1/index.html
[root@localhost ~]# touch /web/dir2/index.html
将前端代码发布到index.html中
[root@localhost ~]# vim /etc/httpd/conf.d/test.conf
DocumentRoot /web/dir1
ServerName www.zhangxiao.com
AllowOverride None
Require all granted
DocumentRoot /web/dir2
ServerName www.zx.com
AllowOverride None
Require all granted
[root@localhost~]# systemctl restart httpd
C:\Windows\System32\drivers\etc
10.36.192.66 www.zhangxiao.com
10.36.192.66 www.zx.com
[root@localhost ~]# ip a a 10.36.192.188 dev ens33
[root@localhost ~]# vim /etc/httpd/conf.d/test.conf
DocumentRoot /web/dir1
AllowOverride None
Require all granted
DocumentRoot /web/dir2
AllowOverride None
Require all granted
[root@localhost ~]# systemctl restart httpd