web基本概念和常识
Web:为用户提供的一种在互联网上浏览信息的服务,Web 服务
 是动态的、可交
 互的、跨平台的和图形化的。
 Web 服务为用户提供各种互联网服务,这些服务包括信息浏览服务,以及各种交互式服务,包括聊天、购物、学习等等内容:
 Web 应用开发也经过了几代技术的不断发展,目前Web 开发依然是最重要的开发内容之一。Web 基础的技术包括超文本标记语言(HTML)和 HTTP 协议,HTML是一种呈现数据的方式(给人看的),而 HTTP 则是一组通信的标准(语法、语义、时许),可以简单的理解为 HTTP 携带 HTML。
1.web 应用:网站(广义上的PC,手机app)
2.浏览器(Browser):也称用户代理,web客户端,主要有IEEdge、Chrome、Firefox、腾讯浏览器,360浏览器等
3.web服务器(webserver):也称HTTP服务器(HTTPserver),要有 NginxApache,Tomcat 等
[root@web ~]# yum -y install httpd
 [root@web ~]# systemctl start httpd
[root@web html]# ls
 微信图片_20240119192230.jpg
 [root@web html]# 
 [root@web html]# mkdir img
 [root@web html]# mv 微信图片_20240119192230.jpg ./img/
http特点
1.简单性:HTTP协议的语法相对简单,易于实现和调试。它使用基于请求-响应模式的通信方式,客户端发送请求,服务器响应请求,简单直观。
2.无状态性:HTTP是一种无状态协议,即服务器不保存任何关于客户端的信息。每个请求都是独立的,不与之前或之后的请求相关联。
3.可靠性较差:HTTP协议没有内置的机制来保证消息的可靠传输,例如消息确认或错误检测和重传。这些功能需要在应用程序层面实现。
4.支持多种数据格式:HTTP支持多种数据格式,包括HTML、XML、JSON等。这使得它成为Web服务的首选协议之一。
5.端口号为80:HTTP默认使用端口号80,因此HTTP请求和响应数据可以通过常见的网络设备(如路由器和防火墙)进行传输。
6.明文传输:HTTP协议的传输是明文的,易于被网络攻击者窃取或篡改数据。但是,HTTPS(HTTP Secure)可以提供加密传输的安全机制。
7.可扩展性:HTTP协议是一种可扩展的协议,允许通过HTTP头和正文中的自定义标记来定义新的数据类型和操作。
生成一个大文件
[root@web html]# dd if=/dev/zero of=/var/www/html/a.txt bs=30M count=1
 记录了1+0 的读入
 记录了1+0 的写出
 31457280字节(31 MB)已复制,0.0634171 秒,496 MB/秒
HTTP 状态码
 2xx:成功,200成功、201已经创建
 3xx:重定向,304未修改
 4xx:请求错误,404未找到文件、408请求超时
5xx:服务器错,500服务器内部错误、502网关错误
查看华为云主机的所有的打开的端口
[root@web html]# systemctl start firewalld
 [root@web html]# firewall-cmd --list-ports
回到虚拟机本地,启动防火墙服务,就访问不到web页面了
[root@web html]# firewall-cmd --zone=public --add-port=80/tcp --permanent
 success
 [root@web html]# firewall-cmd --zone=public --add-port=80/tcp --permanent
 Warning: ALREADY_ENABLED: 80:tcp
 success
查看防火墙打开的端口
[root@web html]# firewall-cmd --list-all
 public (active)
   target: default
   icmp-block-inversion: no
   interfaces: ens160 ens224
   sources: 
   services: ssh dhcpv6-client
   ports: 
   protocols: 
   masquerade: no
   forward-ports: 
   source-ports: 
   icmp-blocks: 
   rich rules: 
  
apache的搭建
安装http服务
[root@http ~]# yum -y install httpd
查看安装情况以及安装的资源文件
[root@http ~]# rpm -qa | grep httpd
 httpd-tools-2.4.6-99.el7.centos.1.x86_64
 httpd-2.4.6-99.el7.centos.1.x86_64
查看文件目录
[root@http ~]# rpm -ql httpd
 [root@http ~]# vim /etc/httpd/conf/httpd.conf 
 [root@http ~]# ls /var/www/html/
 启动服务
[root@http ~]# systemctl start httpd
 查看端口
[root@http ~]# netstat -anlt | grep http
 单独的打开某些端口或者服务,在云服务器上,不能够直接停用防火墙,可以单独打开端口
打开服务器不会马上生效,需要重启或者重载服务信息
[root@http ~]# systemctl start firewalld
 [root@http ~]# firewall-cmd --zone=public --add-service=http
 success
 [root@http ~]# firewall-cmd --list-^C
 [root@http ~]# firewall-cmd --reload
 success
 [root@http ~]# firewall-cmd --list-all
 public (active)
   target: default
   icmp-block-inversion: no
   interfaces: ens160 ens224
   sources: 
   services: ssh dhcpv6-client
   ports: 
   protocols: 
   masquerade: no
   forward-ports: 
   source-ports: 
   icmp-blocks: 
   rich rules: 
停用防火墙或者打开指定端口
 [root@http ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
 success
 [root@http ~]# firewall-cmd --reload        启动端口
 success
可以访问到
当在资源目录中国添加index.html之后,http服务会自动找到
[root@http ~]# vim /var/www/html/index.html

浏览器访问:192.168.2.36

静态文件如果无法在浏览器上访问,就一定无法加载在页面上
源码编译安装nginx
下载源码包
[root@nginx ~]# wget https://nginx.org/download/nginx-1.26.1.tar.gz
 [root@nginx ~]# ls -lh 
-rw-r--r--.  1 root root  1.2M 5月  29 22:30 nginx-1.26.1.tar.gz
 [root@nginx ~]# tar -zxvf nginx-1.26.1.tar.gz 
 [root@nginx ~]# yum -y install gcc gcc-c++ 
 [root@nginx ~]# yum -y install make openssl-devel pcre-devel
 编译安装nginx

[root@nginx nginx-1.26.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-stream
 [root@nginx nginx-1.26.1]# useradd -s /bin/nologin -M nginx
[root@nginx nginx-1.26.1]# tree /usr/local/nginx/
 /usr/local/nginx/
 ├── conf
 │   ├── fastcgi.conf
 │   ├── fastcgi.conf.default
 │   ├── fastcgi_params
 │   ├── fastcgi_params.default
 │   ├── koi-utf
 │   ├── koi-win
 │   ├── mime.types
 │   ├── mime.types.default
 │   ├── nginx.conf
 │   ├── nginx.conf.default
 │   ├── scgi_params
 │   ├── scgi_params.default
 │   ├── uwsgi_params
 │   ├── uwsgi_params.default
 │   └── win-utf
 ├── html
 │   ├── 50x.html
 │   └── index.html
 ├── logs
 └── sbin
     └── nginx
4 directories, 18 files
 [root@nginx nginx-1.26.1]# cd /usr/local/nginx/
 [root@nginx nginx]# ls
 conf  html  logs  sbin
启动服务
[root@nginx nginx]# ./sbin/nginx
 [root@nginx nginx]# netstat -lnput | grep nginx
 tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4800/nginx: master  
 开放端口或者服务
[root@nginx nginx]# systemctl start firewalld
 [root@nginx nginx]# firewall-cmd --zone=public --add-port=80/tcp --permanent
 success
 [root@nginx nginx]# firewall-cmd --reload        重载防火墙
 success
主配置文件
[root@nginx nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/
 [root@nginx nginx]# nginx
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 ^C
 [root@nginx nginx]# nginx -s stop 
 [root@nginx nginx]# netstat -lnput | grep nginx
 [root@nginx nginx]# nginx
 [root@nginx nginx]# netstat -lnput | grep nginx
 tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6825/nginx: master  
之所以指令能在命令行使用,是因为在$PATH目录中能找到这个可执行文件或者是这个可执行文件的链接文件
启动和关闭nginx服务
./nginx ./nginx -s stop
修改了配置文件后,重载nginx服务网
./nginx -s reload
脚本 启动nginx服务
#!/bin/bash
 /usr/local/sbin/nginx &> /dev/null
 if [ $? -nq 0 ];then
         echo "nginx正在执行,或者80端口被占用"
 fi
 [root@nginx nginx]# bash ~/nginx.sh
 nginx正在执行,或者80端口被占用
  
如果使用sbin目录下的nginx,就无法使用systemctl
重启一下,然后使用systemctl启动nginx就可以了
[root@nginx ~]# systemctl start nginx

添加监控块,修改配置文件
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
48 location / status{
49 stub_status on;
50 access_log off;
51 }
[root@nginx ~]# systemctl reload nginx.service访问192.168.2.37/status
Active connections: 2 活动的连接数 server accepts handled requests 累计接受,处理,请求的连接数 2 2 2 Reading: 0 Writing: 1 Waiting: 1 正在读取,写入和等待的连接数
nginx反向代理
  303  wget https://nginx.org/download/nginx-1.26.1.tar.gz
   304  tar -zxvf nginx-1.26.1.tar.gz 
   305  tar -zxvf nginx-1.26.1.tar.gz 
   306   yum -y install gcc gcc-c++
   307  yum -y install make openssl-devel pcre-devel
   308  cd nginx-1.26.1
   309  ./configure --prefix=/usr/local/nginx
   310  make && make install
  319  firewall-cmd --zone=public --add-port=80/tcp --permanent
   321  firewall-cmd --reload
   322  /usr/local/nginx/sbin/nginx 
   323  vim /usr/local/nginx/conf/nginx.conf
  



















