欢迎来到我的博客园

Nginx 基础介绍

Nginx 基础介绍

什么是nginx?

Nginx是由俄罗斯开发工作者igor Sysoev使用c语音开发的web服务器。Nginx是可以跨平台运行的Web服务器,可以在Linux FreeBSD Solaris,Windows等平台上运行。

Nginx 特点

Nginx具有,快速 高扩展性,高可靠性,低内存,高并发等特点。

Nginx源码安装(Linux)

Nginx依赖包处理

安装linux我们需要提前安装后gcc zlib zlib-devel pcre pcre-devel等依赖包,可以使用yum安装这些包。

gcc编译器,gcc是我们在configure编译阶段使用的工具,没有gcc我们无法编译Nginx的源码。 yum install -y gcc

zlib zlib-devel这两个库,nginx会用来做gzip压缩时候用到的,nginx有http_gzip_module模块需要使用这个包。 yum install -y zlib zlib-devel。

PCRE(perl compatible regural expression,perl兼容正则表达式), http_rewrite_module模块会需要使用到此包。yum install -y pcre pcre-devel

获取源码包

wget http://nginx.org/download/nginx-1.20.2.tar.gz 可以从官网下载我们需要的源码包。

[root@node1 install]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
--2022-08-01 09:02:57--  http://nginx.org/download/nginx-1.20.2.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1062124 (1.0M) [application/octet-stream]
Saving to: ‘nginx-1.20.2.tar.gz’

100%[==================================================================================================================================================================================================================================>] 1,062,124    301KB/s   in 3.5s   

2022-08-01 09:03:06 (301 KB/s) - ‘nginx-1.20.2.tar.gz’ saved [1062124/1062124]

解压安装包

tar -xvf nginx-1.20.2.tar.gz  命令来解压我们的源码包。

[root@node1 install]# tar -xvf nginx-1.20.2.tar.gz 
nginx-1.20.2/
nginx-1.20.2/auto/
nginx-1.20.2/conf/
nginx-1.20.2/contrib/
nginx-1.20.2/src/
nginx-1.20.2/configure
nginx-1.20.2/LICENSE
nginx-1.20.2/README
nginx-1.20.2/html/
nginx-1.20.2/man/
nginx-1.20.2/CHANGES.ru
nginx-1.20.2/CHANGES
nginx-1.20.2/man/nginx.8
nginx-1.20.2/html/50x.html
nginx-1.20.2/html/index.html
nginx-1.20.2/src/core/

编译安装Nginx

首先,我们需要进入到解压后的文件目录中,然后按顺序执行 configure, make, make install命令就可以安装nginx了。

[root@node1 install]# cd nginx-1.2
[root@node1 nginx-1.20.2]# groupadd -g 1001 www
[root@node1 nginx-1.20.2]# useradd -m -d /usr/pkgs/nginx/ -g www -p www www
[root@node1 nginx-1.20.2]# ./configure --prefix=/usr/pkgs/nginx --user=www --group=www --with-http_stub_status_module
[root@node1 nginx-1.20.2]# make
[root@node1 nginx-1.20.2]# make install

configure make make install功能介绍

configure命令会检查操作系统内核和已安装的软件,参数解析,中间目录生成,以及根据各种configure的参数生成c源码文件和Makefile文件。

make 命令根据configure生成的Makefile文件编译Nginx软件,生成目标文件和最终的二进制文件。

make install文件根据configure执行时的参数,将Nginx部署到指定安装目录,包括相关目录创建,二进制和配置文件复制到对应的目录中。

configure参数详解

configure的参数有很多,我们可以使用./configure --help | more来查看configure支持的参数,每个安装包的configure 参数不一样,我们在安装之前需要阅读,并根据实际需要来指定参数。

  --help                             print this message
  --prefix=PATH                      软件安装完成后的部署目录
  --sbin-path=PATH                   软件sbin/nginx路径,可以不指定,默认为<prefix>/sbin/nginx
  --modules-path=PATH                modules的目录
  --conf-path=PATH                   配置文件路径,可以不指定,默认为<prefix>/conf/
  --error-log-path=PATH              程序日志路径,可以不指定,默认为<prefix>/logs/error.log
  --pid-path=PATH                    程序pid文件路径,可以不指定,默认为<prefix>/logs/nginx.pid
  --lock-path=PATH                   程序lock文件路径,可以不指定,默认为<prefix>/logs/nginx.lock
  --user=USER                        指定程序的owner
  --group=GROUP                      指定程序的group
  --build=NAME                       set build name
  --builddir=DIR                     configure命令产生的文件的临时目录
  --with-perl=PATH                   指定第三方的perl包的路径--http-log-path=PATH               指定httplog的路径,可以不指定,默认为<prefix>/logs/access.log
  --http-client-body-temp-path=PATH  指定http请求包体的暂时处理位置,可以不指定,默认为<prefix>/client_boty_temp
  --http-proxy-temp-path=PATH        指定反向代理时,产生的http包体的临时存放位置,可以不指定,默认为<prefix>/proxy_temp
  --http-fastcgi-temp-path=PATH      指定fstcgi所产生的临时文件存放位置,可以不指定,默认为<prefix>/fastcgi_temp
  --http-uwsgi-temp-path=PATH        指定uwsgi所产生的临时文件存放位置,可以不指定,默认为<prefix>/uwsgi_temp
  --http-scgi-temp-path=PATH         指定scgi所产生的临时文件存放位置,可以不指定默认为<prefix>/scgi_temp

 

另外我们编译时,如果有一些编译器参数需要修改,可以指定:

编译相关的参数:
  --with-cc=PATH                     指定c编译器路径
  --with-cpp=PATH                    指定c预编译器路径
  --with-cc-opt=OPTIONS              set additional C compiler options
  --with-ld-opt=OPTIONS              set additional linker options
  --with-cpu-opt=CPU                 build for the specified CPU, valid values:
                                     pentium, pentiumpro, pentium3, pentium4,
                                     athlon, opteron, sparc32, sparc64, ppc64

 

依赖软件相关的参数:

因为我们安装的时候需要解决依赖包,如果我们确定了不需要那些功能,我们可以通过如下参数来修改编译方式。

  --without-pcre                     不使用正则表达式。nginx cfg文件不能使用正则表达式。
  --with-pcre                        force PCRE library usage
  --with-pcre=DIR                    指定PCRE包的位置
  --with-pcre-opt=OPTIONS            set additional build options for PCRE
  --with-pcre-jit                    build PCRE with JIT compilation support
  --with-zlib=DIR                    指定zlib包的位置
  --with-zlib-opt=OPTIONS            set additional build options for zlib
  --with-zlib-asm=CPU                use zlib assembler sources optimized
                                     for the specified CPU, valid values:
                                     pentium, pentiumpro

  --with-libatomic                   force libatomic_ops library usage
  --with-libatomic=DIR               set path to libatomic_ops library sources

  --with-openssl=DIR                 set path to OpenSSL library sources
  --with-openssl-opt=OPTIONS         set additional build options for OpenSSL

 

另外Nginx是由许多模块组成的,我们在安装的时候,可以根据项目的需要来指定安装或不安装哪些模块。

Nginx模块在我们编译时,可以分为5类:

事件模块

默认安装的Nginx模块

默认不安装的模块

邮件代理模块

其他模块

事件模块:

事件模块:
  --with-select_module               select模块多路复用功能,用于支持服务器,提供高并发连接。如果机器上有epoll,则不会安装select模块
  --without-select_module            不安装select--with-poll_module                 与select功能类似,poll模块不如epoll模块
  --without-poll_module              不安装poll模块
  --with-threads                     安装threads模块,默认不安装。
  --with-file-aio                    linux默认不安装此模块

默认安装的http模块:

  --without-http_charset_module      disable ngx_http_charset_module
  --without-http_gzip_module         disable ngx_http_gzip_module
  --without-http_ssi_module          disable ngx_http_ssi_module
  --without-http_userid_module       disable ngx_http_userid_module
  --without-http_access_module       disable ngx_http_access_module
  --without-http_auth_basic_module   disable ngx_http_auth_basic_module
  --without-http_mirror_module       disable ngx_http_mirror_module
  --without-http_autoindex_module    disable ngx_http_autoindex_module
  --without-http_geo_module          disable ngx_http_geo_module
  --without-http_map_module          disable ngx_http_map_module
  --without-http_split_clients_module disable ngx_http_split_clients_module
  --without-http_referer_module      disable ngx_http_referer_module
  --without-http_rewrite_module      disable ngx_http_rewrite_module
  --without-http_proxy_module        disable ngx_http_proxy_module
  --without-http_fastcgi_module      disable ngx_http_fastcgi_module
  --without-http_uwsgi_module        disable ngx_http_uwsgi_module
  --without-http_scgi_module         disable ngx_http_scgi_module
  --without-http_grpc_module         disable ngx_http_grpc_module
  --without-http_memcached_module    disable ngx_http_memcached_module
  --without-http_limit_conn_module   disable ngx_http_limit_conn_module
  --without-http_limit_req_module    disable ngx_http_limit_req_module
  --without-http_empty_gif_module    disable ngx_http_empty_gif_module
  --without-http_browser_module      disable ngx_http_browser_module
  --without-http_upstream_hash_module
                                     disable ngx_http_upstream_hash_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module
  --without-http_upstream_least_conn_module
                                     disable ngx_http_upstream_least_conn_module
  --without-http_upstream_random_module
                                     disable ngx_http_upstream_random_module
  --without-http_upstream_keepalive_module
                                     disable ngx_http_upstream_keepalive_module
  --without-http_upstream_zone_module
                                     disable ngx_http_upstream_zone_module
  --without-stream_limit_conn_module disable ngx_stream_limit_conn_module
  --without-stream_access_module     disable ngx_stream_access_module
  --without-stream_geo_module        disable ngx_stream_geo_module
  --without-stream_map_module        disable ngx_stream_map_module
  --without-stream_split_clients_module
                                     disable ngx_stream_split_clients_module
  --without-stream_return_module     disable ngx_stream_return_module
  --without-stream_set_module        disable ngx_stream_set_module
  --without-stream_upstream_hash_module
                                     disable ngx_stream_upstream_hash_module
  --without-stream_upstream_least_conn_module
                                     disable ngx_stream_upstream_least_conn_module
  --without-stream_upstream_random_module
                                     disable ngx_stream_upstream_random_module
  --without-stream_upstream_zone_module
                                     disable ngx_stream_upstream_zone_module

默认不安装的模块:

  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_v2_module              enable ngx_http_v2_module
  --with-http_realip_module          enable ngx_http_realip_module
  --with-http_addition_module        enable ngx_http_addition_module
  --with-http_xslt_module            enable ngx_http_xslt_module
  --with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module
  --with-http_image_filter_module    enable ngx_http_image_filter_module
  --with-http_image_filter_module=dynamic
                                     enable dynamic ngx_http_image_filter_module
  --with-http_geoip_module           enable ngx_http_geoip_module
  --with-http_geoip_module=dynamic   enable dynamic ngx_http_geoip_module
  --with-http_sub_module             enable ngx_http_sub_module
  --with-http_dav_module             enable ngx_http_dav_module
  --with-http_flv_module             enable ngx_http_flv_module
  --with-http_mp4_module             enable ngx_http_mp4_module
  --with-http_gunzip_module          enable ngx_http_gunzip_module
  --with-http_gzip_static_module     enable ngx_http_gzip_static_module
  --with-http_auth_request_module    enable ngx_http_auth_request_module
  --with-http_random_index_module    enable ngx_http_random_index_module
  --with-http_secure_link_module     enable ngx_http_secure_link_module
  --with-http_degradation_module     enable ngx_http_degradation_module
  --with-http_slice_module           enable ngx_http_slice_module
  --with-http_stub_status_module     enable ngx_http_stub_status_module
  --with-stream                      enable TCP/UDP proxy module
  --with-stream=dynamic              enable dynamic TCP/UDP proxy module
  --with-stream_ssl_module           enable ngx_stream_ssl_module
  --with-stream_realip_module        enable ngx_stream_realip_module
  --with-stream_geoip_module         enable ngx_stream_geoip_module
  --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
  --with-stream_ssl_preread_module   enable ngx_stream_ssl_preread_module

邮件相关的模块

  --with-mail                        enable POP3/IMAP4/SMTP proxy module
  --with-mail=dynamic                enable dynamic POP3/IMAP4/SMTP proxy module
  --with-mail_ssl_module             enable ngx_mail_ssl_module
  --without-mail_pop3_module         disable ngx_mail_pop3_module
  --without-mail_imap_module         disable ngx_mail_imap_module
  --without-mail_smtp_module         disable ngx_mail_smtp_module

其他模块

 --add-module=PATH                  enable external module
  --add-dynamic-module=PATH          enable dynamic external module
 --without-http                     disable HTTP server
  --without-http-cache               disable HTTP cache
  --with-file-aio                    enable file AIO support

 

 

 

posted @ 2022-08-02 20:37  panzq  阅读(148)  评论(0编辑  收藏  举报