linux搭建web服务

鹅鹅根据相关要求搭建

临时关闭防火墙和selinux

[root@localhost etc]# systemctl stop firewalld
[root@localhost etc]# setenforce 0

一 练习题

1.搭建web服务器,访问到 "小胖,你咋这么胖"

/etc/httpd/conf.d     子配置目录(自定义的配置文件)

在vim etc/httpd/conf.d/fhosts.d 进行配置

<virtualHost 192.168.171.129>
        DocumentRoot "/fast/129"
        ServerName 192.168.171.129
</virtualHost>

<Directory /fast>
        AllowOverride none
        Require all granter
</Directory> 

mkdir /fast/129
echo 小胖,你咋这么胖 > /fast/129/index.html
systemctl restart httpd

 

 访问成功了!!!

2.创建基于域名的的虚拟主机

 继续在原配置中做修改ewe1e1

<virtualHost 192.168.171.129>
	DocumentRoot "/xiaopang"
	ServerName www.xiaopang.com
</virtualHost>

<virtualHost 192.168.171.129>
        DocumentRoot "/dapang"
        ServerName www.dapangpang.com
</virtualHost>


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

<Directory /dapang>
        AllowOverride none
        Require all granted
</Directory>
 mkdir /xiaopang
 mkdir /dapang
 echo  i am big fat > /dapang/index.html
 echo  i am small fat > /dapang/index.html
systemctl  restart httpd

注意:域名访问需要在文件下面注册 

 

 成功了!!

 3.创建虚拟目录

 

<virtualHost 192.168.171.129>
        DocumentRoot "/xiaopang"
        Alias /x     /xiaopang/129
        ServerName 192.168.171.129
</virtualHost>
<Directory>
        AllowOverride none
        Require all granted
</Directory>

mkdir /xiaopang/129
echo i am 129 > /xiaopang/129/index.html
systemctl restart httpd

 

 成功访问!!!!

4.创建虚拟网络,允许abc和xyz访问

<v<virtualHost 192.168.171.129>
       DocumentRoot "/xiaopang"
       Alias /x     /xiaopang/129
       ServerName 192.168.171.129
</virtualHost>
<Directory /xiaopang>
       AllowOverride none
       Require all granted
</Directory>
<Directory /xiaopang/129>
	AuthType Basic
	AuthName "please login:"
	AuthuserFile /etc/httpd/userfile
	Require user abc xyz
</Directory>

 

 

 成功了!!

5.真题 

<virtualHost 192.168.171.129>
       DocumentRoot "/xiaopang"
       Alias /student     /xiaopang/student
       Alias /data        /xiaopang/data
       Alias /moeny       /xiaopang/money
       ServerName 192.168.171.129
</virtualHost>
<Directory /xiaopang>
       AllowOverride none
       Require all granted
</Directory>
<Directory /xiaopang/student>
        AuthType Basic
        AuthName "please login:"
        AuthuserFile /etc/httpd/userfile
        Require user song tian
</Directory>

<VirtualHost 192.168.171.129>
        DocumentRoot "/xiaopang/money"
        ServerName 192.168.171.129
        SSLEngine on
        SSLCertificateFIle    /etc/pki/tls/certs/openlab.crt
        SSLCertificateKeyFile /etc/pki/tls/private/openlab.key
</Virtualhost>

设置song和tian的密码

htpasswd -c /etc/httpd/userfile song
Adding password for user song
htpasswd -c /etc/httpd/userfile tian
Adding password for user tian

 添加用户数据

 echo this is a stydent! > /xiaopang/student/index.html
 echo this is a data! > /xiaopang/data/index.html
 echo this is money! > /xiaopang/money/index.html

 

 搭建https加密

cd /etc/pki/tls/certs
 openssl req -newkey rsa:4096 -nodes -sha256 -keyout ../private/openlab.key  -x509 -days 365 -out openlab.crt

 

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值