参考:https://blog.csdn.net/az44yao/article/details/8750400
1.下载httpd并开启Apache 服务
(1)下载httpd
yum install httpd
(2)开启httpd服务
systemctl start httpd
(3)关闭防火墙
systemctl stop firewalld
(4)打开浏览器,在地址栏中输入 127.0.0.1:800 结果如下(端口转发 800->80)
2.单站点网络发布
(1)切换到网页目录下
cd /var/www/html/ (切换到此目录)
(2)创建index.html文件,并写入一些内容(如下图)
touch index.html (创建文件)
vi index.html (编辑文件)
(3)重启Apache服务
systemctl restart httpd
(4)打开浏览器,在地址栏中输入 127.0.0.1:800/index.html 结果如下
3.虚拟目录的发布
(1)切换到网页目录下
cd /var/www/
(2)分别创建alias1和alias2两个目录,并写入相应内容(此处以alias1为例)
mkdir alias1
cd /alias1
touch index.html
vi index.html
(3)创建相应的配置文件
cd /etc/httpd/
mkdir test-conf.d
cd test-conf.d/
touch test.conf
vi test.conf
(4)复制下面的内容到上面的配置文件内
- #Documentroot:站点目录
- #Alias:映射URL到文件系统的特定区域
- #Directory:定义目录访问权限
- #ServerName:访问域名
- #ServerAlias:给虚拟主机增加多个域名,上面网址的别名
- #<Directory “/”>:权限设置,标签中的地址是相对于DocumentRoot的
<VirtualHost *:80>
ServerAdmin root@localhost
Documentroot /var/www/
Alias /index /var/alias1
Alias /index1 /var/alias2
<Directory "/var/www/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
(5)引用上面的配置文件
vi /etc/httpd/conf/httpd.conf
IncludeOptional test-conf.d/*.conf (将此句复制到文件中)
(6)重启Apache服务
systemctl restart httpd
(7)打开浏览器进行网页访问测试
4.多端口发布(利用3中的目录以及文件进行操作)
(1)这里仍然使用3中所创建的alias1和alias2两个目录文件为例
(2)打开3中配置文件
vi /etc/httpd/test-conf.d/test.conf
(3)复制下面的内容到上面的配置文件内
<VirtualHost *:80>
ServerAdmin root@localhost
DocumentRoot /var/www/alias1
<Directory "/var/www/alias1">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:82>
ServerAdmin root@localhost
DocumentRoot /var/www/alias2
<Directory "/var/www/alias2">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
(4)添加监听端口如下图
vi /etc/httpd/conf/httpd.conf
(5)配置端口转发 800->80,802->82
(6)关闭selinux防火墙(会阻断端口)
setenforce 0
(7)重启重启Apache服务
systemctl restart httpd
(8)打开浏览器进行网页访问测试
5.多域名发布
(1)这里仍然使用3中所创建的alias1和alias2两个目录文件为例
(2)编辑配置文件
vi /etc/httpd/test-conf.d/test.conf
(3)将下列代码复制进去
<VirtualHost *:80>
ServerAdmin root@localhost
ServerName www.yi.com
DocumentRoot /var/www/alias1
<Directory "/var/www/alias1">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin root@localhost
ServerName www.two.com
DocumentRoot /var/www/alias2
<Directory "/var/www/alias2">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
(4)重启重启Apache服务
systemctl restart httpd
(5)编辑本地 hosts 文件,其文件路径为 C:\Windows\System32\drivers\etc\hosts,hosts 文件,添加下图内容
(6)打开浏览器进行网页访问测试