Centos7 yum 源搭建 Appache httpd 单站点 多站点配置

Centos7 yum 源搭建 Appache httpd 单站点 多站点配置

1.安装

yum install httpd 

2.启动

由于httpd安装好后其服务器默认端口为80端口,如果安装了nginx 或者其他服务的话,需要注意端口是否被占用

查看80是否被占用,如果被占用了需要更改httpd端口或者已占用80端口服务

netstat -untlp|grep 80

启动httpd服务

systemctl start httpd

访问

如果未更改httpd默认端口 启动后访问 虚拟机ip即可  查看是否出现页面,出现
其默认页面则说明httpd服务已启动并且可以工作
3.说明(单站点部署)

yum源安装的httpd服务器其配置文件位置在/etc/httpd 目录下

httpd服务器默认是占用80端口,其默认文件的加载位置在/var/www/html/

就是说,如果要部署纯前端html文件的话。将所有文件放在/html/下即可

html 下直接放要加载的文件 ,不需要在加一个文件夹来存放需要布置的项目资源

exmaple:

[root@alibyleilei conf]# cd /var/www/html
[root@alibyleilei html]# ll
total 344
-rw-r--r-- 1 root root  6617 Jan 21 10:46 aboutUS.html
drwxr-xr-x 2 root root  4096 Jan 21 10:47 css
-rw-r--r-- 1 root root  8472 Jan 21 10:46 disputeResolution.html
drwxr-xr-x 2 root root  4096 Jan 21 10:47 doc
-rw-r--r-- 1 root root     0 Jan 21 10:46 favicon.ico
-rw-r--r-- 1 root root 12395 Jan 21 10:46 findPassword.html
-rw-r--r-- 1 root root 34814 Jan 21 10:46 gameagreement.html
-rw-r--r-- 1 root root  7065 Jan 21 10:46 gameNotice.html
drwxr-xr-x 2 root root 12288 Jan 21 10:46 img
-rw-r--r-- 1 root root 16720 Jan 21 10:46 index.html
drwxr-xr-x 2 root root  4096 Jan 21 10:46 js
-rw-r--r-- 1 root root 10177 Jan 21 10:46 login.html

那么当我吧我的项目放在/var/www/html/下后 访问虚拟机ip 那么就会进入到我项目的index.html页面

到此,单站点项目就部署完成了


多站点部署(配置多个虚拟主机)

一个虚拟机上需要部署多个类似的纯前端资源 那么一个/var/www/html/是不够的,我们需要额外做些配置

(1)新建配置文件

进入配置目录

cd /etc/httpd/

发现里边有许多文件以及文件夹

drwxr-xr-x 2 root root 4096 Jan 21 11:59 conf
drwxr-xr-x 2 root root 4096 Jan 21 11:58 conf.d
drwxr-xr-x 2 root root 4096 Jan 21 10:34 conf.modules.d
lrwxrwxrwx 1 root root   19 Jan 21 10:34 logs -> ../../var/log/httpd
lrwxrwxrwx 1 root root   29 Jan 21 10:34 modules -> ../../usr/lib64/httpd/modules
lrwxrwxrwx 1 root root   10 Jan 21 10:34 run -> /run/httpd

我们多站点部署呢,需要进入conf.d目录下

cd conf.d/

创建一个配置文件

touch vhost.conf
(2)修改新建的配置文件
vim /etc/httpd/conf.d/vhost.conf

编辑保存内容如下

# 测试网站一  存放默认httpd80端口的文件
<VirtualHost *:80>
#绑定的主域
#ServerName test.com
#绑定的子域名
#ServerAlias www.test.com
#网站主目录
DocumentRoot /var/www/html
#日志配置
#ErrorLog /home/web_log/com.test.www_error.log
#CustomLog /home/web_log/com.test.www_access.log common
#ServerSignature Off
</VirtualHost>
#测试一的配置
<Directory "/var/www/html">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
    Allow from All
</Directory>


# 测试网站二
<VirtualHost *:85>
#绑定的主域
#ServerName test.com
#绑定的子域名
#ServerAlias www.test.com
#网站主目录
DocumentRoot /var/www/html2
#日志配置
#ErrorLog /home/web_log/com.test.www_error.log
#CustomLog /home/web_log/com.test.www_access.log common
#ServerSignature Off
</VirtualHost>
#测试二的配置
<Directory "/var/www/html2">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
    Allow from All
</Directory>

那么在上方的配置文件中呢,访问80端口httpd服务器就会去/var/www/html/下去寻找前端资源 ,同理访问85端口 httpd服务器就会去/var/www/html2/下寻找前端资源(/var/www/html2/ 为我自定义目录,可根据运维意愿自己变更)

(3)监听新站点85端口

vim /etc/httpd/conf/ httpd.conf

文件中部分内容如下

#Listen 12.34.56.78:80
Listen 80

我们需要监听在前文配置文件中新加的站点端口 例如我配置的“85”

Listen 85

保存退出 创建85监听站点的前端资源存放目录

mkdir -p /var/www/html2/

将需要部署的另一个前端资源存在此目录下即可

(3)重启httpd服务器

systemctl restart httpd

通过虚拟机ip :80 虚拟机ip:85 查看以及访问两个部署的前端资源即可

3.注意事项

1.防火墙/安区组 问题

如果如果服务器已开启防火墙 那么需要开放前端资源服务器对应的端口,云服务器的话还需要开放对应的安全组

2.端口问题

需要注意端口是否被占用

4.Tips

httpd服务器单站点 多站点 部署到这里就完成了,需要再加更多站点的话,照着模子刻就完事了…

发布了31 篇原创文章 · 获赞 23 · 访问量 3793

猜你喜欢

转载自blog.csdn.net/leilei1366615/article/details/104062137