一、题目:
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