Linux下搭建web服务器

一、题目:

1.配置:

//关闭防火墙
[root@client1 ~]# systemctl stop firewalld 
[root@client1 ~]# setenforce  0 

//创建文件夹
[root@client1 conf.d]#  mkdir /www/ip/{129,130} -pv

//将内容写入文件中
[root@client1 conf.d]#  echo welcome to openlab! > /www/ip/129/index.html

//编写配置文件
[root@client1 conf.d]# vim /etc/nginx/conf.d/test_name.conf
server {
        listen 192.168.10.129:80;
        root /www/name/openlab;
        server_name www.openlab.com;
        location / {
                index index.html;
        }
}
[root@client1 conf.d]# systemctl restart nginx

2.编写hosts文件

hosts文件地址:C:\Windows\System32\drivers\etc\hosts

编写ip和域名

 

3. 浏览器访问

4.添加界面

//配置
[root@client1 129]# vim /etc/nginx/conf.d/test_alias.conf 
server {
        listen 192.168.10.129:80;
        root /www/ip/129;
        location /student {
                alias /student/;
        }
}
//创建学生目录
[root@client1 129]# mkdir student
[root@client1 129]# echo "this is student" > student/index.html

//创建教学资料目录
[root@client1 129]# mkdir data
[root@client1 129]# echo "this is data" > data/index.html

//创建缴费网站
[root@client1 129]# mkdir money
[root@client1 129]# echo "this is money" > money/index.html

 5.用户认证

//配置
[root@client1 129]# vim /etc/nginx/conf.d/test_alias.conf
server {
        listen 192.168.10.129:80;
        root /www/ip/129;
        location /student {
                alias /student/;
                auth_basic on;
                auth_basic_user_file /etc/nginx/users;

        }
}
//添加指定登录用户
[root@client1 129]# htpasswd  -c /etc/nginx/users song
New password: 123456
Re-type new password: 
Adding password for user song
[root@client1 129]# htpasswd  -c /etc/nginx/users tian
New password: 123456
Re-type new password: 
Adding password for user tian

//重启nginx服务
[root@client1 129]# systemctl restart nginx 
[root@client1 129]# curl 192.168.10.129/student/ -u song
Enter host password for user 'song':
this is student

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值