Linux搭建web服务器---静态网站

发布于:2023-01-04 ⋅ 阅读:(423) ⋅ 点赞:(0)

搭建web服务器

三种实例:

1.多ip多网站搭建

2.多端口多网站搭建

3.多域名多网站搭建

实例1.多ip多网站搭建

前提配置:

添加多ip

#nmcli connection modify ens160 ipv4.method manual ipv4.addresses 192.168.10.134/24 +ipv4.addresses 192.168.10.135/24 +ipv4.addresses 192.168.10.136/24 ipv4.gateway 192.168.10.2 ipv4.dns 192.168.10.2 connection.autoconnect yes

#nmcli connection up ens160

 

server主机配置

1.安装web服务包 yum install httpd -y

2.关闭selinux,firewalld

#systemctl stop firewalld

#setenforce 0

3.根据需求更改配置文件

cat /usr/share/doc/httpd/httpd-vhosts.conf 虚拟主机标签的示例参考文件

vim /etc/httpd/conf.d/vhosts.conf 进入配置文件

<VirtualHost 192.168.159.132:80> 虚拟主机标签

DocumentRoot /www/134

ServerName 192.168.159.132 </VirtualHost>

<Directory /www> 目录权限

AllowOverride none #不允许覆盖

Require all granted #所有的客户端主机允许访问

</Directory>

<Virtualhost 192.168.159.131:80>

DocumentRoot /www/135

ServerName 192.168.159.131

</VirtualHost>

<Virtualhost 192.168.159.130:80>

DocumentRoot /www/136

ServerName 192.168.159.130

</VirtualHost>

4.根据配合创建对应资源目录、文件

#mkdir /www/{134,135,136} -pv

#echo this is 134 > /www/134/index.html #添加网站测试界面

#echo this is 135> /www/135/index.html

echo this is 136 > /www/136/index.html

5.重启服务

#systemctl restart httpd

 

6.测试:命令行测试: curl http://ip

网页测试:

 

 

 

实例2.多端口多网站搭建

前提准备如上,然后

1.编辑虚拟用户配置文件:vim /etc/httpd/conf.d/vhost.conf

<VirtualHost 192.168.159.132:9999>

DocumentRoot /net/9999

ServerName 192.168.159.132

</VirtualHost>

<VirtualHost 192.168.159.132:8096>

DocumentRoot /net/8096

ServerName 192.168.159.132

</VirtualHost>

<Directory /net> AllowOverride none Require all granted </Directory>

listen 9999

listen 8096

2.创建对应的文件夹和html文件

#mkdir /net/{9999,8096} -pv

#echo this is 9999 > /net/9999/index.html #添加网站测试界面

#echo this is 8096> /net/8096/index.html

3.重启httpd服务

systemctl restart httpd

 

 4.测试

 

 实例3.多域名多网站搭建

前提配置如上;

1.编辑虚拟用户配置文件:vim /etc/httpd/conf.d/vhost.conf

 

2.创建对应的文件夹和html文件

#mkdir /net/{xixi,haha} -pv

#echo this is xixi > /net/xixi/index.html #添加网站测试界面

#echo this is haha> /net/haha/index.html

3.重启httpd服务

 4.编辑  /etc/hosts 文件

vim /etc/hosts 

 添加xixi和haha的hosts域名解析文件

5.测试

 如果想要在网页上显示 则编辑Windows下的hosts域名解析文件(C:\Windows\System32\drivers\etc\hosts),指定xixi和haha对应自己的IP

192.168.159.132 www.xixi,com

192.168.159.132 www.haha.com

排错总结

httpd -t 检测配置语法

systemctl status httpd | cat 检错

大多数服务起不来是因为语法不规范出了问题  所以多检查配置

vim /etc/httpd/conf.d/vhost.conf

还有最重要一点就是本地的yum源要配置好  配置好 配置好(重要事情说三遍)

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到