Please wait...

小波Note

四川 · 成都市多云14 ℃
English

Install Nginx on CentOS

成都Sun, January 1, 2023 at 2 PM5.88k125Estimated reading time 11 min
QR code
FavoriteCtrl + D

Install dependencies

bash
        yum install gcc
yum install pcre pcre-devel
yum install openssl openssl-devel
yum install zlib zlib-devel
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel
yum install gd gd-devel

    

Compile

Tips

Enter the directory where the file is unzipped You can specify the --prefix directory, which is installed by default to /usr/local/nginx

bash
        ./configure --prefix=xxx --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_xslt_module=dynamic --with-http_image_filter_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-stream --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-compat

    

The above command is expanded as follows, and you can delete it according to your own needs

bash
        --prefix=xxx
Specify the installation directory as xxx. All binary files, configuration files, etc., will be installed into this directory.

--with-select_module
Enable the select module for the event-driven mechanism, using the select system call to handle high-concurrency connections.

--with-poll_module
Enable the poll module, similar to select but with better performance for handling a large number of concurrent connections, using the poll system call.

--with-threads
Enable multi-threading support, allowing Nginx to utilize multi-core processors and improve concurrent processing capabilities.

--with-file-aio
Enable asynchronous file I/O support to enhance file read and write performance, especially under high load conditions.

--with-http_ssl_module
Enable the HTTP SSL module to support HTTPS protocol, enabling secure encrypted communication.

--with-http_v2_module
Enable the HTTP/2 module to support the HTTP/2 protocol, improving webpage loading speed and performance.

--with-http_realip_module
Enable the Real IP module to allow Nginx to obtain the client's real IP address, commonly used in reverse proxy environments.

--with-http_addition_module
Enable the HTTP Addition module, allowing custom content to be added at the beginning or end of responses.

--with-http_xslt_module
Enable the XSLT module to allow the use of XSLT to transform XML content within Nginx.

--with-http_xslt_module=dynamic
Dynamically load the XSLT module instead of statically integrating it during compilation.

--with-http_image_filter_module
Enable the Image Filter module to support image processing tasks such as cropping and scaling.

--with-http_image_filter_module=dynamic
Dynamically load the Image Filter module instead of statically integrating it during compilation.

--with-http_sub_module
Enable the substitution module to allow text replacement within response content.

--with-http_dav_module
Enable the WebDAV module to support the Web Distributed Authoring and Versioning protocol.

--with-http_flv_module
Enable the FLV module to support the transmission of Flash video streams.

--with-http_mp4_module
Enable the MP4 module to support resume and fast-forward capabilities for MP4 files.

--with-http_gunzip_module
Enable the GUNZIP module to allow the decompression of gzip-compressed response content.

--with-http_gzip_static_module
Enable the Static Gzip module to support the direct transmission of pre-compressed static files, reducing the overhead of on-the-fly compression.

--with-http_auth_request_module
Enable the Authentication Request module to allow access control and authentication through sub-requests.

--with-http_random_index_module
Enable the Random Index module to support randomly selecting an index file when multiple index files are available.

--with-http_secure_link_module
Enable the Secure Link module to generate and verify URLs with encrypted signatures, enhancing link security.

--with-http_degradation_module
Enable the Degradation module to automatically degrade certain functionalities when resources are insufficient or load is high, maintaining the availability of core services.

--with-http_slice_module
Enable the Slice module to support sliced transmission of large files, improving download efficiency and concurrency performance.

--with-http_stub_status_module
Enable the Status module to provide simple Nginx status information, such as active connections and request counts.

--with-stream
Enable the Stream module to support proxying and load balancing of TCP/UDP traffic.

--with-stream=dynamic
Dynamically load the Stream module instead of statically integrating it during compilation.

--with-stream_ssl_module
Enable the Stream SSL module to support SSL encryption for TCP/UDP traffic.

--with-stream_realip_module
Enable the Stream Real IP module to obtain the client's real IP address, used for TCP/UDP traffic.

--with-stream_ssl_preread_module
Enable the Stream SSL Preread module to read partial data before the SSL handshake, used for more advanced traffic processing.

--with-compat
Enable the Compatibility module to allow loading dynamic modules compatible with the current compiled version, enhancing module flexibility and scalability.

    
Collapse

Install

bash
        make
make install

    

Run / Reload / Stop

bash
        // Start
xxx/xxx/sbin/nginx
// Reload
xxx/xxx/sbin/nginx -s reload
// Stop
xxx/xxx/sbin/nginx -s stop

    
Astral