实战CentOS7搭建Apache并且绑定多域名

前言

最近由于需求国外的WEB服务器,所以学习了CentOS7服务器的相关资料,使用Vultr的VPS服务器成功搭建Apache(httpd)以及多域名的配置。
至于Vultr的购买方式请看:https://www.svlik.com/136.html

准备工具:
1.XShell (连接CentOS) 下载地址:https://www.svlik.com/262.html
2.Xftp (上传web页面) 下载地址:https://www.svlik.com/263.html

安装Apache

1.安装Apache:yum install httpd    (提示“Is this ok [y/d/N]”的时候输入Y按回车即可。)
2.启动Apache:service start httpd.service
2.1重启Apache:service restart httpd.service
2.2停止Apache:service stop httpd.service
3.设置自启动:service enable httpd.service
4.检测安装状态:ps -e |grep httpd


此时Apache已经安装完毕。

关闭防火墙

很多人问搭建好了Apache却不能访问,那是因为被防火墙阻止了。你可以输入以下命令停止并禁止防火墙。
1.停止防火墙服务:

service stop firewalld.service

2.禁用防火墙开机启动服务:

service disable firewalld.service

配置Apache

1.使用Xftp进入/etc/httpd/conf/目录并下载httpd.conf文件。
2.使用Notepad+打开你下载的httpd.conf文件并进行以下修改。
3.搜索Directory /修改为以下内容。

<Directory />
Options FollowSymLinks ExecCGI Indexes
AllowOverride None
#Order deny,allow
#Deny from all
Order allow,deny
Allow from all
Satisfy all
</Directory>

4.滑动到最底部,添加如下代码。

<VirtualHost *:80>
DocumentRoot /home/www/www
ServerName www.pcpc.top
ServerAlias pcpc.top
# Other directives here
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /home/www/test1
ServerName test1.pcpc.top
# Other directives here
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /home/www/test2
ServerName test2.pcpc.top
# Other directives here
</VirtualHost>

5.输入service restart httpd.service重启服务器即可完毕。

声明:本文为原创,作者为 Svlik,转载时请保留本声明及附带文章链接:https://www.svlik.com/197.html