CentOS 7.2 a detailed tutorial for installing Nginx 1.10.2

  • 2020-05-13 04:25:51
  • OfStack

1. Install using Yum (recommended)

It is recommended to install Yum. The overall process is very simple, and it is not easy to make mistakes. If no special configuration is needed, it is recommended to install Yum.

1. Install and install the epel-release source


yum install epel-release
yum update
yum install nginx

2. Perform relevant application operations


systemctl start nginx # Start the 
systemctl stop nginx # stop 
systemctl restart nginx # restart 
systemctl status nginx # View running status 
systemctl enable nginx # Powered up 

Set up a firewall

You may not be able to access IP after startup, so you need to step 1 to set up a firewall


firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

At this point, the installation is complete.

Refer to the article: https: / / www digitalocean. com/community/tutorials/how - to - install - nginx on -- centos - 7

2. Source code compilation and installation

1. Install the tools required for compilation


yum groupinstall "Development Tools"
yum install wget

2, to the official website to download the latest source code (https: / / nginx org en /)


cd /usr/local/src
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxvf nginx-1.10.2.tar.gz

3. Install dependency packages


yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel

zlib: provide gzip module for nginx, which requires zlib library support, transmit data and package, save traffic (but consume resources)

openssl: provides ssl functionality for nginx

pcre: override the rewrite function to support addresses

4. Create users and groups to run nginx


groupadd nginx
useradd -g nginx -M nginx  � s /sbin/nologin

The -g parameter specifies one group for the nginx user. The -M parameter guarantees that it does not automatically generate the home directory.

5. Compile the source code

Use the first ./configure �help See build help:


[root@localhost nginx-1.10.2]# ./configure --help
 
 --help        print this message
 
 --prefix=PATH      set installation prefix #Nginx The root path of the installation , The default is  /usr/local/nginx . 
 --sbin-path=PATH     set nginx binary pathname # The specified nginx2 The path to the base file , The default is PATH/sbin/nginx . 
 --modules-path=PATH    set modules path #Perl Module position 
 --conf-path=PATH     set nginx.conf pathname # set nginx Profile address, default is PATH/conf/nginx.conf . 
 --error-log-path=PATH    set error log pathname # Error file path, default is  PATH/logs/error.log . 
 --pid-path=PATH     set nginx.pid pathname # master process pid Write to the file location , Usually in the var/run The default is  PATH/logs/nginx.pid . 
 --lock-path=PATH     set nginx.lock pathname # Shared memory mutex file path 
 
 --user=USER      set non-privileged user for worker processes # Specifies a non-privileged user for the program to run 
 --group=GROUP      set non-privileged group for worker processes # Specifies a non-privileged user group for the program to run 
 
 --build=NAME      set build name # Compile the name 
 --builddir=DIR      set build directory # Point to compiled directory 
 
 --with-select_module    enable select module  Allowed or not allowed SELECT Pattern, if configure I didn't find the right model, like, kqueue(sun os) , epoll(linux kenel 2.6+) , rtsig( Real-time signal )
 --without-select_module   disable select module  disable select Module support 
 --with-poll_module     enable poll module  To enable the poll Module support (function with select The same with select Same property, is 1 A polling mode , Not recommended for use in high-load environments) 
 --without-poll_module    disable poll module  disable poll Module support 
 
 --with-threads      enable thread pool support
 
 --with-file-aio     enable file AIO support # for freeBSD4.3+ and linux2.6.22+ System enabled asynchrony io
 
 --with-ipv6      enable IPv6 support # To enable the ipv6 support 
 
# A module that is disabled by default 
 --with-http_ssl_module    enable ngx_http_ssl_module # To support https Request, installed openssl
 --with-http_v2_module    enable ngx_http_v2_module # To enable the HTTP V2
 --with-http_realip_module   enable ngx_http_realip_module # This module supports displaying real sources IP Address, mainly used for NGINX Do front-end load balancing server use 
 --with-http_addition_module  enable ngx_http_addition_module # Output filter , Enable you to pass through at request 1 a location The front or back tense is in this location Add content itself 
 --with-http_xslt_module   enable ngx_http_xslt_module # This module is 1 A filter that it can pass through XSLT Template transformation XML The reply 
 --with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module 
 --with-http_image_filter_module enable ngx_http_image_filter_module # Image filter , Process the image before delivering it to the customer ( Need to be libgd library )
 --with-http_image_filter_module=dynamic
          enable dynamic ngx_http_image_filter_module 
 --with-http_geoip_module   enable ngx_http_geoip_module # Create based on MaxMind GeoIP Matching client address 
 --with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module
 --with-http_sub_module    enable ngx_http_sub_module # This module can be used in nginx Search and replace the text in the response 
 --with-http_dav_module    enable ngx_http_dav_module # Specify permissions for files and directories, limiting different types of users to have different access to the page 
 --with-http_flv_module    enable ngx_http_flv_module # This module supports yes FLV ( flash Drag the file to play 
 --with-http_mp4_module    enable ngx_http_mp4_module # support H.264/AAC Files are pseudo-streaming media 
 --with-http_gunzip_module   enable ngx_http_gunzip_module # For not supporting gzip Coded client , This module is used to extract precompressed content for customers 
 --with-http_gzip_static_module  enable ngx_http_gzip_static_module # This module is 1 Precompressed files are transferred to open Gzip Compressed client before checking if it already exists to" .gz "End of the compressed file, so that the file will not be repeated compression 
 --with-http_auth_request_module enable ngx_http_auth_request_module 
 --with-http_random_index_module enable ngx_http_random_index_module # Select from the directory 1 Random home page 
 --with-http_secure_link_module  enable ngx_http_secure_link_module # This module provides 1 mechanisms , It will be 1 The hash values are linked to 1 a url In the , so , Only those using the correct password can compute the link 
 --with-http_degradation_module  enable ngx_http_degradation_module # Allows return when out of memory 204 or 444 code 
 --with-http_slice_module   enable ngx_http_slice_module 
 --with-http_stub_status_module  enable ngx_http_stub_status_module # achieve 1 some nginx The output state information is available RRDtool Or a similar tool to draw a diagram 
# Module enabled by default 
 --without-http_charset_module  disable ngx_http_charset_module # recoding web page 
 --without-http_gzip_module   disable ngx_http_gzip_module # with -with-http_gzip_static_module function 1 sample 
 --without-http_ssi_module   disable ngx_http_ssi_module # Provide input side processing server include file ( SSI ) filters are currently supported SSI The list of commands is incomplete 
 --without-http_userid_module  disable ngx_http_userid_module # Used to process subsequent requests from the client cookies
 --without-http_access_module  disable ngx_http_access_module # For the 1 Simple host-based access control. allow / Rejected based on ip address 
 --without-http_auth_basic_module disable ngx_http_auth_basic_module # You can use username and password based http Basic authentication methods to protect your site or parts of its content 
 --without-http_autoindex_module disable ngx_http_autoindex_module # Automatically generates a list of directories only in ngx_http_index_module The module makes a request when it does not find the index file. 
 --without-http_geo_module   disable ngx_http_geo_module # create 1 A variable whose value depends on the client IP address 
 --without-http_map_module   disable ngx_http_map_module # Use any key / Value pairs set configuration variables 
 --without-http_split_clients_module disable ngx_http_split_clients_module # Used to partition users based on certain conditions. Conditions such as: ip Address, header, cookies , etc. 
 --without-http_referer_module  disable ngx_http_referer_module # Used to filter requests and reject headers Referer Request with incorrect value 
 --without-http_rewrite_module  disable ngx_http_rewrite_module # Allows changes using regular expressions URI , and turn and select the configuration according to the variables 
 --without-http_proxy_module  disable ngx_http_proxy_module # About proxy servers 
 --without-http_fastcgi_module  disable ngx_http_fastcgi_module # allow Nginx  with FastCGI  Processes interact and are controlled by passing parameters FastCGI  Process work. 
 --without-http_uwsgi_module  disable ngx_http_uwsgi_module # Used to use uwsgi Agreement, uWSGI server-related 
 --without-http_scgi_module   disable ngx_http_scgi_module # Used to enable SCGI Agreement support, SCGI Agreement is CGI Protocol substitution. 
 --without-http_memcached_module disable ngx_http_memcached_module # Used to provide simple caching to improve system efficiency 
 --without-http_limit_conn_module disable ngx_http_limit_conn_module # Allow you to 1 A limit on the number of connections 1 A given session or 1 A particular event 
 --without-http_limit_req_module disable ngx_http_limit_req_module # Allow you to 1 Limit the number of requests to three addresses 1 A given session or 1 A particular event 
 --without-http_empty_gif_module disable ngx_http_empty_gif_module # It's resident in memory 1 a 1*1 The transparent GIF Images can be called very quickly 
 --without-http_browser_module  disable ngx_http_browser_module # Used to create a value that depends on the request header 
 --without-http_upstream_hash_module
          disable ngx_http_upstream_hash_module # For simple load balancing 
 --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_keepalive_module
          disable ngx_http_upstream_keepalive_module
 --without-http_upstream_zone_module
          disable ngx_http_upstream_zone_module
 
 --with-http_perl_module   enable ngx_http_perl_module # This module allows nginx use SSI call perl Or do it directly perl( Use can degrade performance )
 --with-http_perl_module=dynamic enable dynamic ngx_http_perl_module
 --with-perl_modules_path=PATH  set Perl modules path # set perl The module path 
 --with-perl=PATH     set perl binary pathname # set perl Library file path 
 
 --http-log-path=PATH    set http access log pathname # set access log The path 
 --http-client-body-temp-path=PATH set path to store http client request body temporary files # set http The client requests a temporary file path 
 --http-proxy-temp-path=PATH  set path to store http proxy temporary files # set http Proxy temporary file path 
 --http-fastcgi-temp-path=PATH  set path to store http fastcgi temporary files # set http fastcgi Temporary file path 
 --http-uwsgi-temp-path=PATH  set path to store http uwsgi temporary files # set http uwsgi Temporary file path 
 --http-scgi-temp-path=PATH   set path to store http scgi temporary files # set http scgi Temporary file path 
 
 --without-http      disable HTTP server # Completely disabled http The module , If you just want to support mall, You can use this setting 
 --without-http-cache    disable HTTP cache # In the use of upstream When the module ,nginx Ability to configure local cache content , This option disables caching 
 
 --with-mail      enable POP3/IMAP4/SMTP proxy module # The activation POP3/IMAP4/SMTP Agent module , Default not activated 
 --with-mail=dynamic    enable dynamic POP3/IMAP4/SMTP proxy module
 --with-mail_ssl_module    enable ngx_mail_ssl_module #SMTP You can use SSL / TLS. The configuration is already defined HTTP SSL Module, but does not support client certificate detection 
 --without-mail_pop3_module   disable ngx_mail_pop3_module # To enable the mail After the module , Disable alone pop3 The module 
 --without-mail_imap_module   disable ngx_mail_imap_module # To enable the mail After the module , Disable alone imap The module 
 --without-mail_smtp_module   disable ngx_mail_smtp_module # To enable the mail After the module , Disable alone smtp The 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
 --without-stream_limit_conn_module disable ngx_stream_limit_conn_module
 --without-stream_access_module  disable ngx_stream_access_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_zone_module
          disable ngx_stream_upstream_zone_module
 
 --with-google_perftools_module  enable ngx_google_perftools_module # Debugging, analyze the program performance bottleneck 
 --with-cpp_test_module    enable ngx_cpp_test_module
 
 --add-module=PATH     enable external module # Enable external module support 
 --add-dynamic-module=PATH   enable dynamic external module
# Compile the relevant parameters 
 --with-cc=PATH      set C compiler pathname # If you want to set 1 No default path Under the c The compiler 
 --with-cpp=PATH     set C preprocessor pathname # Set up the c The relative path of the preprocessor 
 --with-cc-opt=OPTIONS    set additional C compiler options # Set up the C Compiler parameter 
 --with-ld-opt=OPTIONS    set additional linker options # Contains the path to the connection library and the run path 
 --with-cpu-opt=CPU     build for the specified CPU, valid values:pentium, pentiumpro, pentium3, pentium4,athlon, opteron, sparc32, sparc64, ppc64 # Specify compiled CPU
 
 --without-pcre      disable PCRE library usage # disable pcre library 
 --with-pcre      force PCRE library usage # To enable the pcre library 
 --with-pcre=DIR     set path to PCRE library sources # Point to the pcre Library directory 
 --with-pcre-opt=OPTIONS   set additional build options for PCRE # At compile time pcre The library sets additional parameters 
 --with-pcre-jit     build PCRE with JIT compilation support
 
 --with-md5=DIR      set path to md5 library sources # Point to the md5 Library directory 
 --with-md5-opt=OPTIONS    set additional build options for md5 # At compile time md5 The library sets additional parameters 
 --with-md5-asm      use md5 assembler sources # use md5 Assembler source 
 
 --with-sha1=DIR     set path to sha1 library sources # Point to the sha1 The library catalog 
 --with-sha1-opt=OPTIONS   set additional build options for sha1 # At compile time sha1 The library sets additional parameters 
 --with-sha1-asm     use sha1 assembler sources # use sha1 Assembler source 
 
 --with-zlib=DIR     set path to zlib library sources # Point to the zlib The library catalog 
 --with-zlib-opt=OPTIONS   set additional build options for zlib # At compile time zlib Set additional parameters 
 --with-zlib-asm=CPU    use zlib assembler sources optimized for the specified CPU, valid values: pentium, pentiumpro # For the specified CPU use zlib Assembly source optimization 
 
 --with-libatomic     force libatomic_ops library usage #  Provides for the implementation of atomic memory update operations 1 An architecture 
 --with-libatomic=DIR    set path to libatomic_ops library sources # Point to the libatomic_ops The installation directory 
 
 --with-openssl=DIR     set path to OpenSSL library sources # Point to the openssl The installation directory 
 --with-openssl-opt=OPTIONS   set additional build options for OpenSSL # At compile time openssl Set additional parameters 
 
 --with-debug      enable debug logging # To enable the debug The log 

Set the compilation parameters:


./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--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 \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-pcre \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module

Then perform make && make install Add scripts to the centos7 startup, restart, reload configuration for nginx after installation:


vi /usr/lib/systemd/system/nginx

Add content:


systemctl start nginx # Start the 
systemctl stop nginx # stop 
systemctl restart nginx # restart 
systemctl status nginx # View running status 
systemctl enable nginx # Powered up 
0

Related operations:


systemctl start nginx # Start the 
systemctl stop nginx # stop 
systemctl restart nginx # restart 
systemctl status nginx # View running status 
systemctl enable nginx # Powered up 
1

conclusion

The above is the detailed tutorial of CentOS 7.2 installation of Nginx 1.10.2. I hope the content of this article can help you in your study or work. If you have any questions, please leave a message to communicate.


Related articles: