web——搭建静态网站——基于http协议的静态网站

实验 4 :建立两个基于域名访问的网站,要求如下:
新建一个网站,域名为 www.ceshi.com ,设置网站首页目录为 /www/name ,网页内容为 this is
test
新建一个网站,域名为 rhce.first.day ,同时可通过 ce.first.day 访问,设置网站首页目录
/www/ce, 网页内容为: today is first day of class
重启
实验 5 :基于虚拟目录和用户控制的 web 网站
# 虚拟目录实现
[root@localhost conf.d] # nmcli connection modify ens33 +ipv4.addresses
192.168.231.103/24
[root@localhost conf.d] # nmcli connection up ens3160
[root@localhost ~] # vim /etc/nginx/conf.d/test_virtualdir.conf
server {
listen 192 .168.231.103:80;
root /usr/share/nginx/html;
location /real {
alias /www/real;
}
}
[root@localhost ~] # mkdir /www/real/
[root@localhost ~] # echo real-virtual > /www/real/index.html
[root@localhost ~] # systemctl restart nginx
[root@localhost ~] # curl 192.168.231.103/real/
real-virtual
# 用户访问控制
[root@localhost ~] # vim /etc/nginx/conf.d/test_virtualdir.conf
server {
listen 192 .168.168.155:80;
root /usr/share/nginx/html;
location /real {
alias /www/real;
auth_basic on;
auth_basic_user_file /etc/nginx/conf.d/auth-password;
}
}
[root@localhost ~] # dnf install httpd-tools -y
[root@localhost ~] # htpasswd -cb /etc/nginx/conf.d/auth-password user1
123456
[root@localhost ~] # systemctl restart nginx            重启
[root@localhost ~] # curl 192.168.168.155/real/
<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
[root@localhost ~] # curl 192.168.168.155/real/ -u user1
Enter host password for user 'user1' :
real-virtual
[root@localhost ~] # curl user1:123456@192.168.168.155/real
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
[root@localhost ~] # curl user1:123456@192.168.168.155/real/
real-virtual
[root@localhost ~]# htpasswd -cb /etc/nginx/conf.d/auth-password user1 123456
Adding password for user user1
[root@localhost ~]# systemctl restart nginx.service 

相关推荐

  1. 阿里云服务器 篇二:静态网站

    2024-07-22 18:42:04       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-22 18:42:04       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-22 18:42:04       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-22 18:42:04       45 阅读
  4. Python语言-面向对象

    2024-07-22 18:42:04       55 阅读

热门阅读

  1. Oracle(15)什么是索引(Index)?

    2024-07-22 18:42:04       14 阅读
  2. CSS 的@media规则,响应式的一种解决方案

    2024-07-22 18:42:04       12 阅读
  3. MySQL

    MySQL

    2024-07-22 18:42:04      16 阅读
  4. C++中的atomic:原子

    2024-07-22 18:42:04       14 阅读
  5. Nacos 面试题及答案整理,最新面试题

    2024-07-22 18:42:04       20 阅读
  6. 【Unity】RPG2D龙城纷争(十五)特殊加成型要诀

    2024-07-22 18:42:04       17 阅读