Administrator
发布于 2023-06-08 / 78 阅读
0
0

Nginx Install Theory

refer to : https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/
https://nginx.org/en/download.html

Choosing Between a Stable or a Mainline Version

NGINX Open Source is available in two versions:

  • Mainline – Includes the latest features and bug fixes and is always up to date. It is reliable, but it may include some experimental modules, and it may also have some number of new bugs.

  • Stable – Doesn’t include all of the latest features, but has critical bug fixes that are always backported to the mainline version. We recommend the stable version for production servers.

Installing NGINX Dependencies

  • Gcc compiler
yum install gcc automake autoconf libtool make
yum install gcc-c++
  • PCRE – Supports regular expressions. Required by the NGINX Core and Rewrite modules.
yum install -y pcre pcre-devel
  • zlib – Supports header compression. Required by the NGINX Gzip module.
yum install -y zlib zlib-devel
  • OpenSSL – Supports the HTTPS protocol. Required by the NGINX SSL module and others.
yum install -y openssl openssl-devel

Downloading the Sources

download page: https://nginx.org/en/download.html

wget https://nginx.org/download/nginx-1.22.1.tar.gz
tar -zxvf nginx-1.22.1.tar.gz
cd nginx-1.22.1

Configuring the Build Options

Configure options are specified with the ./configure script that sets up various NGINX parameters, including paths to source and configuration files, compiler options, connection processing methods, and the list of modules. The script finishes by creating the Makefile required to compile the code and install NGINX Open Source.

An example of options to the configure script (should be typed as a single line):

./configure
--sbin-path=/usr/local/nginx/nginx
--conf-path=/usr/local/nginx/nginx.conf
--pid-path=/usr/local/nginx/nginx.pid
--with-pcre=../pcre2-10.42
--with-zlib=../zlib-1.2.13
--with-http_ssl_module
--with-stream
--with-mail=dynamic
--add-module=/usr/build/nginx-rtmp-module
--add-dynamic-module=/usr/build/3party_module

常用场景下,我们直接执行./configure即可

下面是各参数的含义:
The configure script allows you to set paths to NGINX binary and configuration files, and to dependent libraries such as PCRE or SSL, in order to link them statically to the NGINX binary.

Parameter Description
--prefix=<PATH> Directory for NGINX files, and the base location for all relative paths set by the other configure script options (excluding paths to libraries) and for the path to the nginx.conf configuration file. Default: /usr/local/nginx.
--sbin-path=<PATH> Name of the NGINX executable file, which is used only during installation. Default: **/sbin/nginx
--conf-path=<PATH> Name of the NGINX configuration file. You can, however, always override this value at startup by specifying a different file with the -c <FILENAME> option on the nginx command line. Default: **conf/nginx.conf
--pid-path=<PATH> Name of the nginx.pid file, which stores the process ID of the nginx master process. After installation, the path to the filename can be changed with the pid directive in the NGINX configuration file. Default: **/logs/nginx.pid
--error-log-path=<PATH> Name of the primary log file for errors, warnings, and diagnostic data. After installation, the filename can be changed with the error_log directive in the NGINX configuration file. Default: **/logs/error.log
--http-log-path=<PATH> Name of the primary log file for requests to the HTTP server. After installation, the filename can always be changed with the access_log directive in the NGINX configuration file. Default: **/logs/access.log
--user=<NAME> Name of the unprivileged user whose credentials are used by the NGINX worker processes. After installation, the name can be changed with the user directive in the NGINX configuration file. Default: nobody
--group=<NAME> Name of the group whose credentials are used by the NGINX worker processes. After installation, the name can be changed with the user directive in the NGINX configuration file. Default: the value set by the --user option.
--with-pcre=<PATH> Path to the source for the PCRE library, which is required for regular expressions support in the location directive and the Rewrite module.
--with-pcre-jit Builds the PCRE library with “just-in-time compilation” support (the pcre_jit directive).
--with-zlib=<PATH> Path to the source for the zlib library, which is required by the Gzip module.

Selecting the NGINX Modules to Build

NGINX consists of a set of function‑specific modules, which are specified with configure script along with other build options.

Some modules are built by default – they do not have to be specified with the configure script. Default modules can however be explicitly excluded from the NGINX binary with the --without- option on the configure script.

./configure
--sbin-path=/usr/local/nginx/nginx
--conf-path=/usr/local/nginx/nginx.conf
--pid-path=/usr/local/nginx/nginx.pid
--with-http_ssl_module
--with-stream
--with-pcre=../pcre2-10.42
--with-zlib=../zlib-1.2.13
--without-http_empty_gif_module  

常用的module描述如下:

Module Name Description
http_access_module Accepts or denies requests from specified client addresses.
http_auth_basic_module Limits access to resources by validating the user name and password using the HTTP Basic Authentication protocol.
http_autoindex_module Processes requests ending with the forward-slash character (/) and produces a directory listing.
http_browser_module Creates variables whose values depend on the value of the User-Agent request header.
http_charset_module Adds the specified character set to the Content-Type response header. Can convert data from one character set to another.
http_empty_gif_module Emits a single-pixel transparent GIF.
http_fastcgi_module Passes requests to a FastCGI server.
http_geo_module Creates variables with values that depend on the client IP address.
http_gzip_module Compresses responses using gzip, reducing the amount of transmitted data by half or more.
http_limit_conn_module Limits the number of connections per a defined key, in particular, the number of connections from a single IP address.
http_limit_req_module Limits the request processing rate per a defined key, in particular, the processing rate of requests coming from a single IP address.
http_map_module Creates variables whose values depend on the values of other variables.
http_memcached_module Passes requests to a memcached server.
http_proxy_module Passes HTTP requests to another server.
http_referer_module Blocks requests with invalid values in the Referer header.
http_rewrite_module Changes the request URI using regular expressions and return redirects; conditionally selects configurations. Requires the PCRE library.
http_scgi_module Passes requests to an SCGI server.
http_ssi_module Processes SSI (Server Side Includes) commands in responses passing through it.
http_split_clients_module Creates variables suitable for A/B testing, also known as split testing.
http_upstream_hash_module Enables the generic Hash load-balancing method.
http_upstream_ip_hash_module Enables the IP Hash load-balancing method.
http_upstream_keepalive_module Enables keepalive connections.
http_upstream_least_conn_module Enables the Least Connections load-balancing method.
http_upstream_zone_module Enables shared memory zones.
http_userid_module Sets cookies suitable for client identification.
http_uwsgi_module Passes requests to a uwsgi server.

Many NGINX modules are not built by default, and must be listed on the configure command line to be built.

The mail, stream, geoip, image_filter, perl and xslt modules can be compiled as dynamic. See Dynamic Modules for details.

An example of the configure command that includes nondefault modules (should be typed as a single line):

 ./configure
--sbin-path=/usr/local/nginx/nginx
--conf-path=/usr/local/nginx/nginx.conf
--pid-path=/usr/local/nginx/nginx.pid
--with-pcre=../pcre2-10.42
--with-zlib=../zlib-1.2.13
--with-http_ssl_module
--with-stream
--with-mail 

Compile and install the build:

make
make install  

start NGINX

cd /usr/local/nginx/
cd sbin
./nginx 

Nginx配置文件格式化器

https://okcode.vip/dev/nginx-formatter

卸载Nginx

  
cd /usr/local/nginx/sbin
./nginx -s stop  
  
[root@wvppro sbin]# find / -iname nginx
/usr/local/nginx
/usr/local/nginx/sbin/nginx
/opt/Nginx
/opt/Nginx/nginx-1.22.1/objs/nginx

# 删除nginx相关文件
  
rm -rf  /usr/local/nginx
rm -rf  /opt/Nginx

查看Nginx额外安装了哪些模块

cd /usr/local/nginx/sbin

[root@wvppro sbin]# ./nginx -V
nginx version: nginx/1.22.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-18) (GCC) 
configure arguments: --with-http_realip_module

可以看到,Nginx额外安装了 http_realip_module 这个module


评论