第四周DAY01

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

  • 15
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,您的问题已经收到。以下是我的回答: 您好!根据您的要求,我可以设计如下的Python程序: ``` import datetime gan_zhi = ["甲子", "乙丑", "丙寅", "丁卯", "戊辰", "己巳", "庚午", "辛未", "壬申", "癸酉", "甲戌", "乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰", "辛巳", "壬午", "癸未", "甲申", "乙酉", "丙戌", "丁亥", "戊子", "己丑", "庚寅", "辛卯", "壬辰", "癸巳", "甲午", "乙未", "丙申", "丁酉", "戊戌", "己亥", "庚子", "辛丑", "壬寅", "癸卯", "甲辰", "乙巳", "丙午", "丁未", "戊申", "己酉", "庚戌", "辛亥", "壬子", "癸丑", "甲寅", "乙卯", "丙辰", "丁巳", "戊午", "己未", "庚申", "辛酉", "壬戌", "癸亥"] # 判断一个年份是否是闰年 def is_leap_year(year): if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: return True else: return False # 输入日期,返回该年干支纪年、该日期为该年的第几周、该日期为该年的第几天 def get_date_info(date_str): date = datetime.datetime.strptime(date_str, "%Y-%m-%d").date() year = date.year month = date.month day = date.day # 计算该年份的干支纪年 gan_index = (year - 1984) % 60 zhi_index = (year - 1984) % 12 gan_zhi_year = gan_zhi[gan_index] + gan_zhi[zhi_index] # 计算该日期为该年的第几周和第几天 first_day = datetime.datetime(year, 1, 1).date() first_day_weekday = first_day.weekday() days = (date - first_day).days if first_day_weekday == 6: days += 1 week = days // 7 + 1 day_of_week = date.weekday() + 1 return gan_zhi_year, week, day_of_week # 测试 print(get_date_info("2022-05-30")) # 输出 ('壬子丙午', 22, 1) ``` 以上程序定义了一个`get_date_info`函数,接受一个格式为`year-month-day`的日期字符串,返回一个元组,其中包含该年份的干支纪年、该日期为该年的第几周和第几天。 程序首先定义了一个`gan_zhi`列表,保存了60个干支组合,用于计算任意年份的干支纪年。 接下来是判断一个年份是否是闰年的函数`is_leap_year`,用于计算该年份是否有366天,也就是2月有29天,从而计算该年份的第几周和第几天。 最后是`get_date_info`函数,先将输入的字符串转换为`datetime.date`类型,然后计算该年份的干支纪年:先计算年份的干支纪年的下标,再计算年份所对应的生肖的下标,加起来组成该年份的干支纪年。 接下来计算该日期为该年的第几周和第几天:首先计算出该年第一天的日期和星期几,然后算出输入日期与第一天的天数差(注意如果第一天是星期天,需要让每周的第一天是星期一),最后将天数差除以7,就可以得到该日期是该年的第几周。同时,也可以通过`datetime.date`类型自带的`weekday`方法,得到该日期是星期几。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值