做网站基本教程,深圳网站制作必推祥奔科技,潍坊网站制作推广,我想做京东网站淘宝怎么做的目录 HTTP简介HTTP原理查看访问网站的详细流程curl -vwget --debug 查看网站访问量HTTP协议版本HTTP协议交互HTTP 请求请求报文起始行请求头 HTTP响应响应报文起始行响应头 Nginx常见的Web服务常见网站服务 安装NginxNginx目录结构Nginx启动管理Nginx常用命令 Nginx配置文件主配… 目录 HTTP简介HTTP原理查看访问网站的详细流程curl -vwget --debug 查看网站访问量HTTP协议版本HTTP协议交互HTTP 请求请求报文起始行请求头 HTTP响应响应报文起始行响应头 Nginx常见的Web服务常见网站服务 安装NginxNginx目录结构Nginx启动管理Nginx常用命令 Nginx配置文件主配置文件子配置文件 HTTP简介
HTTP原理
WebServer为Client提供网页浏览等服务又称HTTPServer或WWWServer。HTTP采用B/S模型Client和Server通过HTTP或HTTPS进行数据的传输。HTTP采用TCP链接HTTP默认监听80端口HTTPS默认监听443端口。HTTP的工作原理 链接Browser和WebServer建立链接通过打开socket表明链接建立成功。请求Browser通过socket向WebServer提交请求一般为HTTP的GET或POST。应答Server通过特定端口接收监听到的Web页面请求若请求存在再通过HTTP发送Browser需要的信息若请求不存在则返回错误提示。关闭连接每完成一次应答就会断开一次链接。
查看访问网站的详细流程
curl -v
[rootfront ~]# curl -v www.baidu.com
* Rebuilt URL to: www.baidu.com/
* Trying 153.3.238.110...
* TCP_NODELAY set
* Connected to www.baidu.com (153.3.238.110) port 80 (#0)GET / HTTP/1.1Host: www.baidu.comUser-Agent: curl/7.61.1Accept: */*HTTP/1.1 200 OKAccept-Ranges: bytesCache-Control: private, no-cache, no-store, proxy-revalidate, no-transformConnection: keep-aliveContent-Length: 2381Content-Type: text/htmlDate: Sun, 02 Jun 2024 12:25:56 GMTEtag: 588604eb-94dLast-Modified: Mon, 23 Jan 2017 13:28:11 GMTPragma: no-cacheServer: bfe/1.0.8.18Set-Cookie: BDORZ27315; max-age86400; domain.baidu.com; path/!DOCTYPE html
!--STATUS OK--html headmeta http-equivcontent-type contenttext/html;charsetutf-8meta http-equivX-UA-Compatible contentIEEdgemeta contentalways namereferrerlink relstylesheet typetext/css hrefhttp://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.csstitle百度一下你就知道/title/head body link#0000cc div idwrapper div idhead div classhead_wrapper div classs_form div classs_form_wrapper div idlg img hidefocustrue src//www.baidu.com/img/bd_logo1.png width270 height129 /div form idform namef action//www.baidu.com/s classfm input typehidden namebdorz_come value1 input typehidden nameie valueutf-8 input typehidden namef value8 input typehidden namersv_bp value1 input typehidden namersv_idx value1 input typehidden nametn valuebaiduspan classbg s_ipt_wrinput idkw namewd classs_ipt value maxlength255 autocompleteoff autofocus/spanspan classbg s_btn_wrinput typesubmit idsu value百度一下 classbg s_btn/span /form /div /div div idu1 a hrefhttp://news.baidu.com nametj_trnews classmnav新闻/a a hrefhttp://www.hao123.com nametj_trhao123 classmnavhao123/a a hrefhttp://map.baidu.com nametj_trmap classmnav地图/a a hrefhttp://v.baidu.com nametj_trvideo classmnav视频/a a hrefhttp://tieba.baidu.com nametj_trtieba classmnav贴吧/a noscript a hrefhttp://www.baidu.com/bdorz/login.gif?loginamp;tplmnamp;uhttp%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 nametj_login classlb登录/a /noscript scriptdocument.write(a hrefhttp://www.baidu.com/bdorz/login.gif?logintplmnu encodeURIComponent(window.location.href (window.location.search ? ? : ) bdorz_come1) nametj_login classlb登录/a);/script a href//www.baidu.com/more/ nametj_briicon classbri styledisplay: block;更多产品/a /div /div /div div idftCon div idftConw p idlh a hrefhttp://home.baidu.com关于百度/a a hrefhttp://ir.baidu.comAbout Baidu/a /p p idcpcopy;2017nbsp;Baidunbsp;a hrefhttp://www.baidu.com/duty/使用百度前必读/anbsp; a hrefhttp://jianyi.baidu.com/ classcp-feedback意见反馈/anbsp;京ICP证030173号nbsp; img src//www.baidu.com/img/gs.gif /p /div /div /div /body /html
* Connection #0 to host www.baidu.com left intactwget --debug
[rootfront ~]# wget --debug www.baidu.com
DEBUG output created by Wget 1.19.5 on linux-gnu.Reading HSTS entries from /root/.wget-hsts
URI encoding ‘UTF-8’
Converted file name index.html (UTF-8) - index.html (UTF-8)
--2024-06-02 20:28:06-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 153.3.238.110, 153.3.238.102, 2408:873d:22:18ac:0:ff:b021:1393, ...
Caching www.baidu.com 153.3.238.110 153.3.238.102 2408:873d:22:18ac:0:ff:b021:1393 2408:873d:22:1a01:0:ff:b087:eecc
Connecting to www.baidu.com (www.baidu.com)|153.3.238.110|:80... connected.
Created socket 3.
Releasing 0x0000557a357bf620 (new refcount 1).---request begin---
GET / HTTP/1.1
User-Agent: Wget/1.19.5 (linux-gnu)
Accept: */*
Accept-Encoding: identity
Host: www.baidu.com
Connection: Keep-Alive---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 200 OK
Content-Length: 2381
Content-Type: text/html
Server: bfe
Date: Sun, 02 Jun 2024 12:28:06 GMT---response end---
200 OK
Registered socket 3 for persistent reuse.
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html’index.html 100%[] 2.33K --.-KB/s in 0s2024-06-02 20:28:06 (123 MB/s) - ‘index.html’ saved [2381/2381]
查看网站访问量 alexa.chinaz.com 指标说明IP访问网站的独立IP数量公网IP。PV页面访问量Page view。UV独立访客数量接近于用户数量 Unique Visitor。DAU每天的活跃用户的数量日活(日活跃用户)。MAU月活(月活跃用户)。
HTTP协议版本
http1.0http1.1http2.0http3.0特点短连接,每次请求都需要重复建立断开连接加入长连接功能增加并发,访问更快基于udp更快,应用于流媒体占用服务端资源keepalive响应后不会立刻断开是否加密http不加密https加密默认基于https基于tcp/udptcptcptcpudp
HTTP协议交互
浏览器发送request请求服务器回复response响应
HTTP 请求
---request begin---
GET / HTTP/1.1
User-Agent: Wget/1.19.5 (linux-gnu)
Accept: */*
Accept-Encoding: identity
Host: www.baidu.com
Connection: Keep-Alive---request end---请求报文起始行 GET / HTTP/1.1 请求方法用于指定客户端如何访问服务端(下载,上传,查看服务端信息)
常见的请求方法说明GET下载大部分请求用于请求服务器发送指定资源。POST上传上传文件内容、登录用于向服务器提交数据通常导致服务器上的状态变化或副作用。HEAD类似于GET仅仅输出响应的头部信息查看服务端的信息一般用于检查。 资源的位置(URI): 这个资源在网站站点目录的哪个地方,叫什么名字. 这里面写的/斜线并非是Linux系统的根目录.这个/叫网站的站点目录 http协议版本
请求头 User-Agent: Wget/1.19.5 (linux-gnu) Accept: / Accept-Encoding: identity Host: www.baidu.com Connection: Keep-Alive HTTP请求头解释User-Agent: Wget/1.19.5 (linux-gnu)请求头告诉服务器发起请求的应用类型和版本这里是Wget命令行下载工具。Accept: /请求头告诉服务器客户端接受任何类型的 MIME 响应。Accept-Encoding: identity请求头告诉服务器客户端不接受任何编码转换即希望服务器发送原始数据。Host: www.baidu.com请求头指定请求的服务器域名这里是百度网站的域名。Connection: Keep-Alive请求头告诉服务器客户端希望保持连接活跃以便为后续请求重用相同的TCP连接。
HTTP响应
---response begin---
HTTP/1.1 200 OK
Content-Length: 2381
Content-Type: text/html
Server: bfe
Date: Sun, 02 Jun 2024 12:49:11 GMT---response end---响应报文起始行 HTTP/1.1 200 OK HTTP版本 状态码 状态码描述 状态码是反应服务器是否正确的处理用户请求 |状态码 |含义| |-|-| |2xx |表示正常| |3xx |表示需要进行跳转,表示正常| |4xx |表示异常,客户端问题| |5xx |表示异常,服务端问题|
状态码状态码描述解释200OK访问正常服务器成功处理了请求。301Moved Permanently永久跳转请求的资源已被永久移动到新位置。302Found或Moved Temporarily临时跳转请求的资源临时移动到新位置。304Not Modified浏览器缓存请求的资源未修改可以使用缓存的内容。403Forbidden权限拒绝拒绝访问。权限问题如未授权访问首页文件问题如配置错误导致无法访问首页。404Not Found文件找不到一般辅助错误日志排查用于定位请求的资源不存在的问题。500Internal Error内部错误如服务器配置错误、应用程序错误等。SElinux开启时可能会导致一些异常。一般需要辅助错误日志来排查。502Bad Gateway网关错误一般发生在负载均衡器中请求发送到后端服务器但后端服务器没有响应导致网关返回错误。503Service Unavailable服务临时不可用后端负载异常等情况或者人为设置如系统升级导致服务暂时不可用。504Gateway Time-out网关超时请求发送到网关但网关在规定时间内没有响应。
响应头 Content-Length: 2381 Content-Type: text/html Server: bfe Date: Sun, 02 Jun 2024 12:49:11 GMT HTTP响应组成部分解释Content-Length: 2381响应头指示实体主体的大小以字节为单位这里是2381字节。Content-Type: text/html响应头指示响应的内容类型这里是HTML文本。Server: bfe响应头指示处理请求的服务器软件这里是百度的前端服务器Baidu Front End。Date: Sun, 02 Jun 2024 12:49:11 GMT响应头指示消息发送的时间这里是2024年6月2日星期日格林尼治标准时间12:49:11。
Nginx
常见的Web服务
类型说明WEB服务网站服务部署并启动了这个服务你就可以搭建一个网站。WEB中间件等同于WEB服务用于提供网站的托管和访问服务。中间件范围更加广泛指的负载均衡之后的服务包括各种应用程序层和网络层的中间件。数据库中间件数据库缓存、消息队列等功能的中间件用于提高数据库性能和处理数据。
常见网站服务
网站服务说明官网Nginx大部分使用nginx, Engine Xhttp://nginx.org/en/docs/Tengine基于Nginx二开, 淘宝开源, 更多内置模块http://tengine.taobao.org/Openresty基于Nginx二开, 加强Lua功能与模块http://openresty.org/Tomcat运行Java环境的Web服务https://tomcat.apache.org/Jboss运行Java环境的Web服务https://www.jboss.org/Jetty运行Java环境的Web服务https://www.eclipse.org/jetty/Weblogic运行Java环境的Web服务https://www.oracle.com/weblogic/PHP运行PHP环境的Web服务需要nginx (LNMP)https://www.php.net/
安装Nginx 从官网安装 nginx.org/en Mainline 主线版本 – 奇数版本 - 开发测试版本 -- 开发团队 - 二次开发Stable 稳定版本 – 偶数版本 - 稳定生产 - 中小企业Lengacy 历史版本 – 偶数版本 - 稳定的 download-stable 最下面-RHEL and derivatives-yum # 配置官网yum源stable版
[rootfront ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
namenginx stable repo
baseurlhttp://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck1
enabled1
gpgkeyhttps://nginx.org/keys/nginx_signing.key
module_hotfixestrue#安装
yum install -y nginx#检查
[rootfront ~]# rpm -qa nginx
nginx-1.26.1-2.el8.ngx.x86_64
[rootfront ~]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/usr/lib/.build-id
/usr/lib/.build-id/3d
/usr/lib/.build-id/3d/2e2d5ec454efae0e8f8abeb6f056b4636a8a0c
/usr/lib/.build-id/4f
/usr/lib/.build-id/4f/adbe3f34e65c805137a92caf2f2035f1112f6a
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.26.1
/usr/share/doc/nginx-1.26.1/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginxNginx目录结构 不同的安装方式目录、文件会有所变化 目录结构说明/etc/nginx/Nginx各种配置的目录/etc/nginx/nginx.conf主配置文件/etc/nginx/conf.d/子配置文件网站目录/etc/nginx/conf.d/default.conf默认的子配置文件/usr/sbin/nginxngx命令用于启动、停止、重启Nginx服务器/usr/share/nginx/html/ngx默认的站点目录网站的根目录/var/log/nginx/ngx日志访问日志、错误日志、跳转日志
其他目录和文件说明/etc/logrotate.d/nginx日志切割防止文件过大/etc/nginx/mime.types媒体类型文件定义了MIME类型和扩展名的映射/etc/nginx/fastcgi_params包含FastCGI参数的文件用于处理PHP请求/etc/nginx/uwsgi_params包含uWSGI参数的文件用于处理Python请求/usr/lib/systemd/system/nginx.servicesystemctl配置文件用于使用systemd管理Nginx服务/var/cache/nginx/缓存目录用于存储临时文件和缓存内容
Nginx启动管理 源码安装的nginx启动方式不同建议菜鸟教程 # 启动
[rootfront ~]# systemctl enable nginx --now# 查看端口
[rootfront ~]# ss -tunlp | grep 80
tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users:((nginx,pid2403,fd6),(nginx,pid2402,fd6),(nginx,pid2225,fd6))
# 查看进程
[rootfront ~]# ps -ef | grep nginx
root 2225 1 0 16:56 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 2402 2225 0 19:51 ? 00:00:00 nginx: worker process
nginx 2403 2225 0 19:51 ? 00:00:00 nginx: worker process
root 2851 1384 0 21:22 pts/0 00:00:00 grep --colorauto nginx# 访问测试
[rootfront ~]# curl 127.0.0.1
!DOCTYPE html
html
head
titleWelcome to nginx!/title
style
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
/style
/head
body
h1Welcome to nginx!/h1
pIf you see this page, the nginx web server is successfully installed and
working. Further configuration is required./ppFor online documentation and support please refer to
a hrefhttp://nginx.org/nginx.org/a.br/
Commercial support is available at
a hrefhttp://nginx.com/nginx.com/a./ppemThank you for using nginx./em/p
/body
/html
Nginx常用命令
命令选项解释nginx -s stop停止Nginx服务器nginx -s quit优雅地停止Nginx服务器nginx -s reload重新加载Nginx配置文件nginx -s reopen重新打开日志文件nginx -s configtest测试Nginx配置文件的语法错误nginx -t测试Nginx配置文件的语法错误nginx -c filename指定配置文件路径nginx -p path指定Nginx的运行路径nginx -g “options”设置全局配置选项nginx -V显示Nginx版本信息nginx -h显示帮助信息
Nginx配置文件
主配置文件 指令说明user指定Nginx进程运行的用户和组默认是nobodyworker_processes指定工作进程的数量默认为1error_log指定错误日志文件的位置和级别默认为/var/log/nginx/error.logpid指定Nginx进程ID文件的位置默认为/var/run/nginx.pidevents配置事件模块包括工作进程的数量和类型http配置HTTP模块包括全局设置和监听端口server配置虚拟主机包括域名、根目录、日志文件等location配置请求匹配的规则包括资源路径、重定向、缓存等access_log指定访问日志文件的位置和格式默认为/var/log/nginx/access.logerror_log指定错误日志文件的位置和格式默认为/var/log/nginx/error.logsendfile指定是否开启sendfile传输模式默认为ontcp_nopush指定是否在发送数据前压缩缓冲区默认为onkeepalive_timeout指定长连接的超时时间默认为65client_max_body_size指定客户端请求的最大体长默认为1Mclient_body_buffer_size指定客户端请求体长缓冲区的大小默认为8kgzip指定是否开启gzip压缩默认为ongzip_vary指定是否在响应头中包含gzip压缩的信息默认为ongzip_proxied指定是否压缩代理请求的响应默认为anygzip_types指定需要压缩的MIME类型默认为text/htmlgzip_disable指定不需要压缩的MIME类型默认为msie6fastcgi_pass指定FastCGI后端服务器的地址和端口默认为127.0.0.1:9000uwsgi_pass指定uWSGI后端服务器的地址和端口默认为127.0.0.1:9000proxy_pass指定代理后端服务器的地址和端口默认为http://127.0.0.1:80proxy_set_header指定代理请求的头部信息默认为Host: $hostproxy_http_version指定代理请求的HTTP版本默认为1.1proxy_connect_timeout指定代理连接的超时时间默认为60sproxy_send_timeout指定代理发送请求的超时时间默认为60sproxy_read_timeout指定代理读取响应的超时时间默认为60sproxy_buffer_size指定代理请求缓冲区的大小默认为4kproxy_buffering指定是否启用代理缓冲区默认为onproxy_cache指定代理缓存的相关设置默认为offproxy_cache_key指定代理缓存键的生成规则默认为 s c h e m e scheme schemeproxy_host$request_uriproxy_cache_valid指定代理缓存的有效时间默认为1dproxy_cache_min_uses指定代理缓存的最小使用次数默认为1proxy_cache_use_stale指定代理缓存是否使用过时的数据默认为offproxy_cache_lock指定代理缓存是否锁定数据默认为onproxy_cache_lock_timeout指定代理缓存锁定数据的时间默认为5sproxy_cache_lock_age指定代理缓存锁定数据的时间默认为5sproxy_cache_lock_timeout指定代理缓存锁定数据的时间默认为5sproxy_cache_lock_age指定代理缓存锁定数据的时间默认为5sproxy_cache_lock_timeout指定代理缓存锁定
子配置文件 指令说明listen指定监听端口server_name指定域名多个通过空格分割location匹配请求中的uri资源地址root指定站点目录网站的根目录index指定站点的首页文件。用户访问的时候不加上任何的文件展示首页文件error_log指定错误状态码与对应的错误页面