linux搭建web服务器

要求:

1.要求搭建web服务器,能够访问到网页内容为“小胖,你咋这么胖呢!”
2.要求搭建web服务器,创建基于域名的虚拟主机,能够使用www.xiaopang.com和www.dapang.com访问各自的网站网站存放路径分别为/xiaopang和/dapang,内容自定。

配置文件

[root@wxf ~]# cd /etc/httpd/
[root@wxf httpd]# ll
total 0
drwxr-xr-x. 2 root root  37 Aug 16 16:17 conf    //主配置文件
drwxr-xr-x. 2 root root 100 Aug 16 16:24 conf.d  //子配置文件
drwxr-xr-x. 2 root root 226 Aug 15 13:39 conf.modules.d
lrwxrwxrwx. 1 root root  19 May 20 12:33 logs -> ../../var/log/httpd
lrwxrwxrwx. 1 root root  29 May 20 12:33 modules -> ../../usr/lib64/httpd/modules
lrwxrwxrwx. 1 root root  10 May 20 12:33 run -> /run/httpd
lrwxrwxrwx. 1 root root  19 May 20 12:33 state -> ../../var/lib/httpd

在子配置文件夹目录下创建一个vhost.conf(文件名自取),编辑文件

<VirtualHost 192.168.190.130:80>  //主机名(ip地址)
        DocumentRoot /www/130   //文件位置
        ServerName 192.168.190.130
</VirtualHost>               

<Directory /www>        //能访问的目录权限      
        AllowOverride none   //不覆盖
        Require all granted   //表示同意访问该目录下的文件
</Directory>

然后在文件位置/www/130 下创建html文件

[root@wxf conf]# pwd
/etc/httpd/conf
[root@wxf conf]# ll
total 28 
-rw-r--r--. 1 root root 11926 Aug 16 16:16 httpd.conf    //主配置文件
-rw-r--r--. 1 root root 13064 May 20 12:33 magic

先访问一下主配置文件

<IfModule dir_module>
    DirectoryIndex index.html    //这一项表示能够访问的网页文件
</IfModule>                                          

这里只允许一个index.html 文件,所以在/www/130下创建文件是名字一定要取index.html,否则将无法访问网页(403)如果要改名字或者添加文件类型,要在该主配置文件里,index.html 后面把要加的补上去,比如index.css/130.html 等等

来到网页文件目录下创建index.htm

[root@wxf 130]# echo '小胖,你咋这么胖呢!' > index.html
[root@wxf 130]# cat index.html 
小胖,你咋这么胖呢!

重启httpd服务            (首先得关闭防火墙和selinux)

[root@wxf 130]# systemctl stop firewalld
[root@wxf 130]# systemctl stop selinux
[root@wxf 130]# systemctl restart httpd

 //disable  关闭开机启动

 进入浏览器输入IP即可

一对多(一个IP多个域名)

进入刚刚创建的子配置文件vhost.conf 重新编辑

<VirtualHost 192.168.190.130:80>
        DocumentRoot /xiaopang
        ServerName www.xiaopang.com   //域名
</VirtualHost>

<VirtualHost 192.168.190.130:80>
        DocumentRoot /dapang
        ServerName www.dapang.com
</VirtualHost>


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

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

再在各个目录下创建每个域名所对应的index.html,重启httpd   

修改host文件

在windows下

 hosts文件 添加 ip对应的域名信息

(最后两行是新加的) 保存退出 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿巴阿巴巴bbb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值