-
Nginx (engine x) 是一个高性能的
-
其特点是占有内存少,
-
Nginx是由伊戈尔·赛索耶夫为
Nginx的作用
-
Http代理,反向代理:作为web服务器最常用的功能之一,尤其是反向代理
正向代理
反向代理
-
负载均衡
nginx提供两种的两种的的负载均衡策略。内置策略为轮询,加权轮询,Ip hash。扩展策略,就天马行空,只有你想不到,没有他做不到的!!!
轮询
加权轮询
Iphash
iphash对客户端请求的ip进行hash操作,然后根据hash的结果将同一个客户Ip请求分发同一台服务器进行处理,已解决session不贡献的问题!
动静分离
在我们软件开发过程中,有些请求需要后台去处理的,有些是不需要后台进行处理的(如:ccs、html、jpg、js等等文件),这些不需要后处理的就叫做静态文件。让动态网站里的动态网页根据一定规则把不变的资源和经常变的资源分开来,动静资源放开了以后,我们就可以根据静态的特点将其做缓存的操作,提高资源的响应速度!
Nginx安装
nginx 1.18.0稳定版 官网下载地址:http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure
make
make install
/usr/local/nginx/sbin/nginx
[root@localhost ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
--2022-04-16 06:22:47-- http://nginx.org/download/nginx-1.18.0.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5702::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1039530 (1015K) [application/octet-stream]
Saving to: ‘nginx-1.18.0.tar.gz’
100%[==============================================================================>] 1,039,530 672KB/s in 1.5s
2022-04-16 06:22:49 (672 KB/s) - ‘nginx-1.18.0.tar.gz’ saved [1039530/1039530]
[root@localhost ~]# ls
anaconda-ks.cfg nginx-1.18.0.tar.gz
[root@localhost ~]# tar -zxf nginx-1.18.0.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg nginx-1.18.0 nginx-1.18.0.tar.gz
[root@localhost ~]# cd nginx-1.18.0
[root@localhost nginx-1.18.0]# ll
total 768
drwxr-xr-x. 6 1001 1001 4096 Apr 16 06:22 auto
-rw-r--r--. 1 1001 1001 302863 Apr 21 2020 CHANGES
-rw-r--r--. 1 1001 1001 462213 Apr 21 2020 CHANGES.ru
drwxr-xr-x. 2 1001 1001 4096 Apr 16 06:22 conf
-rwxr-xr-x. 1 1001 1001 2502 Apr 21 2020 configure
drwxr-xr-x. 4 1001 1001 68 Apr 16 06:22 contrib
drwxr-xr-x. 2 1001 1001 38 Apr 16 06:22 html
-rw-r--r--. 1 1001 1001 1397 Apr 21 2020 LICENSE
drwxr-xr-x. 2 1001 1001 20 Apr 16 06:22 man
-rw-r--r--. 1 1001 1001 49 Apr 21 2020 README
drwxr-xr-x. 9 1001 1001 84 Apr 16 06:22 src
[root@localhost nginx-1.18.0]# ./configure
checking for OS
+ Linux 3.10.0-327.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
[root@localhost nginx-1.18.0]# make
make -f objs/Makefile
make[1]: Entering directory `/root/nginx-1.18.0'
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core