当前位置: 首页 > news >正文

Linux之web服务器

1.web服务器简介

http协议请求的工作流程:

1.终端客户在web浏览器地址栏输入访问地址;2.web浏览器请求DNS服务器把域名解析成web服务器的IP地址 ;3.web浏览器将端口号(默认是80)从访问地址(URL)中解析出来; 4.web浏览器通过解析后的ip地址及端口号与web服务器之间建立一条TCP连接 ;5.建立TCP连接后,web浏览器向web服务器发送一条HTTP请求报文 ;6.web服务器响应并读取浏览器的请求信息,然后返回一条HTTP响应报文;7.web服务器关闭HTTP连接,关闭TCP连接,web浏览器显示访问的网站内容到屏幕上。

https协议相对于http的加密: 

对称加密 我的理解是: 首先我们需要协商使用什么算法(AES), 接着我们通过相同的密钥对数据进行加密即可实现:明文 + 密钥 ==> 密文 密文 + 密钥 ==> 明文。由此我们可以看出, 都使用相同的密钥,一旦密钥泄露, 那么数据相当于公开。 优点: 效率高。 改进:能不能提前把密钥加密,只能由服务端才能解密。

非对称加密 是网络通信的基石, 保证了非对称加密 密钥的安全。 首先, 非对称加密需要 私钥 和 公钥, 公钥加密的数据只能由私钥解开, 而私钥加密的数据只能由公钥解开。 公钥存储在客服端, 私钥存储在服务端, 永远不对外暴漏。 流程:首先客服端请求公钥, 服务端响应公钥, 之后客服端通过公钥加密数据传输, 服务端通过私钥解密获取信息。 存在的安全隐患: 我们的公钥是直接进行传输的, 那么黑客就可以得到我们的公钥从而获取信息。

非对称加密 + 对称加密

客服端请求公钥响应后, 客服端通过公钥可以加密一串随机数,作为以后信息传输对称加密的密钥, 而这串随机数也只能由服务端的私钥才能解析

2.基于http的静态网站

在配置前使用nmtui进入配置IP界面,添加要使用的IP

实验1.搭建一个显示“hello jio!”的服务器

 [root@localhost ~]# echo "hello jio!" > /usr/share/nginx/html/index.html[root@localhost ~]# curl localhosthello jio![root@localhost ~]# curl 192.168.168.50hello jio!

实验2.搭建两个基于不同IP地址访问的网站

(主机位为100和200,首页目录为/www/ip/100,/www/ip/200,首页内容分别为this is100,this is 200)

[root@localhost ~]# nmcli connection up ens160 #激活
[root@localhost ~]# mkdir -pv /www/ip/{100,200}
[root@localhost ~]# echo this is 100 > /www/ip/100/index.html
[root@localhost ~]# echo this is 200 > /www/ip/200/index.html
[root@server html]# setenforce 0 #selinux
[root@localhost ~]# vim /etc/nginx/conf.d/ip.confserver {listen 192.168.168.100:80;root /www/ip/100;location / {}}server {listen 192.168.168.200:80;root /www/ip/200;location / {}}[root@localhost ~]# systemctl restart nginx #如果出错了按照提示复制命令检查问题[root@localhost ~]# curl 192.168.168.100this is 100[root@localhost ~]# curl 192.168.168.200this is 200

实验3.搭建两个基于不同端口访问的网站

(端口分别为80和10000,首页目录为/www/port/80,/www/port/10000,首页内容分别为the port is 80,the port is  10000)

[root@localhost ~]# mkdir -pv /www/port/{80,10000}
[root@localhost ~]# echo the port is 80 > /www/port/80/index.html
[root@localhost ~]# echo the port is 10000 > /www/port/10000/index.html 
[root@localhost ~]# vim /etc/nginx/conf.d/test_port.confserver {listen 192.168.168.153:80;root /www/port/80;location / {}}server {listen 192.168.168.153:10000;root /www/port/10000;location / {}}[root@localhost ~]# systemctl restart nginx[root@localhost ~]# curl 192.168.168.153:10000the port is 10000[root@localhost ~]# curl 192.168.168.153:80the port is 80

实验4.搭建两个基于不同域名访问的网站

(域名分别为www.jio.com和zj.de.wang,首页目录为/www/jio,/www/jioz,首页内容分别为my name is jio,my name is jioz)

 [root@localhost ~]# mkdir /www/{jio,jioz}[root@localhost ~]# echo my name is jio > /www/jio/index.html[root@localhost ~]# echo my name is jioz > /www/jioz/index.html[root@localhost ~]# vim /etc/nginx/conf.d/name.confserver {listen 192.168.168.154:80;server_name www.jio.com;root /www/jio;location / {}}server {listen 192.168.168.154:80;server_name jio.de.wang jiojio.de.wang;root /www/jioz;location / {}}[root@localhost ~]# vim /etc/hosts192.168.168.154 www.jio.com jio.de.wang jiojio.de.wang [root@localhost ~]# systemctl restart nginx[root@localhost ~]# curl www.jio.commy name is jio[root@localhost ~]# curl jio.de.wangmy name is jioz[root@localhost ~]# curl jiojio.de.wangmy name is jioz

实验5.基于虚拟目录和用户控制的web网站

[root@localhost ~]# mkdir /www/real/
[root@localhost ~]# echo real-virtual > /www/real/index.html
[root@localhost ~]# vim /etc/nginx/conf.d/virtual.conf
server {listen 192.168.168.155:80;root /usr/share/nginx/html;location /real {alias /www/real;}}[root@localhost ~]# systemctl restart nginx[root@localhost ~]# curl 192.168.168.155/real/real-virtual[root@localhost ~]# vim /etc/nginx/conf.d/virtual1.confserver {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/ -u user1Enter host password for user 'user1':real-virtual[root@localhost ~]# curl user1:123456@192.168.168.155/real/real-virtual

3.基于https的静态网站

实验.https的网站配置

[root@localhost ~]# echo 我是更加安全的https > /www/https/index.html
[root@localhost ~]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl  genrsa -out https.key    #私钥文件
[root@localhost certs]# openssl  req  -utf8 -new -key https.key -x509 -days 100 -out https.crt    #公钥文件
[root@localhost ~]# vim /etc/nginx/conf.d/test_https.confserver {listen 192.168.168.156:443 ssl;root /www/https;ssl_certificate /etc/pki/tls/certs/https.crt;ssl_certificate_key /etc/pki/tls/certs/https.key;location / {}}[root@localhost ~]# systemctl restart nginx[root@localhost ~]# curl -k https://192.168.168.156https我是更加安全的https

4.动态网站的搭建


http://www.mrgr.cn/news/59165.html

相关文章:

  • 前端:localStorage和浏览器的历史记录(History API)
  • vue父子传参的方式——Prop
  • Java面试题——微服务篇
  • 10.22.2024刷华为OD C题型(三)--for循环例子
  • 【JAVA】第三张_Eclipse下载、安装、汉化
  • Node.js初学者指南:搭建HTTP服务器、获取请求信息及响应、变量声明与NPM包管理
  • 快捷键记忆
  • 变频器启动、停止、正/反转控制电路原理详解
  • Leecode热题100-287.寻找重复数
  • 实测体验Claude 3.5升级版:AI首次实现直接操控电脑!
  • Pyside6 布局管理器(3)--- QGridLayout的使用
  • Python使用unrar遇到的问题及解决
  • API网关的作用--为什么微服务需要一个API网关?
  • 计算机网络中网络层发送报文时IP地址的变化,交换器的广播功能及相关设备功能
  • 【Nas】X-DOC:Mac mini Docker部署中国特供版Jellyfin
  • Ubuntu24.04配置samba共享
  • ubuntu22.04安装qemu-9.1并在i.MX6上运行linux kernel 6.11
  • 【创业】互联网行业30年发展史与风口,后双创时代杀出重围的独角兽们(追求极致,务实敢为)
  • SpringCloud Gateway路由核心原理解析
  • 深入理解Python异常处理机制
  • IDEA如何将一个分支的代码合并到另一个分支(当前分支)
  • GCN+BiLSTM多特征输入时间序列预测(Pytorch)
  • 使用Python的DrissonPage库自动化爬取美女图片
  • 怎么用c++的fill函数?
  • STemWin移植中文GB2312编码支持
  • 探寻闲鱼libsgmain加解密算法(4) ——JNI入口跳转