9.pv,uv,ip,松耦合架构,Nginx配置文件三个模块

HTTP相关术语

# PV:页面独立浏览量

# UV:独立设备

# IP :独立IP

例:假设公司有一座大厦,大厦有100人,每个人有一台电脑和一部手机,上网都是通过nat转换出口,每个人点击网站2次, 请问对应的pv,uv,ip分别是多少?

PV:100 * 2+100 * 2 =400

UV:100+100=200

 IP:1

# 注:日pv千万量并不大

# SOA松耦合架构
它将应用程序的不同功能单元(称为服务)进行拆分,并通过这些服务之间定义良好的接口和契约联系起来。接口是采用中立的方式进行定义的,它应该独立于实现服务的硬件平台、操作系统和编程语言。这使得构建在各种各样的系统中的服务可以以一种统一和通用的方式进行交互。
相当于多个模块
# 例:京东是多个网站组合,拆分模块
一个电商公司,他的网站页面功能会有很多
注册
登录
首页
详情页
购物车
价格标签
留言
客服
支付中心
物流
仓储信息
订单相信
图片

哪部分出问题只需解决那一部分

Nginx简述

Nginx是一个开源的,高性能,可靠的HttpWeb服务,代理服务

开源:直接获取源代码

高性能:支持海量并发

可靠:服务稳定

Nginx3大主要功能

  • 支持网页服务:自身是静态Web服务,如apache,IIS...

    支持动态web服务:如php,java,python...

  • 负载均衡 \ 反向代理

    haproxy,lvs,F5

    支持http,rcp/udp

  • 缓存服务器

Nginx特点

  • 支持高并发
  • 占用资源少,消耗资源少
  • 可以做反向代理和加速缓存

Nginx应用场景

  1. 静态服务

  2. 代理服务

  3. 安全服务

    流行架构:Nginx+PHP(fastcgi_pass)LNMP

    ​ Nginx+Java(Proxy_pass) LNMT

    ​ Nginx+Python(uwsgi_pass)

静态服务器

# 以下服务没有办法直接连接数据库
nginx
apache
IIS
lighttpd
tengine
openresty-nginx
只需要看,请求是否调用数据库
# 不调用:静态请求

动态服务器

tomcat
resin
php
weblogic
jboss
# 调用:动态请求

Nginx和Apache区别

Nginx采用Epool网络模型,Apache采用Select模型

Select:当用户发起一次请求,select模型就会进行一次遍历扫描,从而导致性能低下

Epool: 当用户发起请求,epool模型会直接进行处理,效率高效,并无连接限制

安装Nginx

1.源码编译=>Nginx (1.版本随意 2.安装复杂 3.升级繁琐 4.规范 5.便于管理)

源码需要安装依赖yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree

2.epel仓库=>Nginx (1.版本较低 2.安装简单 3.配置不易读)

3.官方仓库=>Nginx (1.版本较新 2.安装简单 3.配置易读)

官方仓库安装

Nginx官网:TP

1.png

2.png

3.png

# 1.修改官方源
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

# 2.安装
[root@web01 ~]# yum install -y nginx

# 3.启动,并添加开机自启
[root@web01 conf.d]# systemctl start nginx
[root@web01 conf.d]# systemctl enable nginx

# 4.查看端口
[root@web01 ~]# netstat -lntup |grep 80

# 5.查看进程
[root@web01 ~]# ps -ef |grep [n]ginx


# 查看Nginx的版本
[root@web01 ~]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'                    
                                                                  ### 开发需要的模块

## nginx启停systemd管理
# 1.停止
[root@web01 conf.d]# systemctl stop nginx
# 2.启动
[root@web01 conf.d]# systemctl start nginx
# 3.重启
[root@web01 conf.d]# systemctl restart nginx
# 4.重新加载配置文件(不会重启)
[root@web01 conf.d]# systemctl reload nginx

## nginx二进制程序管理
# 1.停止
[root@web01 ~]# nginx -s stop
# 2.启动
[root@web01 ~]# nginx
# 3.重新加载配置文件(不会重启)
[root@web01 ~]# nginx -s reload

nginx相关配置文件

[root@web01 ~]# ll /etc/nginx/
total 36
drwxr-xr-x 2 root root   26 May 14 19:07 conf.d
-rw-r--r-- 1 root root 1007 Apr 21 23:07 fastcgi_params
-rw-r--r-- 1 root root 2837 Apr 21 23:07 koi-utf
-rw-r--r-- 1 root root 2223 Apr 21 23:07 koi-win
-rw-r--r-- 1 root root 5231 Apr 21 23:07 mime.types
lrwxrwxrwx 1 root root   29 May 14 18:59 modules -> ../../usr/lib64/nginx/modules
-rw-r--r-- 1 root root  643 Apr 21 23:05 nginx.conf
-rw-r--r-- 1 root root  636 Apr 21 23:07 scgi_params
-rw-r--r-- 1 root root  664 Apr 21 23:07 uwsgi_params
-rw-r--r-- 1 root root 3610 Apr 21 23:07 win-utf


# 1.nginx的主配置文件
drwxr-xr-x 2 root root   26 May 14 19:07 conf.d

# 2.nginx代理文件
-rw-r--r-- 1 root root  636 Apr 21 23:07 scgi_params
-rw-r--r-- 1 root root  664 Apr 21 23:07 uwsgi_params
-rw-r--r-- 1 root root 1007 Apr 21 23:07 fastcgi_params

# 3.字符编码文件
-rw-r--r-- 1 root root 2837 Apr 21 23:07 koi-utf
-rw-r--r-- 1 root root 2223 Apr 21 23:07 koi-win
-rw-r--r-- 1 root root 3610 Apr 21 23:07 win-utf

# 4.浏览器支持的打开格式
-rw-r--r-- 1 root root 5231 Apr 21 23:07 mime.types

# 5. nginx相关命令文件
-rwxr-xr-x 1 root root 1342640 Apr 21 23:07 /usr/sbin/nginx
-rwxr-xr-x 1 root root 1461544 Apr 21 23:07 /usr/sbin/nginx-debug

# 6.相关日志文件
-rw-r--r-- 1 root root 351 Apr 21 23:05 /etc/logrotate.d/nginx   # 系统默认日志切割

[root@web01 /var/log/nginx]# ll
total 20
-rw-r----- 1 nginx adm 9543 May 15 00:24 access.log          # 访问日志
-rw-r----- 1 nginx adm 6904 May 15 00:44 error.log           # 错误日志
 

Nginx配置文件

主要分成三个模块

  • 核心模块
  • 事件驱动模块
  • HTTP模块

Nginx配置文件详解

[root@web01 ~]# vim /etc/nginx/nginx.conf 
################################## 核心模块 ########################################
# nginx启动用户
user nginx;
# worker进程数
worker_processes auto;                      # auto 以你cpu核心数决定多少
# 错误日志的路径 和 级别
error_log /var/log/nginx/error.log warn;
# pid文件的路径
pid /var/run/nginx.pid;

###############################  事件驱动模块 #######################################
events {
# 每一个worker进程允许连接数量
worker_connections 1024;
}

###################################  HTTP模块 ######################################
http {
# 包含指定文件的内容,该文件是nginx浏览器允许访问的文件类型
include /etc/nginx/mime.types;
# 默认需要下载类型的格式
default_type application/octet-stream;
# 日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format zidingyi 'zls - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# 日志路径 和 指定格式
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/zls_access.log zidingyi;
# 高效传输文件
sendfile on;
#tcp_nopush on;
# 长连接的超时时间
keepalive_timeout 65;
# 开启gzip压缩
#gzip on;
# 包含所有下面路径下conf结尾的文件
include /etc/nginx/conf.d/*.conf;
}


# 检测语法错误
[root@web01 /etc/nginx]# nginx -t
posted @ 2020-06-01 23:19  柯正  阅读(415)  评论(0)    收藏  举报