Apache网站搭建发布(基于centos 7.9)

1、安装httpd服务

yum -y install httpd

2、网页测试

关闭防火墙:systemctl stop firewalld
                     systemctl disable firewalld
关闭selinux:setenforce 0

                    vim /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

#在web端输入自己得服务器IP ,显示如下,即安装成功

 3、网站发布

Apache默认的网站发布目录在/var/www/html下,讲源码信息放到此网站即可。

*一般网页发布,不可能只发布一个网页,而且大多数情况下,公司考虑预算情况,也不可能增设多台服务器,这也会造成服务器资源得浪费,所以下面,我们配置一下怎么在一台服务器上用Apache服务发布多个网站

Apache有一个默认配置文件在/etc/httpd/conf/httpd.conf(主配置文件)

如果想多网站发布,需在/etc/httpd/conf.d/下面创建次配置文件,用test.conf次配置文件为例,里面内容如下。

<VirtualHost *:80>   #指定虚拟主机端口,*代表监听本机所有ip,也可以指定ip
DocumentRoot /soso     #指定发布网站目录,自己定义
ServerName www.soso666.com  #指定域名,可以自己定义
<Directory "/soso/">
  AllowOverride None    #设置目录的特性,不设置目录的特性
  Require all granted   #允许所有人访问
</Directory>
</VirtualHost>

一、基于端口发布

1、在主配置文件中加入不同的端口,例:3000、4000

vim /etc/httpd/conf/httpd.conf

2、更改次配置文件信息

vim /etc/httpd/conf.d/test.conf
<VirtualHost *:3000>  
DocumentRoot /web/3000/    
#ServerName www.soso666.com 
<Directory "/web/3000">
  AllowOverride None    
  Require all granted   
</Directory>
</VirtualHost>




<VirtualHost *:4000>  
DocumentRoot /web/4000/    
#ServerName www.soso666.com 
<Directory "/web/4000">
  AllowOverride None    
  Require all granted   
</Directory>
</VirtualHost>

4、在3000的发布目录/tmp/3000下面创建一个index.html文件,在里面随便写入内容作为后续测试,例:echo "我是3000端口测试" > /web/3000/index.html

在4000的发布目录做同样操作

 echo "我是4000端口测试" > /web/4000/index.html

注:其中/web/4000/和/web/3000/为两个网页的指定发布目录

5、重启Apache服务  

systemctl restart httpd

6、打开网页测试

10.36.192.217:3000

10.36.192.217:4000 

二、基于域名发布

1、修改主配置文件,只设置一个监听端口

2、修改次配置文件,讲发布端口修改成80,域名打开或增加

<VirtualHost *:80>
DocumentRoot "/web/3000/"
ServerName www.3000test.com
<Directory "/web/3000/">
  AllowOverride None
  Require all granted
</Directory>
</VirtualHost>




<VirtualHost *:80>
DocumentRoot "/web/4000/"
ServerName www.4000test.com
<Directory "/web/4000/">
  AllowOverride None
  Require all granted
</Directory>
</VirtualHost>

注:因为我是用的是虚拟机,所以需要在windows里面配置本地域名解析,文件在 C:\Windows\System32\drivers\etc下的hosts文件,在最后另起一行加入

 3、重启Apache服务

systemctl restart httpd

4、网页测试

www.4000test.com

www.3000test.com

三、基于IP发布 

1、添加一个虚拟IP

ip a a 10.36.192.18 dev ens33

2、修改次配置文件

<VirtualHost 10.36.192.217:80>
DocumentRoot "/web/3000/"
#ServerName www.3000test.com 
<Directory "/web/3000/">
  AllowOverride None
  Require all granted
</Directory>
</VirtualHost>




<VirtualHost 10.36.192.18:80>
DocumentRoot "/web/4000/"
#ServerName www.4000test.com 
<Directory "/web/4000/">
  AllowOverride None
  Require all granted
</Directory>
</VirtualHost>
~               

3、网页测试

10.36.192.217

10.36.192.18

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值