学习目标:
- 实验
- 实验需求
- 实验配置内容和分析 (每一个设备的每一步操作)
- 实验结果验证
- 其他
学习内容:
- 实验
- 实验需求
- 实验配置内容和分析 (每一个设备的每一步操作)
- 实验结果验证
- 其他
目录
修改默认 端口、文件、目录 【nginx的端口,默认发布文件,默认发布目录等配置】
1.实验
2.实验需求
图+文字
3.实验配置内容和分析 (每一个设备的每一步操作)
wed服务【nginx的安装与启用】
dnf install nginx -y
systemctl enable --now nginx
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
firewall-cmd --list-all
cd /usr/share/nginx/html/
ls
echo timinglee > index.html
cat index.html
netstat -antlupe | grep nginx
ll /etc/nginx/
修改默认 端口、文件、目录 【nginx的端口,默认发布文件,默认发布目录等配置】
vim /etc/nginx/nginx.conf
worker_processes auto;(mask下worker
worker_connections
server
listen :xx;
nginx -s reload
netstat -antlupe grep nginx
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
cd /usr/share/nginx/html/
vim test.html
vim /etc/nginx/nginx.conf
index xxx1 xxx2;
index test.html index.html;
nginx -t
nginx -s reload
rm -fr test.html
mkdir /usr/share/nginx/tininglee
echo tininglee > /usr/share/nginx/tininglee/index.html
cat /usr/share/nginx/tininglee/index.html
cd /usr/share/nginx
vim /etc/nginx/nginx.conf
root xxx;
root /usr/share/nginx/tininglee;
root /usr/share/nginx/html;
nginx -s reload
web服务器的访问控制【nginx的访问控制】
cd /usr/share/nginx/html/
mkdir lee
echo lee > lee/index.html
curl 192.168.23.131/lee/
vim /etc/nginx/nginx.conf
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /lee/{
allow 192.168.23.131;
deny all;
}
}
nginx -s reload
curl 192.168.23.131
dnf install httpd-tools -y
htpasswd -cm /etc/nginx/.htpasswd lee
vim /etc/nginx/nginx.conf
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /lee/ {
auth_basic on;
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
nginx -s reload
curl -u lee:lee 192.168.23.131/lee/
【nginx的虚拟主机】
ip a a 192.168.23.10/24 dev ens160
ip a a 192.168.23.20/24 dev ens160
mkdir /usr/share/nginx/virtualhost/{news,bbs} -p
echo 192.168.23.10 > /usr/share/nginx/virtualhost/news/index.html
echo 192.168.23.20 > /usr/share/nginx/virtualhost/bbs/index.html
include /etc/nginx/conf.d/*.conf
cd /etc/nginx/conf.d/
vim vhosts.conf
listen 172.25.254.10:80;
server {
listen 192.168.23.10;
root /usr/share/nginx/virtualhost/news/;
index index.html;
}
server {
listen 192.168.23.20;
root /usr/share/nginx/virtualhost/bbs/;
index index.html;
}
nginx -s reload
vim vhosts.conf
server {
listen 80;
server_name news.timinglee.org;
root /usr/share/nginx/virtualhost/news/;
index index.html;
}
server {
listen 80;
server_name bbs.timinglee.org;
root /usr/share/nginx/virtualhost/bbs/;
index index.html;
}
nginx -s reload
news.timinglee.org
(本地磁盘(C:)Windows>System32 > drivers > etc>hosts)
vim /etc/hosts
192.168.23.131 www.timinglee.org bbs.timinglee.org news.timinglee.org
ping www.timinglee.org
ping news.timinglee.org
ping bbs.timinglee.org
vim /etc/nginx/nginx.conf
server{
……
}
include /etc/nginx/conf.d/*.conf;
nginx -s reload
curl www.timinglee.org
4.实验结果验证
wed服务
修改默认 端口、文件、目录
web服务器的访问控制
ip
用户
一个nginx 多个index--虚拟机
ip
域名
5.其他
URI,URL和URN
概念 | 定义 | 餐厅语言描述 | 关键区别 | |
---|---|---|---|---|
URI | 统一资源标识符(唯一标识资源) | 餐厅会员卡:包含顾客所有信息(姓名、卡号、积分),可识别身份或查询储值余额 | 广义概念:包含 URL 和 URN,既可定位资源(URL),也可仅命名资源(URN) | |
URL | 统一资源定位符(定位资源位置) | 餐厅导航地址:例如 https://hotpot.com:8080/menu/spicy?level=high#sauce :- 通过 VIP 通道( https ) 进入火锅店官网,到 8080 包厢(port ) 查看 辣味菜单(/menu/spicy ),要求 加辣(?level=high ),定位到 调料台(#sauce ) | 必须包含协议和路径:依赖网络位置访问资源(如菜单需在线获取) | |
URN | 统一资源名称(仅命名资源) | 菜品唯一编号:例如 urn:dish:2025-noodles ,表示“2025 号特色面条”(即使菜单位置变更,编号仍唯一标识该菜品) | 仅命名不定位:无需依赖路径或协议(如菜品编号不因菜单存放位置改变而失效) |
url组成
组件名称 | 结构符号 | 生活化描述 | |
---|---|---|---|
方案 (Scheme) | <scheme>:// | 相当于“交通工具类型”,规定访问资源的方式(例如 http 是普通网页,https 是加密网页) | |
用户 (User) | <user>: | 访问某些资源时的“用户名”,类似于进小区要刷卡登记姓名(可选) | |
密码 (Password) | <password>@ | 用户名的“钥匙”,用冒号和用户名分隔(例如 admin:123456@ ) | |
主机 (Host) | <host> | 资源的“家庭住址”,可以是域名(如 www.baidu.com )或 IP(如 192.168.1.1 ) | |
端口 (Port) | :<port> | 主机的“门牌号”,默认门牌可省略(例如 HTTP 默认走 80 端口,访问 http://xxx 等同于 http://xxx:80 ) | |
路径 (Path) | /<path> | 资源的“具体房间号”,类似文件路径(例如 /photos/2024/spring.jpg 指向图片文件) | |
参数 (Params) | ;<params> | 分号分隔的“附加参数”,例如文件格式或版本控制(如 /file;p=1 表示参数 p 的值是 1) | |
查询 (Query) | ?<query> | 问号后的“搜索条件”,多个条件用 & 连接(例如 ?q=apple&color=red 表示搜索红苹果) | |
片段 (Frag) | #<frag> | 页面内的“书签定位”,快速跳转到指定位置(例如 #chapter3 直接显示第三章内容) |
URL 组件 | 餐厅语言描述 | |
---|---|---|
Scheme | 餐厅的入口方式(如 http 对应正门,https 对应 VIP 加密通道,ftp 对应员工送货通道) | |
User | VIP 会员账号(如 admin 表示餐厅经理账号,需配合密码使用) | |
Password | 会员密码(如 123456 对应会员卡密码,与账号共同验证身份) | |
Host | 餐厅名称或地址(如 www.hotpot.com 表示火锅店官网,192.168.1.1 类似分店 IP 地址) | |
Port | 餐厅楼层或区域(如 :80 对应主用餐区,:8080 对应后厨专用通道) | |
Path | 具体座位号或菜单路径(如 /table3 表示 3 号桌,/menu/spicy 指向辣味菜单) | |
Params | 特殊服务参数(如 ;chopsticks=yes 表示要求提供筷子,以分号分隔多个参数) | |
Query | 点餐附加要求(如 ?spice_level=high&rice=no 表示“加辣、不要米饭”) | |
Frag | 餐厅内特定区域(如 #kids_area 表示儿童游乐区,仅客户端使用不传至服务器) |
生活场景类比
网购快递单号
https://user:pass@kuaidi.com:443/track/123456?from=shanghai#status
用加密快递(https),用户名和密码验证身份(user:pass@),快递公司地址(kuaidi.com),默认走 443 端口,查询单号 123456 的物流路径,附带“从上海发货”的条件,直接显示“最新状态”部分
图书馆借书系统
http://lib:guest@library.org/books/scifi?author=Liu#page50
通过普通协议访问图书馆系统(http),用公共账号 lib:guest 登录,进入“科幻书籍”分区,筛选“刘慈欣”的作品,跳转到第 50 页
关键说明
必选与可选组件
必须包含 Scheme、Host、Path(如 http://www.baidu.com/index.html)
其他组件(如用户、密码、端口)仅在特定场景下需要
编码与特殊符号
空格、中文等特殊字符需转换为 %20、%E4%B8%AD 等形式,避免传输错误
协议差异
HTTP 默认端口 80,HTTPS 默认 443,FTP 默认 21,不同协议路径规则可能不同
请求报文、响应报文
首位数字 | 餐厅场景分类 | 示例状态码 |
---|---|---|
1xx | 服务员正在处理订单(如“101:正在核对库存”) | 100 Continue |
2xx | 订单处理成功(如“200:已上菜”,“201:新会员注册成功”) | 200 OK, 201 Created |
3xx | 需要跳转操作(如“302:牛排已售罄,推荐换为猪排”) | 302 Found |
4xx | 顾客操作错误(如“400:订单格式错误”,“403:无权限”) | 404 Not Found |
5xx | 厨房或系统故障(如“500:厨师请假”,“503:食材短缺”) | 503 Service Unavailable |
状态码 | 餐厅语言描述 | |
---|---|---|
200 OK | 顾客点单成功,服务员准确收到订单并开始备餐(如:用户成功下单一份牛排套餐) | |
400 Bad Request | 顾客填写订单时写错菜品编号或格式(如:将“A1套餐”写成“A01”),服务员无法理解请求 | |
401 Unauthorized | 顾客想进入VIP包厢但未出示会员卡,服务员要求先验证身份(需配合出示“WWW-Authenticate”类会员验证方式) | |
403 Forbidden | 顾客试图进入后厨区域,服务员直接拒绝(如普通顾客无权限进入厨房) | |
404 Not Found | 顾客点了一份“龙肉炒饭”,服务员查遍菜单发现无此菜品(类似输入错误URL) | |
500 Internal Server Error | 厨房设备突然故障,无法完成订单(如烤箱爆炸导致订单卡住) | |
503 Server Unavailable | 餐厅客满,暂时无法接待新顾客(服务员告知“请30分钟后再来”) |
学习时间:
学习时间为学习时间
学习时间 | 筋肉人 |
为学习时间 | future |
内容为笔记【有时比较抽象,有时比较过于详细,请宽恕。作者可能写的是仅个人笔记,筋肉人future】
学习产出:
web服务(nginx的安装与启用,nginx的端口,默认发布文件,默认发布目录等配置,nginx的访问控制,nginx的虚拟主机)
绿色框为logo
画工
。puppy-CSDN博客。puppy擅长计算机网络,python,软件,等方面的知识
https://blog.csdn.net/2301_79807099?type=blog
再来1章linux 系列-5.2 权限管理的实验详细1Sticky Bit2 SGID (Set GID)3 SUID (Set UID)4. chmod 5.ACL 6.chown-CSDN博客
- 技术笔记 1遍
- 有错误请指出,作者会及时改正